jxl导出excel 导出日期格式的处理方式
关键代码
WritableCellFormat wrappedTime = new WritableCellFormat(new DateFormat("yyyy-MM-dd HH:mm:ss"));
详细代码片段
public static void writeDeptInfoVO() throws Exception {
// 创建用于写入内容的Excel文件的引用
String mbexcel = "d:/124.xls";
String mbexceltemp = "d:/123.xls";
try {
// 获取Excel文件
Workbook Book = Workbook.getWorkbook(new File(mbexcel));
if (Book != null) {
// 通过Excel文件获取第一个工作簿sheet
WritableWorkbook wbook = Workbook.createWorkbook(new File(mbexceltemp), Book); // 根据book创建一个操作对象
WritableSheet sh = wbook.getSheet(0);
// 设置标题
WritableFont font = new WritableFont(WritableFont.ARIAL, 18, WritableFont.BOLD);
WritableCellFormat wrappedText = null;
wrappedText = new WritableCellFormat(font);
wrappedText.setAlignment(jxl.format.Alignment.CENTRE);// 水平居中
wrappedText.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 垂直
WritableCellFormat wrappedTime = new WritableCellFormat(new DateFormat("yyyy-MM-dd HH:mm:ss"));
// 列 行
sh.addCell(new Label(0, 0, "1", wrappedText));
sh.addCell(new DateTime(1, 0, new Date(), wrappedTime));
sh.addCell(new DateTime(2, 0, new Date(), wrappedTime));
wbook.write();
wbook.close();
}
} catch (Exception e) {
e.getStackTrace();
System.out.println(e.getMessage());
} finally {
}
}
爆款云服务器s6 2核4G 低至0.46/天,具体规则查看活动详情