Search code examples
javaexcelapiapache-poisax

POI SAX Date data type


I'm trying to get date data types from an excel file, but the output when he's reading is 41306.038888888892.

This value just appear for date, is there any way to get the normal date?

I did not find anything searching in the web. Hope someone can help

thanks


Solution

  • As with your previous question, I'd strongly suggest you try reading and understanding some of the various examples for this, you'll save yourself a lot of time! The two main ones probably being XSSFEventBasedExcelExtractor in Apache POI and XSSFExcelExtractorDecorator in Apache Tika

    If you take the easy route, then you can just use XSSFSheetXMLHandler, which will handle all the pesky formatting stuff for you, and give you nicely formatted strings for your dates

    Otherwise, if you want to stay at the low level, then you need to check the formatting rule applied to a cell. If it's a date-based format string, you then need to convert it from a number into a Date object. Handily, there's a POI class DateUtil which can both help you check if a cell is Date formatted, and convert it into a Java Date object for you