Browse Source

无法正常下载报告的问题

tags/v1.1.0
qiujinyang 2 years ago
parent
commit
fa0ae70764
1 changed files with 7 additions and 1 deletions
  1. +7
    -1
      tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/ReportServiceImpl.java

+ 7
- 1
tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/ReportServiceImpl.java View File

f.delete(); f.delete();
f.createNewFile(); f.createNewFile();
} }
log.info("开始编写word文件,文件为:{}",filePath);
wordUtils.openDocument(filePath); wordUtils.openDocument(filePath);
wordUtils.getDocument().setPageSize(PageSize.A4); wordUtils.getDocument().setPageSize(PageSize.A4);
wordUtils.getDocument().setMargins(71f, 71f, 72f, 72f); wordUtils.getDocument().setMargins(71f, 71f, 72f, 72f);
table.addCell(cell); table.addCell(cell);
} }
wordUtils.getDocument().add(table); wordUtils.getDocument().add(table);
log.info("林场信息写入完成");


wordUtils.insertTitlePatternThird("二:巡检信息", WordUtilsOld.rtfGsBt3); wordUtils.insertTitlePatternThird("二:巡检信息", WordUtilsOld.rtfGsBt3);
Table table2 = new Table(2);//生成一表格 Table table2 = new Table(2);//生成一表格
table2.addCell(cell); table2.addCell(cell);
} }
wordUtils.getDocument().add(table2); wordUtils.getDocument().add(table2);
log.info("巡检信息写入完成");


List<QuestionTypeCountVO> questionTypeInfo = reportInfoVO.getQuestionTypeInfo(); List<QuestionTypeCountVO> questionTypeInfo = reportInfoVO.getQuestionTypeInfo();
Map<String, Integer> questionCount=new HashMap<>(); Map<String, Integer> questionCount=new HashMap<>();
wordUtils.getDocument().add(table3); wordUtils.getDocument().add(table3);
} }


log.info("巡检结果写入完成");
if (reportInfoVO.getQuestionReportList().size() > 0) { if (reportInfoVO.getQuestionReportList().size() > 0) {
wordUtils.insertTitlePatternThird("四:问题清单", WordUtilsOld.rtfGsBt3); wordUtils.insertTitlePatternThird("四:问题清单", WordUtilsOld.rtfGsBt3);
log.info("报告标题四成功"); log.info("报告标题四成功");
} }


wordUtils.closeDocument(); wordUtils.closeDocument();
log.info("问题清单写入完成");


//清空缓存 //清空缓存
response.reset(); response.reset();
// 定义浏览器响应表头,并定义下载名 // 定义浏览器响应表头,并定义下载名
String urlFileName = URLEncoder.encode("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.doc", "UTF-8");
String urlFileName = URLEncoder.encode("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.docx", "UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=" + urlFileName); response.setHeader("Content-Disposition", "attachment;filename=" + urlFileName);
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8");
//定义下载的类型 //定义下载的类型
OutputStream out; OutputStream out;
File files = new File(filePath); File files = new File(filePath);


log.info("读出的文件文件地址为:{}",filePath);
FileInputStream inputStream = new FileInputStream(files); FileInputStream inputStream = new FileInputStream(files);
//3.通过response获取ServletOutputStream对象(out) //3.通过response获取ServletOutputStream对象(out)
out = response.getOutputStream(); out = response.getOutputStream();

Loading…
Cancel
Save