word文件做成代码:其中包含表格,图片,埋点文字等
ExportWordByTempUtils exportWordByTempUtils = new ExportWordByTempUtils();
String filePath = exportWordByTempUtils.getFilePath("template/project.docx");
String resFilePath = StringUtils.substringBeforeLast(filePath, "/").concat("/res/");
ClassPathResource picture1 = new ClassPathResource("template/images/one1.png");
InputStream picture1InputStream = picture1.getInputStream();
ClassPathResource picture2 = new ClassPathResource("template/images/two1.png");
InputStream picture2InputStream = picture2.getInputStream();
ClassPathResource picture3 = new ClassPathResource("template/images/three1.png");
InputStream picture3InputStream = picture3.getInputStream();
Map<String, InputStream> picMap = new HashMap<>();
picMap.put("picture1", picture1InputStream);
picMap.put("picture2", picture2InputStream);
picMap.put("picture3", picture3InputStream);
ClassPathResource resource = new ClassPathResource("template/project.docx");
InputStream in = resource.getInputStream();
XWPFDocument document = new XWPFDocument(in);
changeText(document, map, picMap);
createProjectTable(document, one, two, three, four);
generatorWord(document, response, fileName, resFilePath);
1.获取jar中的文件路径
ExportWordByTempUtils exportWordByTempUtils = new ExportWordByTempUtils(); String filePath = exportWordByTempUtils.getFilePath("template/project.docx"); String resFilePath = StringUtils.substringBeforeLast(filePath, "/").concat("/res/");
ClassPathResource resource = new ClassPathResource("template/project.docx"); InputStream in = resource.getInputStream(); XWPFDocument document = new XWPFDocument(in);
问题:不能直接用文件流来获取jar中的文件,文件流获取的是文件夹的路径,但是jar不是文件夹。
解决:所以才会有这种解决方式。