|
@@ -0,0 +1,47 @@
|
|
|
|
|
+package com.common.workflow.web.rest;
|
|
|
|
|
+
|
|
|
|
|
+import com.common.workflow.service.util.WordTemplate;
|
|
|
|
|
+import com.common.workflow.web.rest.vm.WordTemplateVM;
|
|
|
|
|
+import com.deepoove.poi.XWPFTemplate;
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import javax.validation.Valid;
|
|
|
|
|
+import java.io.OutputStream;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Created by gyue on 2019-03-18.
|
|
|
|
|
+ */
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/api/word")
|
|
|
|
|
+public class WordResource {
|
|
|
|
|
+ private final Logger log = LoggerFactory.getLogger(WordResource.class);
|
|
|
|
|
+
|
|
|
|
|
+ public WordResource() {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/fill-word")
|
|
|
|
|
+ public void fillWordTemplate(@Valid @RequestBody WordTemplateVM wordTemplateVM, HttpServletResponse response) throws Exception {
|
|
|
|
|
+ response.reset();
|
|
|
|
|
+ response.setContentType("multipart/form-data");//;charset=utf-8
|
|
|
|
|
+ response.setHeader("content-disposition", "attachment;filename=details12.docx");
|
|
|
|
|
+ response.setHeader("Pragma","No-cache");
|
|
|
|
|
+ response.setHeader ( "Cache-Control", "no-store");
|
|
|
|
|
+ response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
|
+ response.setHeader("Access-Control-Allow-Headers", "*");
|
|
|
|
|
+ OutputStream outputStream = response.getOutputStream();
|
|
|
|
|
+ WordTemplate wordTemplate = new WordTemplate();
|
|
|
|
|
+ XWPFTemplate template = wordTemplate.exportWordTemplate(wordTemplateVM.getDatas(), wordTemplateVM.getTemplateUrl());
|
|
|
|
|
+ template.write(outputStream);
|
|
|
|
|
+ outputStream.flush();
|
|
|
|
|
+ outputStream.close();
|
|
|
|
|
+ template.close();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|