if(cellData instanceof Date){
//System.out.println(" cell type is double");
cell.setCellValue((Date) cellData);
String dateFormat="yyyy-MM-dd";
CellStyle cellStyle = createCellStyle(dateFormat);
cell.setCellStyle(cellStyle)
}
--以下是红色字体对应方法
public CellStyle createCellStyle(String format){
CellStyle cellStyle = workbook.createCellStyle();
CreationHelper creationHelper = workbook.getCreationHelper();
short dataFormat = creationHelper.createDataFormat().getFormat(format);
cellStyle.setDataFormat(dataFormat);
return cellStyle;
}
然后输出的excel时日期类型全部显示
//System.out.println(" cell type is double");
cell.setCellValue((Date) cellData);
String dateFormat="yyyy-MM-dd";
CellStyle cellStyle = createCellStyle(dateFormat);
cell.setCellStyle(cellStyle)
}
--以下是红色字体对应方法
public CellStyle createCellStyle(String format){
CellStyle cellStyle = workbook.createCellStyle();
CreationHelper creationHelper = workbook.getCreationHelper();
short dataFormat = creationHelper.createDataFormat().getFormat(format);
cellStyle.setDataFormat(dataFormat);
return cellStyle;
}
然后输出的excel时日期类型全部显示
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货