导出excel显示Thu Jul 21 16:11:13 CST 2016 现在用list for循环得到时间的值(Date类型),然后转换为"yyyy-MM-dd HH:mm:ss"
再将值赋予它,应该怎么做。或者在excel页面直接将单元格设置成"yyyy-MM-dd HH:mm:ss"
你excel里面若是正确的时间格式,可以把所有表格的类型改为string类型,例:
/**
* 判断每个单元格中数据的类型
* @param cell
* @return
*/
public static String getStringVal(Cell cell){
if(cell==null)
{
return null;
}
switch(cell.getCellType()){
case Cell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue()? "true" : "false";
case Cell.CELL_TYPE_FORMULA:
cell.setCellType(Cell.CELL_TYPE_STRING);
return cell.getStringCellValue();
case Cell.CELL_TYPE_NUMERIC:
cell.setCellType(Cell.CELL_TYPE_STRING);
return cell.getStringCellValue().toString().trim();
case Cell.CELL_TYPE_STRING:
return cell.getStringCellValue().toString();
default:
return null;
}
}
SimpleDateFormat simple=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
simple.format(for遍历的时间值);//相当于格式化你的日期值
然后再输出到excel