pom.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/controller/ReportController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/mapper/PersonMapper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/pojo/Person.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/config/application-dev.yml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/template/template_01.docx | 补丁 | 查看 | 原始文档 | blame | 历史 |
pom.xml
@@ -115,6 +115,11 @@ <artifactId>javase</artifactId> <version>3.5.3</version> </dependency> <dependency> <groupId>org.docx4j</groupId> <artifactId>docx4j</artifactId> <version>6.1.2</version> </dependency> </dependencies> src/main/java/com/whyc/controller/ReportController.java
@@ -1,9 +1,19 @@ package com.whyc.controller; import com.whyc.service.ReportService; import org.docx4j.Docx4J; import org.docx4j.openpackaging.packages.WordprocessingMLPackage; import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.io.File; import java.text.SimpleDateFormat; import java.util.HashMap; import static org.docx4j.Docx4J.*; /** * 报告生成 @@ -15,4 +25,38 @@ @Autowired private ReportService service; @GetMapping("generateDocument") public void generateDocument(){ try { //获取classpath下的模板 String templatePath = this.getClass().getClassLoader().getResource("").getPath()+"resources\\template\\template_01.docx"; //加载模板 WordprocessingMLPackage wordprocessingMLPackage = WordprocessingMLPackage.load(new File(templatePath)); MainDocumentPart documentPart = wordprocessingMLPackage.getMainDocumentPart(); //查询巡检时候的电流电压温度数据 float current = 1.0f; float voltage = 2.0f; float temperature = 3.0f; String reporter = "whyc"; String inspectionTime = "2020-01-01 00:00:00"; HashMap<String,String> map = new HashMap<>(); map.put("current",current+""); map.put("voltage",voltage+""); map.put("temperature",temperature+""); map.put("reporter",reporter); map.put("inspectionTime",inspectionTime); //替换占位符 documentPart.variableReplace(map); //输出文件名称 SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); String fileName = "报告_01_"+format.format(System.currentTimeMillis())+".docx"; Docx4J.save(wordprocessingMLPackage, new File("C:\\code\\web\\InspectionSystem\\src\\main\\resources\\template\\"+fileName)); }catch(Exception e){ e.printStackTrace(); } } } src/main/java/com/whyc/mapper/PersonMapper.java
File was deleted src/main/java/com/whyc/pojo/Person.java
File was deleted src/main/resources/config/application-dev.yml
@@ -19,11 +19,13 @@ spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.highgo.jdbc.Driver # url: jdbc:dm://localhost:5236/SYSDBA?rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8 url: jdbc:highgo://192.168.10.183:5866/highgo?rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8 username: sysdba password: Lmx&8688139 driver-class-name: com.mysql.cj.jdbc.Driver # url: jdbc:mysql://localhost:3360/db_user?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true&useSSL=false url: jdbc:mysql://192.168.10.79:3360/db_user?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true # url: jdbc:mysql://192.168.10.80:3360/db_user?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true # url: jdbc:mysql://118.89.139.230:3360/db_user?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true username: root password: lmx8688139 maxIdel: 60 initialPoolSize: 2 minPoolSize: 5 src/main/resources/template/template_01.docxBinary files differ