导航

 
public static void main(String[] args) throws IOException {
        // exportList为表头总的集合,导出的EXCEL表格的表头完全是按照这个来生成的
        List<ExcelExportEntity> exportList = new ArrayList<>();
        // 创建最底部的一级表头10个
        ExcelExportEntity A1 = new ExcelExportEntity("一级表头A1", "a1");
        ExcelExportEntity A2 = new ExcelExportEntity("一级表头A2", "a2");
        ExcelExportEntity B1 = new ExcelExportEntity("一级表头B1", "b1");
        ExcelExportEntity B2 = new ExcelExportEntity("一级表头B2", "b2");
        ExcelExportEntity B3 = new ExcelExportEntity("一级表头B3", "b3");
        ExcelExportEntity C1 = new ExcelExportEntity("一级表头C1", "c1");
        ExcelExportEntity C2 = new ExcelExportEntity("一级表头C2", "c2");
        ExcelExportEntity D1 = new ExcelExportEntity("一级表头D1", "d1");
        ExcelExportEntity D2 = new ExcelExportEntity("一级表头D2", "d2");
        ExcelExportEntity D3 = new ExcelExportEntity("一级表头D3", "d3");

        // 创建二级表头,并将二级表头对应的下级一级表头放入其中,以此类推...
        ExcelExportEntity A = new ExcelExportEntity("二级表头A", "a");
        A.setList(Arrays.asList(A1, A2));
        ExcelExportEntity B = new ExcelExportEntity("二级表头B", "b");
        B.setList(Arrays.asList(B1, B2, B3));
        ExcelExportEntity C = new ExcelExportEntity("二级表头C", "c");
        C.setList(Arrays.asList(C1, C2));
        ExcelExportEntity D = new ExcelExportEntity("二级表头D", "d");
        D.setList(Arrays.asList(D1, D2, D3));

        ExcelExportEntity AA = new ExcelExportEntity("三级表头AA", "aa");
        AA.setList(Arrays.asList(A, B, C));
        ExcelExportEntity AB = new ExcelExportEntity("三级表头BB", "bb");
        AB.setList(Arrays.asList(D));


ExcelExportEntity XYZ
= new ExcelExportEntity("四级表头", "xyz"); XYZ.setList(Arrays.asList(AA, AB)); // 最后表头设置完毕,将总和起来的四级表头放入 exportList.add(XYZ); // EXCEL导出参数 ExportParams params = new ExportParams("表格标题", "随便取个sheet名", ExcelType.XSSF); // 导出的表格 // Workbook sheets = ExcelExportUtil.exportBigExcel(params, exportList, "查询数据用的接口":service, "查询数据接口要用到的查询参数":queryParams); List<Map<String, Object>> titles = new ArrayList<>(); List<Map<String, Object>> data = new ArrayList<>();//数据为 Map<String, Object> map = ExcelUtils.createDynamicHeaderSheetMap(data, exportList, params); // params.setSheetName(""); // params.setStyle(ExcelStyle.class); titles.add(map); Workbook dynamicHeaderSheets = ExcelUtils.createDynamicHeaderSheets(titles, ExcelType.XSSF, false); FileOutputStream fos = new FileOutputStream(new File("C:\\Users\\farben\\Desktop\\a.xlsx")); dynamicHeaderSheets.write(fos); }

 

 

posted on 2023-04-28 14:08  一棵二叉树  阅读(912)  评论(0编辑  收藏  举报