最近在做一个excel导出的功能,是按照相应的模板然后再将内容填充进去,代码如下
使用的是集成好的一个插件 码云地址
具体实现代码
@GetMapping("/ExcelExport/{sickIds}")
public void testFillInTable(@PathVariable Integer [] sickIds,HSSFWorkbook wb,HttpServletResponse response) throws Exception {
//获取患者id
/* Integer[] sickArray = Convert.toIntArray(sickIds);*/
Integer[] sickArray = sickIds;
/* int[] sickId =Arrays.asList(sickIds).stream().mapToInt(Integer::parseInt).toArray();*/
/* InputStream systemResourceAsStream = this.getClass().getResourceAsStream("/"+"导出记录表模板.xlsx");*/
ClassPathResource resource = new ClassPathResource("导出记录表模板.xlsx");
InputStream inputStream = resource.getInputStream();
// 获取 excel 二进制文件
/* File file = new File("src/main/resources/导出记录表模板.xlsx");*/
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int num1;
while ((num1 = inputStream.read(buffer)) != -1) {
byteArrayOutputStream.write(buffer, 0, num1);
}
byteArrayOutputStream.flush();
/* byte[] bytes = FileUtils.readFileToByteArray(file);*/
byte[] bytes =byteArrayOutputStream.toByteArray();
// 创建 table 对象
ExcelWorkbook excelWorkbook = ExcelHelper.createWorkbook(bytes);
SheetTable table = excelWorkbook.getSheet(0);
// 设置 自定义 sheet 页名称
table.setSheetName("内异云导出记录");
// 定义 excel 表格数据
/* neiyiData sickdata = new neiyiData();*/
//包含患者所有患病信息
SickQueryVo sickQueryVo = new SickQueryVo();
/* ====================================
开始组装表格数据
====================================
*/
/* List<sickQueryVo> sickList = Arrays.asList(
new neiyiData(1,"张三","4","四川","156456","2021","名称