33444
This commit is contained in:
parent
94a668864c
commit
5075cde8c0
8
pom.xml
8
pom.xml
@ -38,7 +38,7 @@
|
|||||||
<easypoi.version>4.2.0</easypoi.version>
|
<easypoi.version>4.2.0</easypoi.version>
|
||||||
<xerces.version>2.12.0</xerces.version>
|
<xerces.version>2.12.0</xerces.version>
|
||||||
<poi-scratchpad.version>4.1.1</poi-scratchpad.version>
|
<poi-scratchpad.version>4.1.1</poi-scratchpad.version>
|
||||||
<poi-ooxml-schemas.version>1.3</poi-ooxml-schemas.version>
|
<poi-ooxml-schemas.version>5.2.3</poi-ooxml-schemas.version>
|
||||||
<aws-java-sdk.version>1.11.842</aws-java-sdk.version>
|
<aws-java-sdk.version>1.11.842</aws-java-sdk.version>
|
||||||
<log4j-spring-boot.version>2.17.2</log4j-spring-boot.version>
|
<log4j-spring-boot.version>2.17.2</log4j-spring-boot.version>
|
||||||
<hutool.version>5.7.22</hutool.version>
|
<hutool.version>5.7.22</hutool.version>
|
||||||
@ -281,6 +281,12 @@
|
|||||||
<version>${easyexcel.version}</version>
|
<version>${easyexcel.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml</artifactId>
|
||||||
|
<version>5.2.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aliyun.oss</groupId>
|
<groupId>com.aliyun.oss</groupId>
|
||||||
<artifactId>aliyun-sdk-oss</artifactId>
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
|
|||||||
@ -106,5 +106,4 @@ public class CaseplatformCaseController {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,8 +17,8 @@ import net.lab1024.sa.common.common.domain.ResponseDTO;
|
|||||||
import net.lab1024.sa.common.common.exception.BusinessException;
|
import net.lab1024.sa.common.common.exception.BusinessException;
|
||||||
import net.lab1024.sa.common.module.support.operatelog.annoation.OperateLog;
|
import net.lab1024.sa.common.module.support.operatelog.annoation.OperateLog;
|
||||||
import org.apache.poi.ss.formula.functions.T;
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@ -28,9 +28,11 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,60 +101,72 @@ public class CaseplatformCaseExcelController {
|
|||||||
public void exportExpertCaseExcel(HttpServletResponse response, @Valid CaseplatformCaseQueryForm queryForm) {
|
public void exportExpertCaseExcel(HttpServletResponse response, @Valid CaseplatformCaseQueryForm queryForm) {
|
||||||
try {
|
try {
|
||||||
List<ExportExpertCaseExcelVo> list = caseplatformCaseService.exportExpertCaseExcel(queryForm);
|
List<ExportExpertCaseExcelVo> list = caseplatformCaseService.exportExpertCaseExcel(queryForm);
|
||||||
|
|
||||||
// 处理数据
|
|
||||||
List<ExportExpertCaseExcelVo> processedList = caseplatformCaseService.exportExpertCaseExcelProcess(list);
|
List<ExportExpertCaseExcelVo> processedList = caseplatformCaseService.exportExpertCaseExcelProcess(list);
|
||||||
|
|
||||||
// 1. 构建合并的第一行标题
|
// 字段标题
|
||||||
List<List<String>> head = new ArrayList<>();
|
List<List<String>> head = Arrays.asList(
|
||||||
List<String> titleRow = new ArrayList<>();
|
Collections.singletonList("序号"),
|
||||||
titleRow.add("人工肝诊疗病例征集项目专家劳务费表");
|
Collections.singletonList("银行"),
|
||||||
for (int i = 0; i < 13; i++) { // 假设你总共有 13 列(从"序号"到"身份证号")
|
Collections.singletonList("账号所在省份"),
|
||||||
if (i > 0) titleRow.add("");
|
Collections.singletonList("账户所在地市"),
|
||||||
}
|
Collections.singletonList("卡号"),
|
||||||
head.add(titleRow);
|
Collections.singletonList("姓名"),
|
||||||
|
Collections.singletonList("实发"),
|
||||||
// 2. 添加第二行字段标题(正常列头)
|
Collections.singletonList("备注"),
|
||||||
List<String> headerRow = Arrays.asList(
|
Collections.singletonList("个税"),
|
||||||
"序号", "银行", "账号所在省份", "账户所在地市",
|
Collections.singletonList("应发"),
|
||||||
"卡号", "姓名", "实发", "备注", "个税", "应发", "单位", "电话", "身份证号", "关联病例"
|
Collections.singletonList("单位"),
|
||||||
|
Collections.singletonList("电话"),
|
||||||
|
Collections.singletonList("身份证号"),
|
||||||
|
Collections.singletonList("关联病例")
|
||||||
);
|
);
|
||||||
head.add(headerRow);
|
|
||||||
|
|
||||||
// 1设置表头样式
|
// 表头样式
|
||||||
WriteCellStyle headStyle = new WriteCellStyle();
|
WriteCellStyle headStyle = new WriteCellStyle();
|
||||||
// 1.1设置表头数据居中
|
|
||||||
headStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
headStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||||
|
headStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
|
||||||
// 2设置表格内容样式
|
// 内容样式
|
||||||
WriteCellStyle bodyStyle = new WriteCellStyle();
|
|
||||||
// 2.1设置表格内容水平居中
|
|
||||||
bodyStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
|
||||||
// 2.2设置表格内容垂直居中
|
|
||||||
bodyStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
||||||
|
|
||||||
WriteCellStyle contentStyle = new WriteCellStyle();
|
WriteCellStyle contentStyle = new WriteCellStyle();
|
||||||
contentStyle.setHorizontalAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment.CENTER);
|
contentStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||||
|
contentStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
|
||||||
// 4拿到表格处理对象
|
// 1. 创建ExcelWriter,注册自定义合并handler
|
||||||
ExcelWriter writer = EasyExcel.write(response.getOutputStream())
|
ExcelWriter writer = EasyExcel.write(response.getOutputStream(), ExportExpertCaseExcelVo.class)
|
||||||
.head(head)
|
.head(head)
|
||||||
.excelType(ExcelTypeEnum.XLSX)
|
.excelType(ExcelTypeEnum.XLSX)
|
||||||
.registerWriteHandler(new HorizontalCellStyleStrategy(headStyle, contentStyle))
|
.registerWriteHandler(new HorizontalCellStyleStrategy(headStyle, contentStyle))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
WriteSheet writeSheet = EasyExcel.writerSheet("劳务费明细").needHead(true).build();
|
WriteSheet writeSheet = EasyExcel.writerSheet("劳务费明细")
|
||||||
|
.needHead(true)
|
||||||
|
.relativeHeadRowIndex(2) // 数据从第三行开始
|
||||||
|
.build();
|
||||||
|
|
||||||
// 5写入excel数据
|
// 2. 用 POI 操作 sheet,合并第一行并写入大标题
|
||||||
|
Workbook workbook = (Workbook) writer.writeContext().writeWorkbookHolder().getWorkbook();
|
||||||
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, head.size() - 1));
|
||||||
|
Row row = sheet.getRow(0);
|
||||||
|
if (row == null) {
|
||||||
|
row = sheet.createRow(0);
|
||||||
|
}
|
||||||
|
Cell cell = row.createCell(0);
|
||||||
|
cell.setCellValue("人工肝诊疗病例征集项目专家劳务费表");
|
||||||
|
|
||||||
|
// 2. 写入数据
|
||||||
writer.write(processedList, writeSheet);
|
writer.write(processedList, writeSheet);
|
||||||
|
writer.finish();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 6通知浏览器以附件的形式下载处理,设置返回头要注意文件名有中文
|
// 6通知浏览器以附件的形式下载处理,设置返回头要注意文件名有中文
|
||||||
String fileName = URLEncoder.encode("人工肝专家劳务费明细表", "UTF-8").replaceAll("\\+", "%20");
|
String fileName = URLEncoder.encode("病例数据", "UTF-8").replaceAll("\\+", "%20");
|
||||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
||||||
response.setContentType("multipart/form-data");
|
response.setContentType("multipart/form-data");
|
||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
writer.finish();
|
writer.finish();
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user