* @param filePath 存放excel文件的路径(path/demo.xls)
* @param sheetName Excel表格的表名
* @param colName excel中包含的列名(可以有多个)
public static void initExcel(String filePath, String sheetName, String[] colName) {
format();
WritableWorkbook workbook = null;
System.out.println("是否运行excel文件");
try {
File file = new File(filePath);
if (!file.exists()) {
workbook = Workbook.createWorkbook(file);
//设置表格的名字
WritableSheet sheet = workbook.createSheet(sheetName,0);
//m.addMergedRegion(new CellRangeAddress(1,1,1,2));
sheet.addCell((WritableCell) new Label(0, 0, filePath, arial14format));
sheet.setRowView(0, 800);
sheet.setRowView(20, 600);
sheet.setRowView(3, 600);
sheet.mergeCells(0,0,6,0);
sheet.mergeCells(5,1,6,1);
sheet.mergeCells(1,2,3,2);
sheet.mergeCells(1,3,3,3);
sheet.mergeCells(5,2,6,2);
sheet.mergeCells(5,3,6,3);
sheet.mergeCells(1,1,3,1);
sheet.mergeCells(0,4,6,4);
sheet.mergeCells(5,5,6,5);
sheet.mergeCells(5,6,6,6);
sheet.mergeCells(5,7,6,7);
sheet.mergeCells(5,8,6,8);
sheet.mergeCells(5,9,6,9);
sheet.mergeCells(5,10,6,10);
sheet.mergeCells(5,11,6,11);
sheet.mergeCells(5,12,6,12);
sheet.mergeCells(5,13,6,13);
sheet.mergeCells(5,14,6,14);
sheet.mergeCells(5,15,6,15);
sheet.mergeCells(5,16,6,16);
sheet.mergeCells(5,17,6,17);
sheet.mergeCells(5,18,6,18);
sheet.mergeCells(5,19,6,19);
sheet.mergeCells(3,5,4,5);
sheet.mergeCells(3,6,4,6);
sheet.mergeCells(3,7,4,7);
sheet.mergeCells(3,8,4,8);
sheet.mergeCells(3,9,4,9);
sheet.mergeCells(3,10,4,10);
sheet.mergeCells(3,11,4,11);
sheet.mergeCells(3,12,4,12);
sheet.mergeCells(3,13,4,13);
sheet.mergeCells(3,14,4,14);
sheet.mergeCells(3,15,4,15);
sheet.mergeCells(3,16,4,16);
sheet.mergeCells(3,17,4,17);
sheet.mergeCells(3,18,4,18);
sheet.mergeCells(3,19,4,19);
sheet.mergeCells(0,21,1,21);
sheet.mergeCells(2,21,3,21);
sheet.mergeCells(5,21,6,21);
sheet.mergeCells(0,20,6,20);
sheet.addCell(new Label(0,0 ,"学生十四天健康情况登记表" , arial10format));
sheet.addCell(new Label(0,1 ,"单位名称" , arial10format));
sheet.addCell(new Label(0,2 ,"姓名" , arial10format));
sheet.addCell(new Label(0,3 ,"目前健康状态" , arial10format));
sheet.addCell(new Label(0,4 ,"每日体温,健康状况监测(周期14天)" , arial10format));
sheet.addCell(new Label(0,5 ,"日期" , arial10format));
/*sheet.addCell(new Label(0,6 ,"2021-3-5" , arial10format));
sheet.addCell(new Label(0,7 ,"2021-3-6" , arial10format));
sheet.addCell(new Label(0,8 ,"2021-3-7" , arial10format));
sheet.addCell(new Label(0,9 ,"2021-3-8" , arial10format));
sheet.addCell(new Label(0,10 ,"2021-3-9" , arial10format));
sheet.addCell(new Label(0,11 ,"2021-3-10" , arial10format));
sheet.addCell(new Label(0,12 ,"2021-3-11" , arial10format));
sheet.addCell(new Label(0,13 ,"2021-3-12" , arial10format));
sheet.addCell(new Label(0,14 ,"2021-3-13" , arial10format));
sheet.addCell(new Label(0,15 ,"2021-3-14" , arial10format));
sheet.addCell(new Label(0,16 ,"2021-3-15" , arial10format));
sheet.addCell(new Label(0,17 ,"2021-3-16" , arial10format));
sheet.addCell(new Label(0,18 ,"2021-3-17" , arial10format));
sheet.addCell(new Label(0,19 ,"2021-3-18" , arial10format));*/
sheet.addCell(new Label(0,20 ,"本人承诺:自觉履行疫情防控责任和义务,保证以上填报信息全部属实," +
"如有隐瞒,自愿承担相应法律后果。" , arial10format));
new WritableCellFormat().setWrap(true);//通过调整宽度和高度自动换行
sheet.addCell(new Label(0,21,"本人签字:" , arial10format));
sheet.addCell(new Label(1,5 ,"每日体温°C" , arial10format));
sheet.addCell(new Label(2,5 ,"健康状况" , arial10format));
sheet.addCell(new Label(3,5 ,"当日所在地" , arial10format));
sheet.addCell(new Label(4,1 ,"填表日期:" , arial10format));
sheet.addCell(new Label(4,2 ,"学号" , arial10format));
sheet.addCell(new Label(4,3 ,"手机号" , arial10format));
sheet.addCell(new Label(4,21 ,"签字日期:" , arial10format));
sheet.addCell(new Label(5,5 ,"备注" , arial10format));
/*
//创建标题栏
sheet.addCell((WritableCell) new Label(0, 0, filePath, arial14format));
for (int col = 0; col < colName.length; col++) {
sheet.addCell(new Label(col, 0, colName[col], arial10format));
}
*/
//设置行高
sheet.setRowView(0, 340);
workbook.write();
workbook.close();
System.out.println("已创建excel文件");
} else {
System.out.println("已存在excel文件");
return;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (workbook != null) {
try {
workbook.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}