This commit is contained in:
haomingming 2026-01-04 14:35:44 +08:00
parent d071779de8
commit 5e0ddde4ec

View File

@ -159,10 +159,40 @@ public class CaseplatformCaseExcelController {
// 写数据
writer.write(processedList, writeSheet);
// 创建合计行在数据写入后finish 之前
// 设置标题和合计行在数据写入后finish 之前
try {
Workbook workbook = writer.writeContext().writeWorkbookHolder().getWorkbook();
Sheet sheet = workbook.getSheetAt(0);
// 确保标题行存在并设置标题
Row titleRow = sheet.getRow(0);
if (titleRow == null) {
titleRow = sheet.createRow(0);
}
titleRow.setHeightInPoints(30);
Cell titleCell = titleRow.getCell(0);
if (titleCell == null) {
titleCell = titleRow.createCell(0);
}
titleCell.setCellValue("人工肝诊疗病例征集项目专家劳务费表");
// 合并标题单元格
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, head.size() - 1));
// 设置标题样式
CellStyle titleStyle = workbook.createCellStyle();
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 16);
titleFont.setBold(true);
titleStyle.setFont(titleFont);
titleStyle.setAlignment(HorizontalAlignment.CENTER);
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
titleStyle.setBorderBottom(BorderStyle.THIN);
titleStyle.setBorderTop(BorderStyle.THIN);
titleStyle.setBorderLeft(BorderStyle.THIN);
titleStyle.setBorderRight(BorderStyle.THIN);
titleCell.setCellStyle(titleStyle);
int totalRowIndex = 2 + processedList.size(); // 0=大标题1=表头2~1+size=数据2+size=合计
Row totalRow = null;