// 导出数据列表
List<YourDataModel> dataList = yourService.getDataList();

// 构建Excel表格
ExcelWriter writer = EasyExcel.write(response.getOutputStream()).build();

// 设置表格头部样式
WriteCellStyle headStyle = new WriteCellStyle();
headStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
WriteFont headFont = new WriteFont();
headFont.setFontHeightInPoints((short) 14);
headFont.setBold(true);
headStyle.setWriteFont(headFont);

// 构建表格头部数据
List<List<String>> headList = new ArrayList<>();
List<String> headTitleList = new ArrayList<>();
headTitleList.add("大标题");
headList.add(headTitleList);

// 写入表格头部
Sheet sheet = new Sheet(1, 0);
sheet.setClazz(YourDataModel.class);
sheet.setHead(headList);
sheet.setHeadStyle(headStyle);
writer.write(dataList, sheet);

// 关闭ExcelWriter
writer.finish();
GitHub 加速计划 / ea / easyexcel
25
5
下载
快速、简洁、解决大文件内存溢出的java处理Excel工具
最近提交(Master分支:3 个月前 )
c42183df Bugfix 1 年前
efa7dff6 * 重新加回 `commons-io` 1 年前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐