1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| HashMap<String, String> headerRules = new HashMap<>(); headerRules.put("1,1,A,K", "项目资源统计"); headerRules.put("2,3,A,A", "序号"); headerRules.put("2,2,B,E", "基本信息"); headerRules.put("3,3,B,B", "项目名称"); headerRules.put("3,3,C,C", "所属区域"); headerRules.put("3,3,D,D", "省份"); headerRules.put("3,3,E,E", "市"); headerRules.put("2,3,F,F", "项目所属人"); headerRules.put("2,3,G,G", "市项目领导人"); headerRules.put("2,2,H,I", "分值"); headerRules.put("3,3,H,H", "得分"); headerRules.put("3,3,I,I", "平均分"); headerRules.put("2,3,J,J", "创建时间"); headerRules.put("2,3,K,K", "项目图片");
HashMap<String, String> footerRules = new HashMap<>(); footerRules.put("1,2,A,C", "注释:"); footerRules.put("1,2,D,K", "导出参考代码!");
Column[] column = { Column.field("projectName"), Column.field("areaName").width(10), Column.field("province").width(5).dorpDown(new String[]{"陕西省", "山西省", "辽宁省"}), Column.field("city").align(HorizontalAlignment.RIGHT), Column.field("people").valign(VerticalAlignment.TOP), Column.field("leader").width(4).verifyCustom("VALUE(F3:F500)", "我是提示"), Column.field("scount").verifyIntNum("10~20").backColor(IndexedColors.BROWN), Column.field("avg").verifyFloatNum("10.0~20.0").color(IndexedColors.RED), Column.field("createTime").width(20).verifyDate("2000-01-03 12:35~3000-05-06 23:23") .align(HorizontalAlignment.LEFT).valign(VerticalAlignment.CENTER) .backColor(IndexedColors.YELLOW).color(IndexedColors.GOLD), Column.field("img")
};
Workbook bean = ExcelUtils.createWorkbook( sheetData, ExportRules.complexRule(column, headerRules).autoNum(true).footerRules(footerRules).sheetName("mysheet2"), true, (fieldName, value, row, col) -> { if ("projectName".equals(fieldName) && row.getProjectName().equals("中青旅23")) { col.align(HorizontalAlignment.LEFT); col.valign(VerticalAlignment.CENTER); col.height(2); col.backColor(IndexedColors.RED); col.color(IndexedColors.YELLOW); } return value; });
bean.write(new FileOutputStream("src/test/java/excel/export/export2.xlsx"));
|