我想使用 Apache POI 在 Excel 文件中设置日期格式的日期。该值将以这样的方式设置,以便在地址栏中它将显示为 mm/dd/YYYY,在单元格中它将显示为 dd-mmm(数字日和月缩写:01-Jan)。
您可以申请一个CellStyle
到您需要填写的单元格。这是我过去工作中的一些代码片段,它并不完整,但显示了基本思想:
Row row = sheet.createRow(0);
Cell cell = row.createCell((short) 0);
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
SimpleDateFormat datetemp = new SimpleDateFormat("yyyy-MM-dd");
Date cellValue = datetemp.parse("1994-01-01 12:00");
cell.setCellValue(cellValue);
//binds the style you need to the cell.
CellStyle dateCellStyle = wb.createCellStyle();
short df = wb.createDataFormat().getFormat("dd-mmm");
dateCellStyle.setDataFormat(df);
cell.setCellStyle(dateCellStyle);
有关 JDK 中日期格式的更多信息,您应该阅读以下内容:http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)