Apache POI Date format partially working

妖精的绣舞 提交于 2019-12-11 14:27:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!