This project is read-only.

DateTime precision when writing to XSSF Cell

May 20, 2014 at 7:01 PM
Hello everyone,

I made a simple program to write a DataTable to Excel and it works really great when saving .xls files, but when I use XSSF instead of HSSF, the precision of DateTime values is corrupted.

If I have a DateTime with the value "2014-05-20 14:58:30" and I assign that value to the cell then I lose the TIME of the date.

I'm attaching 2 screenshots, in both of them I run the very same program, just one is using HSSF and the another XSSF, please notice how XSSF Cell Value loses it's decimal part.

Any help is appreciated.

Thanks

HSSF (working good)
Image

XSSF (with error)
Image
Coordinator
May 22, 2014 at 10:07 AM
Edited May 22, 2014 at 10:11 AM
Sorry, I cannot reproduce the issue. Btw, What's wrong with your NumericCellValue? the value is too big. 408337083333333.0?

What's your culture setting? There used to be a bug in 2.0.6 caused by wrong thread CultureInfo
May 22, 2014 at 6:59 PM
Hello tony, thank you for answering.

Well, in the Excel Model, Dates are saved in numbers which represents de ammount of days from the year 1900, the hour/minute/second is stored as the decimal part of the number. You can see in the second screenshot that the date 2011-10-17 17:00:00 is ignoring the decimal part and is saving it as an integer, please compare cell.NumericCellValue in both screenshots and you'll see the difference. The first screenshot is ok, the second one is not.
Coordinator
May 23, 2014 at 5:25 AM
I understand what you mean. But I tried XSSF and your code (exact the time you assigned). I cannot reproduce the issue. There must be something wrong. Please add my skype: tonyqus to discuss the issue
May 23, 2014 at 10:32 PM
Tony, I searched you on skype, I think I found you, I sent you a message.

I will prepare an isolated test project to send it to you, in the meanwhile: could you tell me how do I set a different CultureInfo? Currently my Culture is es-CL (I live in Chile).

Greetings
May 23, 2014 at 10:51 PM
This is the class which writes the Excel, could you look at it, it's really short. Remember, the only scope of this class is to write a DataTable as Excel (xls or xlsx)

http://mysticpaste.com/view/l4jxR6PTYJ?2

Greetings