Created attachment 23853 [details] Patch to XSSFWorkbook.java from poi 3.5-beta6 When I create a spreadsheet using XSSFWorkbook with date values in them, and open the file on Mac Excel 2008, all of the date values are off by exactly 4 years. I have done some investigation, and I believe the issue is due to differing defaults when the workbook.xml file has a missing <workbookPr> tag (which seems to happen with all xlsx files created via XSSFWorkbook). According to the ECMA-376 docs, on page 2292, it talks about "1900" vs "1904 backward compatibility" for dates in xlsx files, and I believe the "lack" of a <workbookPr> tag showing the different defaults for Windows Excel 2007 and Mac Excel 2008. If I simply add the following code after workbook creation, the <workbookPr> tag is added to the workbook.xml file, and the dates show properly on Mac Excel 2008, and Windows Excel 2007. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr; import org.apache.poi.xssf.usermodel.XSSFWorkbook; XSSFWorkbook workbook = new XSSFWorkbook(); if (workbook.getCTWorkbook().getWorkbookPr() == null) { // this code causes a <workbookpr> element to be written to the workbook.xml // file. If this mode isn't set, then Mac // Excel 2008 defaults to date1904 mode whereas Windows Excel 2007 // defaults to date1900 mode. CTWorkbookPr workbookPr = CTWorkbookPr.Factory.newInstance(); workbookPr.setDate1904(false); workbook.getCTWorkbook().setWorkbookPr(workbookPr); } I will attach some screenshots and example code showing the differences between display of dates on Excel 2007/Excel 2008. Also, I believe the patch to this is simply adding extra initialization to onWorkbookCreate() in XSSFWorkbook.java. I will also attach a patch showing this addition. Thanks much! --Leif
Created attachment 23854 [details] TestPoiDate.java - sample code exhibiting behavior
Created attachment 23855 [details] Excel 2008 without the workbookPrTag in workbook.xml (this is showing the issue)
Created attachment 23856 [details] Excel 2008 with added workbookPrTag in workbook.xml (this is showing the fix)
Created attachment 23857 [details] Excel 2007 with workbookPrTag - This is showing that Excel 2007 works the same either way.
Created attachment 23858 [details] Excel 2007 without workbookPrTag - This is showing that Excel 2007 defaults to 1900 date formatting even with the workbookPr tag missing.
Leif, You are absolutely correct. The date1904 flag indicates whether the date system starts in 1904. If this flag is missing then the default Excel setting is used which is different in Win Excel 2007 and Mac Excel 2008. The suggested fix is fine, I applied in r788956. Regards, Yegor
Yegor, Thanks so much! --Leif