easyexcel 导出模板生成第一行示例
时间: 2023-11-09 14:00:08 浏览: 103
生成 EasyExcel 导出模板的第一行示例代码如下:
```
// 创建一个 EasyExcel 写入对象
ExcelWriter excelWriter = EasyExcel.write(filePath).build();
// 创建一个 Sheet 对象,设置 Sheet 名称和表头行数
Sheet sheet = new Sheet(1, 0);
sheet.setSheetName("Sheet1");
// 创建一个表头样式对象,并设置样式
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
headWriteCellStyle.setBorderTop(BorderStyle.THIN);
headWriteCellStyle.setBorderLeft(BorderStyle.THIN);
headWriteCellStyle.setBorderRight(BorderStyle.THIN);
headWriteCellStyle.setBorderBottom(BorderStyle.THIN);
Font headFont = new Font();
headFont.setFontHeightInPoints((short)12);
headFont.setFontName("微软雅黑");
headFont.setBold(true);
headWriteCellStyle.setWriteFont(headFont);
// 创建表头数据
List<String> headList = Arrays.asList("姓名", "年龄", "性别");
// 写入表头数据到 Excel 文件中
List<List<String>> headData = new ArrayList<>();
headData.add(headList);
excelWriter.write(headData, sheet, new WriteTableParameter(null, headWriteCellStyle));
// 关闭 Excel 写入对象
excelWriter.finish();
```
阅读全文