读取word模板导出文档(学习未验证)
需要导入这个包
<!-- freemarker -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.28</version>
</dependency>
解读:
(前提,其中读取的是ftl后缀的模板,这个好像是word设置域就是${username}那些,然后转换为xml在转换为ftl,可百度)
1.查询需要打印的数据
2.组装到一个map集合里面
3.读取模板
4.调用工具类TemplateUtils.createDoc方法生成word文档(TemplateUtils工具类附下面了)
5.读文件(也是调用接口 附下面了)
6.设置respnse信息 开始写
7.删除临时文件(也是调用接口 附下面了)
@IgnoreSysLog
@ApiOperation(value = "节水三同时上报-打印验收表", notes = "节水三同时上报-打印验收表", produces = "application/json")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "path", name = "waterBaseId", value = "节水三同时上报-删除", required = true, dataType = "long")})
@PostMapping(value = URI_SAVING_THREE_PRINT_CHECK)
public void printThreeSimultaneousCheck(@PathVariable("waterBaseId") Long waterBaseId, HttpServletResponse response) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("节水三同时上报-打印验收表失败");
}
WaterSavingBaseTotalDTO waterSavingBaseTotalDTO = waterSavingService.checkSeeThreeSimultaneousReport(waterBaseId);
WaterSavingBaseCheckDTO waterSavingBaseCheckDTO = waterSavingService.seeThreeSimultaneousReport(waterBaseId);
final Map<String, Object> map = newHashMapWithExpectedSize(1);
String time = new SimpleDateFormat("yyyy-MM-dd").format(new Date()).toString();
try {
map.put("year", time.substring(0, 4));
map.put("month", time.substring(5, 7));
map.put("day", time.substring(8, 10));
map.put("applicant", waterSavingBaseTotalDTO.getWaterSavingBaseTotal().getApplicant());
map.put("constrotionProject", waterSavingBaseTotalDTO.getWaterSavingBaseTotal().getConstrotionProject());
map.put("contactPerson", waterSavingBaseTotalDTO.getWaterSavingBaseTotal().getContactPerson());
map.put("contactPhone", waterSavingBaseTotalDTO.getWaterSavingBaseTotal().getContactPhone());
map.put("designUnit", waterSavingBaseTotalDTO.getWaterSavingBaseTotal().getDesignUnit());
map.put("constructionUnit", waterSavingBaseCheckDTO.getConstructionUnit());
map.put("controlUnit", waterSavingBaseCheckDTO.getControlUnit());
map.put("constrotionAddress", waterSavingBaseTotalDTO.getWaterSavingBaseTotal().getConstrotionAddress());
map.put("plannedArea", waterSavingBaseCheckDTO.getPlannedArea().