|
|
@@ -6,9 +6,11 @@ import com.deepoove.poi.data.DocxRenderData;
|
|
|
import com.deepoove.poi.data.Includes;
|
|
|
import com.deepoove.poi.data.Pictures;
|
|
|
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
@@ -27,14 +29,13 @@ public class WordUtils {
|
|
|
public static void getWord1(Word1 word1, List<Word1.Detail> list, HttpServletResponse response) throws IOException {
|
|
|
// URL url = Thread.currentThread().getContextClassLoader().getResource("word/1.docx");
|
|
|
|
|
|
- // TODO 有时间处理资源打包jar 文件无法访问问题
|
|
|
- String url;
|
|
|
- String os = System.getProperty("os.name");
|
|
|
- if (os.toLowerCase().startsWith("win")) {
|
|
|
- url = WordUtils.class.getResource("/word/1.docx").getPath();
|
|
|
- }else {
|
|
|
- url = "/home/word_temp/1.docx";
|
|
|
- }
|
|
|
+// String url;
|
|
|
+// String os = System.getProperty("os.name");
|
|
|
+// if (os.toLowerCase().startsWith("win")) {
|
|
|
+// url = WordUtils.class.getResource("/word/1.docx").getPath();
|
|
|
+// }else {
|
|
|
+// url = "/home/word_temp/1.docx";
|
|
|
+// }
|
|
|
|
|
|
|
|
|
/*word1 = new Word1();
|
|
|
@@ -59,7 +60,11 @@ public class WordUtils {
|
|
|
|
|
|
Configure config = Configure.builder().bind("details", new LoopRowTableRenderPolicy()).build();
|
|
|
|
|
|
- XWPFTemplate template = XWPFTemplate.compile(url, config);
|
|
|
+ ClassPathResource classpathResource = new ClassPathResource("word/1.docx");
|
|
|
+
|
|
|
+// XWPFTemplate template = XWPFTemplate.compile(url, config);
|
|
|
+ XWPFTemplate template = XWPFTemplate.compile(classpathResource.getInputStream(), config);
|
|
|
+
|
|
|
template.render(
|
|
|
new HashMap<String, Object>(){{
|
|
|
|
|
|
@@ -85,7 +90,7 @@ public class WordUtils {
|
|
|
public static void getWord2(Word2 word2, List<Word2.Detail> list, HttpServletResponse response) throws IOException {
|
|
|
// URL url = Thread.currentThread().getContextClassLoader().getResource("word/2.docx");
|
|
|
|
|
|
- String url, detailUrl;
|
|
|
+ /*String url, detailUrl;
|
|
|
|
|
|
String os = System.getProperty("os.name");
|
|
|
if (os.toLowerCase().startsWith("win")) {
|
|
|
@@ -94,7 +99,7 @@ public class WordUtils {
|
|
|
}else {
|
|
|
url = "/home/word_temp/2.docx";
|
|
|
detailUrl = "/home/word_temp/word2_detail.docx";
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
/*word2 = new Word2();
|
|
|
word2.setDept_name("环境与测绘学院");
|
|
|
@@ -138,10 +143,11 @@ public class WordUtils {
|
|
|
|
|
|
// Configure config = Configure.builder().bind("%", new PictureRenderPolicy()).build();
|
|
|
|
|
|
- Configure config = Configure.createDefault()
|
|
|
- .plugin('%', new SignPicPolicy());
|
|
|
+ Configure config = Configure.createDefault().plugin('%', new SignPicPolicy());
|
|
|
+
|
|
|
+ ClassPathResource classpathResource = new ClassPathResource("word/2.docx");
|
|
|
|
|
|
- XWPFTemplate template = XWPFTemplate.compile(url, config);
|
|
|
+ XWPFTemplate template = XWPFTemplate.compile(classpathResource.getInputStream(), config);
|
|
|
template.render(
|
|
|
new HashMap<String, Object>(){{
|
|
|
|
|
|
@@ -159,7 +165,9 @@ public class WordUtils {
|
|
|
}
|
|
|
}
|
|
|
// put("details",wordPolicy);
|
|
|
- put("details", Includes.ofLocal(detailUrl).setRenderModel(list).create());
|
|
|
+ ClassPathResource classpathResource = new ClassPathResource("word/word2_detail.docx");
|
|
|
+// put("details", Includes.ofLocal(classpathResource.getInputStream()).setRenderModel(list).create());
|
|
|
+ put("details", Includes.ofStream(classpathResource.getInputStream()).setRenderModel(list).create());
|
|
|
}});
|
|
|
// template.writeAndClose(new FileOutputStream("E:\\out2.docx"));
|
|
|
template.write(response.getOutputStream());
|
|
|
@@ -168,7 +176,7 @@ public class WordUtils {
|
|
|
|
|
|
public static void getWord3(Word3 word3, List<Word3.Detail> list, List<Word3.Descs> descs, HttpServletResponse response) throws IOException {
|
|
|
// URL url = Thread.currentThread().getContextClassLoader().getResource("word/3.docx");
|
|
|
- String url, detailUrl;
|
|
|
+ /*String url, detailUrl;
|
|
|
|
|
|
String os = System.getProperty("os.name");
|
|
|
if (os.toLowerCase().startsWith("win")) {
|
|
|
@@ -177,7 +185,7 @@ public class WordUtils {
|
|
|
}else {
|
|
|
url = "/home/word_temp/3.docx";
|
|
|
detailUrl = "/home/word_temp/word3_detail.docx";
|
|
|
- }
|
|
|
+ }*/
|
|
|
/*word3 = new Word3();
|
|
|
word3.setCode("001");
|
|
|
word3.setDept_name("环境与测绘学院");
|
|
|
@@ -221,7 +229,9 @@ public class WordUtils {
|
|
|
Configure config = Configure.builder().bind("details", new LoopRowTableRenderPolicy())
|
|
|
.addPlugin('%', new SignPicPolicy()).build();
|
|
|
|
|
|
- XWPFTemplate template = XWPFTemplate.compile(url, config);
|
|
|
+ ClassPathResource classpathResource = new ClassPathResource("word/3.docx");
|
|
|
+
|
|
|
+ XWPFTemplate template = XWPFTemplate.compile(classpathResource.getInputStream(), config);
|
|
|
template.render(
|
|
|
new HashMap<String, Object>(){{
|
|
|
|
|
|
@@ -239,7 +249,8 @@ public class WordUtils {
|
|
|
}
|
|
|
}
|
|
|
put("details",list);
|
|
|
- put("descs", Includes.ofLocal(detailUrl).setRenderModel(descs).create());
|
|
|
+ ClassPathResource classpathResource = new ClassPathResource("word/word3_detail.docx");
|
|
|
+ put("descs", Includes.ofStream(classpathResource.getInputStream()).setRenderModel(descs).create());
|
|
|
}});
|
|
|
// template.writeAndClose(new FileOutputStream("E:\\out3.docx"));
|
|
|
template.write(response.getOutputStream());
|