POI導出Excel的時候有時需要日期格式,在篩選時是這樣的

private XSSFWorkbook wb = null;
String dateFormat = "yyyy-MM-dd";//或者"yyyy/MM/dd"格式,"yyyy/M/d"這樣的格式不會自動補0
public 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類型的日期
}
下面就附上代碼