模板

导出结果

代码
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
@GetMapping("/wordExport")
public void wordExport(HttpServletResponse response) throws Exception {
// 获取模板文档
File rootFile =new File(ResourceUtils.getURL("classpath:").getPath());
File templateFile= new File(rootFile,"/template/1.docx");
System.out.println("模板路径path===>>>"+templateFile.getPath());
// 填充数据
Map<String,Object> data = new HashMap<>();
data.put("orderId","00000001");
data.put("htbh","123456");
data.put("sjrksj","2024-02-05");
data.put("ckmc","仓库名称");
data.put("rkr","张三");
data.put("rkrbm","生产计划部");
data.put("xmlx","修理项目");
data.put("pzdh","123456465");
data.put("zdr","张三");
List<Map<String,Object>> list = new ArrayList<>();
for (int i = 0; i < 2; i++) {
Map<String,Object> m = new HashMap<>();
m.put("wzmc","名称"+i);
m.put("ggxh","规格型号");
m.put("ybm","");
m.put("number",20);
m.put("jldw","个");
m.put("dj",20);
m.put("zse",20);
m.put("amount",400);
m.put("jshj",420);
m.put("xmbh","XMBH000"+i);
m.put("xmmc","项目名称"+i);
m.put("dxgcmc","");
list.add(m);
}
data.put("list",list);
data.put("byjxs",1321);
data.put("bybhsje",1321);
data.put("byhsje",4654);
data.put("bdjxs",784);
data.put("bdbhsje",323);
data.put("bdhsje",1231);
// 映射为模板
XWPFDocument word = WordExportUtil.exportWord07(templateFile.getPath(),data);
String filename = "1.docx";
// 下载
response.setContentType("text/html; charset=UTF-8");
response.setContentType("application/octet-stream");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
word.write(response.getOutputStream());
}
这是什么原因?一上午都没找出问题出在哪


