POI导出Excel的时候有时需要日期格式,在筛选时是这样的
private XSSFWorkbook wb = null;String dateFormat = "yyyy-MM-dd";//或者"yyyy/MM/dd"格式,"yyyy/M/d"这样的格式不会自动补0public void setCell(int index,Date value,boolean isStyle){XSSFCell cell = this.row.createCell(index);DataFormat format = wb.createDataFormat();// 日期格式化CellStyle cellStyle = wb.createCellStyle();cellStyle.setDataFormat(format.getFormat(dateFormat));cell.setCellStyle(cellStyle);cell.setCellValue(value);//Date类型的日期 }
下面就附上代码