I am writing a program that imports xlsx files using EventModel Apache POI (SAX / XSSF). I am almost ready, but I cannot get the correct dates.
I am parsing a cell with a date value
<cr="D1" s="1"> <v>41319.558333333334</v> </c>
I use the class org.apache.poi.ss.usermodel.DateUtil to get the date:
DateUtil.getJavaCalendar(doble date, bool use1904windowing);
What should I pass as use1904windowing to get the correct dates? I use false temporarily, as this gives me the correct dates in my test book, but I know that I have to read this value somewhere.
In xls binary, there is a DateWindow1904Record entry that I am reading using HSSF. What is its counterpart in XSSF? Or should I always use false ?
EDIT : @rgettman's answer pointed me to a solution, but it is not complete. In the event model, you do not have an xssfWorkbook object, and you cannot just get it from CWWorkbook ().
Instead, you can create a CTWorkbook directly from an InputStream:
OPCPackage pkg = OPCPackage.open(filename); XSSFReader r = new XSSFReader( pkg ); InputStream workbookXml = r.getWorkbookData(); CTWorkbook ctWorkbook = CTWorkbook.Factory.parse(workbookXml); boolean isDate1904 = ctWorkbook.getWorkbookPr().getDate1904();
Swilk source share