Hutool POI - Excel 报表导出 用法样例


Hutool POI - Excel 报表导出 用法样例

流写出设置

ExcelWriter writer = ExcelUtil.getWriter();
// ...
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
response.setHeader("Content-Disposition","attachment;filename=" 
                   + DateUtil.formatDate(new Date()) + ".xlsx");
OutputStream out = response.getOutputStream();
writer.flush(out, true);
writer.close();
IoUtil.close(out);

写出数据到单元格

writer.writeCellValue(0, 0, row);

设置全局单元格样式

ExcelWriter writer = ExcelUtil.getWriter();
CellStyle cellStyle = writer.getCellStyle();
cellStyle.setBorderBottom(BorderStyle.NONE); // 无边框

设置单个单元格样式

CellStyle style = writer.createCellStyle(x, y);
style.setFillForegroundColor(IndexedColors.CORAL.getIndex()); // 背景色
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setAlignment(HorizontalAlignment.CENTER); // 水平对齐
style.setVerticalAlignment(VerticalAlignment.CENTER); // 垂直对齐


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM