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); // 垂直对齐
posted @ 2021-05-21 18:53  60kmph  阅读(886)  评论(0编辑  收藏  举报