私の連絡先情報
郵便メール:
2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
シートは動的にエクスポート、疑似コードを作成し、塗りつぶされたワークブック オブジェクトを作成します。
- List<Map<String, Object>>list = new ArrayList<Map<String, Object>>();
- HashMap<String, Object> map = new HashMap<>();
- map.put("name", "小明");
- map.put("age", "18");
- list1.add(map);
- List<ExcelExportEntity> entitys=new ArrayList<>();
- entitys.add(new ExcelExportEntity("名字" ,"name"));
- entitys.add(new ExcelExportEntity("年龄" ,"age"));
- ExportParams exportParams = new ExportParams(null, "sheet1名字");
- exportParams.setType(ExcelType.XSSF);
- Workbook workbook = ExcelExportUtil.exportExcel(exportParams, entitys, list);
複数のシートの動的エクスポート、疑似コード、および塗りつぶされたワークブック オブジェクトの作成
- List<Map<String, Object>> sheet1ListMap= new ArrayList<Map<String, Object>>();
-
- List<Map<String, Object>> sheet2ListMap= new ArrayList<Map<String, Object>>();
-
- List<ExcelExportEntity> sheet1List=new ArrayList<>();
- sheet1List.add(new ExcelExportEntity("名字" ,"name"));
- sheet1List.add(new ExcelExportEntity("年龄" ,"age"));
-
- List<ExcelExportEntity> sheet2List=new ArrayList<>();
- sheet2List.add(new ExcelExportEntity("学号" ,"sno"));
- sheet2List.add(new ExcelExportEntity("课程" ,"course"));
-
- ExportParams exportParams1 = new ExportParams(null, "sheet1名字");
- exportParams1.setType(ExcelType.XSSF);
-
- ExportParams exportParams2 = new ExportParams(null, "sheet2名字");
- exportParams2.setType(ExcelType.XSSF);
-
- Workbook workbook = new XSSFWorkbook();
- ExcelExportService service = new ExcelExportService();
- // 创建sheet1,执行的先后顺序
- service.createSheetForMap(workbook, exportParams1, sheet1List, sheet1ListMap);
- // 创建sheet2
- service.createSheetForMap(workbook, exportParams2, sheet2List, sheet2ListMap);
注: createSheetForMap() メソッドには使用制限があり、エクスポートされたデータを null にすることはできません。ヘッダーのみを含みデータを含まないフォームをエクスポートする必要がある場合は、対応するエンティティ クラスを作成し、注釈を使用する必要があります。
参照文書:easy-poi は、動的な列 (タイトル)、Excel ドキュメントの複数シートのエクスポートなどの操作を実装します。 - 完全なテスト ケースが添付されています。