问题
I am using poi 3.8 to create excel sheet
I have some date columns which I am formitting with the below code
CreationHelper ch = wb.getCreationHelper();
short df = ch.createDataFormat().getFormat("MM/dd/yyyy");
System.out.println(df);
CellStyle cs = wb.createCellStyle();
cs.setDataFormat(df);
Cell cell = sheet.createRow(0).createCell(0);
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
cell.setCellValue( sdf.parse("04/30/2013") );
sheet.setColumnWidth(0, 6000);
cell.setCellStyle(cs);
but the problem is that poi is not formating some of the date cells, instead of showing date in "MM/dd/yyyy" format it is showing date as number value like 451235
One more thing to mention here is that I am using pre created styles with setDataFormat(df) method call for date and default format for non-date columns
来源:https://stackoverflow.com/questions/18992496/apache-poi-date-format-partially-working