| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URLEncoder; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | |
| | | String fileName = ""; |
| | | switch (type) { |
| | | case 1: |
| | | fileName = "社区问题单"; |
| | | fileName = "community_question.docx"; |
| | | break; |
| | | case 2: |
| | | fileName = "问题处理单"; |
| | | fileName = "question_handle.docx"; |
| | | if (Objects.nonNull(partyMember)) { |
| | | community = community + "-" + partyMember.getServiceTarget(); |
| | | } |
| | |
| | | if (Objects.nonNull(record)) { |
| | | reportType = record.getReportType(); |
| | | } |
| | | fileName = "协调通知单"; |
| | | fileName = "notice.docx"; |
| | | break; |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | |
| | | response.setContentType("application/octet-stream"); |
| | | String fileNameEncode = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename=\"" + fileNameEncode + ".docx" + "\""); |
| | | ClassPathResource resource = new ClassPathResource("template/" + fileName + ".docx"); |
| | | XWPFTemplate.compile(resource.getFile()).render(map).writeAndClose(response.getOutputStream()); |
| | | InputStream resourceAsStream = this.getClass().getResourceAsStream("/template/" + fileName); |
| | | XWPFTemplate.compile(resourceAsStream).render(map).writeAndClose(response.getOutputStream()); |
| | | } |
| | | |
| | | |
| | |
| | | String content = "第一行内容\n第二行内容\n第三行内容"; |
| | | map.put("complaintProgress", content); |
| | | map.put("status", "处理中"); |
| | | XWPFTemplate.compile("F:\\DeskTop\\zhihuishequ\\springcloud_k8s_panzhihuazhihuishequ\\service_sangeshenbian\\src\\main\\resources\\template\\社区问题单.docx").render(map).writeToFile("F:\\DeskTop\\社区.docx"); |
| | | XWPFTemplate.compile("F:\\DeskTop\\zhihuishequ\\springcloud_k8s_panzhihuazhihuishequ\\service_sangeshenbian\\src\\main\\resources\\template\\community_question.docx").render(map).writeToFile("F:\\DeskTop\\社区.docx"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |