Nick Burch wrote:
DateUtil.isCellDateFormatted works for both xssf and hssf. I'd suggest you take a peek into that. Use that to trace back how to get both the index and the string from xssf, then do the same sort of thing for your sax parsing

Thanks for the tip. I am indeed using SAX-style processing to read the sheets. But the style table looks reasonably short, like it will fit in memory without trouble. I revised the XLSX2CSV program to get a StylesTable object from an XSSFReader, then while processing cells, it looks up the styles using the style index value, which yields objects of type XSSFCellStyle. From that object it calls getDataFormat() which yields a short; it also calls getDataFormatString(), which always yields null. DateUtil recognizes the short data format value just fine, and doesn't complain about the null string.

My next question -- the sheet has some mm-dd-yyyy only values (i.e., date no time), HH:MM only values (time no date), as well as full mm-dd-yyyy HH:MM (i.e., datetime aka Java Date). Internally those are different: date-only is an integer, time-only is a double with nothing to the left of the decimal, and datetime is a double with digits on both sides of the decimal. I would like to show them suitably in the output instead of showing detail that really isn't there, like "Sun Dec 31 1899" as the date for a time-only value.

For a HSSF sheet, the XLS2CSVmra examples uses a FormatTrackingHSSFListener, which offers a formatNumberDateCell option, and that handles the dateonly, timeonly, etc. cases well.

Does DateUtil provide any assistance for XSSF sheets? Do I need to use XSSFDataFormat class? How else can I address this problem?

I feel like I'm really close, but just need a few more clues. Thanks in advance.

chris...

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to