1. poi的“
- HSSFCellStyle cellStyle = wb.createCellStyle();
- cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
- cell = row.createCell((short)1);
- cell.setCellValue(new Date());
- cell.setCellStyle(cellStyle);
该方法只能创建HSSFDataFormat方法中内建的几种日期格式,而不是真正的完全自定义格式,如果只需要内建的格式,请参考源码。
2. 真正的日期自定义格式,应该参考“
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet("format sheet");
- HSSFDataFormat format = wb.createDataFormat();
- HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell(0);
- HSSFCellStyle style = wb.createCellStyle();
- style.setDataFormat(format.getFormat"yyyy年MM月dd日"));
- cell.setCellValue(new Date());
- cell.setCellStyle(style);