easyexcel导出excel 到浏览器,并设置第一行大标题

// 导出数据列表
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();

你可能感兴趣的:(excel)