展示效果
![在这里插入图片描述](https://img-blog.csdnimg.cn/c6780823d5524957bf292e4d5ab719f1.png)
依赖
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>4.1.0</version>
</dependency>
导出
@RequestMapping(value = "/exportData", method = RequestMethod.GET, produces = "application/octet-stream")
@ApiOperation(value = "导出", httpMethod = "GET")
public void exportData(HttpServletResponse response) {
String excelName= "yyyyy";
String sheetNameName = "xxxx";
String[] headers = new String[]{"列1", "列2", "附件", "列3", "列4", "列5"};
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet(sheetNameName);
AtomicInteger ai = new AtomicInteger();
Row row = sheet.createRow(ai.getAndIncrement());
AtomicInteger aj = new AtomicInteger();
for (String header : headers) {
Cell cell = row.createCell(aj.getAndIncrement());
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cellStyle.setAlignment(HorizontalAlignment.CENTER);
Font font = wb.createFont();
font.setBold(true);
cellStyle.setFont(font);
cell.setCellStyle(cellStyle);
cell.setCellValue(header);
}
list.forEach(tZpjh -> {
Row row1 = sheet.createRow(ai.getAndIncrement());
row1.createCell(0).setCellValue(tZpjh.getxx());
row1.createCell(1).setCellValue(tZpjh.getxx());
row1.createCell(3).setCellValue(tZpjh.getxx());
row1.createCell(4).setCellValue(tZpjh.getxx());
row1.createCell(5).setCellValue(tZpjh.getxx());
Cell cell2 = row1.createCell(2);
String url = tZpjh.getFj();
if (ObjectUtil.isNotEmpty(url)) {
String fileName = tZpjh.getFjName();
url = filePrefix.concat(url);
String formula = MessageFormat.format("HYPERLINK(\"{0}\",\"{1}\")", url, fileName);
cell2.setCellFormula(formula);
CellStyle cellStyle = wb.createCellStyle();
cellStyle.cloneStyleFrom(cell2.getCellStyle());
Font font = wb.createFont();
font.setColor(IndexedColors.BLUE.getIndex());
font.setUnderline((byte) 1);
cellStyle.setFont(font);
cell2.setCellStyle(cellStyle);
}
});
wb.getSheet(sheetNameName).createFreezePane(0, 1, 0, 1);
ExcelUtils.buildExcelDocument(excelName, wb, response);
}