认证-上报库-自定义导出excel模板
This commit is contained in:
+23
-12
@@ -1,7 +1,5 @@
|
||||
package com.jero.modules.cert.report.service.impl;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
@@ -30,6 +28,7 @@ import com.jero.modules.cert.template.enums.ControlTypeEnum;
|
||||
import com.jero.modules.ocr.util.LineHumpUtil;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import com.jero.modules.project.util.ExcelUtil;
|
||||
import com.jero.modules.project.util.WordUtil;
|
||||
import com.jero.modules.split.common.ReadExcel;
|
||||
import com.jero.modules.system.entity.SysDictItem;
|
||||
@@ -37,7 +36,6 @@ import com.jero.modules.system.service.ISysDictItemService;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.util.HSSFColor;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
import org.aspectj.util.FileUtil;
|
||||
@@ -753,6 +751,7 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
||||
paramsReportExportHistoryEO.setExportTime(new Date());
|
||||
paramsReportExportHistoryEOService.add(paramsReportExportHistoryEO);
|
||||
|
||||
uploadFileio.close();
|
||||
os.flush();
|
||||
os.close(); // 后开先关
|
||||
fis.close(); // 先开后关
|
||||
@@ -795,7 +794,7 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
||||
|
||||
// 查询导出数据
|
||||
List<Map> allParamsInfoList = queryForExportCustom(paramsReportDetailVO);
|
||||
Map<String, Object> params = allParamsInfoList.get(0);
|
||||
HashMap<String, String> params = (HashMap<String, String>) allParamsInfoList.get(0);
|
||||
|
||||
String templateUrl = "";
|
||||
ParamsExportTemplateEO paramsExportTemplateEO = paramsExportTemplateEOService.getById(paramsReportDetailVO.getExportTemplateId());
|
||||
@@ -807,25 +806,37 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
||||
// 替换模板中的占位符
|
||||
try {
|
||||
|
||||
//下载关联文件内容
|
||||
List<OSSFile> allRelevFileList = (List<OSSFile>) allParamsInfoList.get(2).get("fileListAll");
|
||||
if (allRelevFileList != null && !allRelevFileList.isEmpty()) {
|
||||
allRelevFileList = allRelevFileList.stream().distinct().collect(Collectors.toList());
|
||||
downLoadFileList(allRelevFileList,fileNowPath + File.separator + "导出文件");
|
||||
}
|
||||
|
||||
// 拿取模板
|
||||
String repFileName = fileName.replaceAll("/","_");
|
||||
wordOS = new FileOutputStream(fileNowPath + File.separator + repFileName);
|
||||
if (CosBootUtil.doesObjectExist(templateUrl)) {
|
||||
InputStream wordTemplate = CosBootUtil.download(templateUrl);
|
||||
com.qcloud.cos.utils.IOUtils.copy(wordTemplate, wordOS);
|
||||
// com.qcloud.cos.utils.IOUtils.copy(wordTemplate, wordOS);
|
||||
|
||||
ExcelUtil.variableReplace(wordTemplate, wordOS, params);
|
||||
|
||||
}
|
||||
|
||||
// 替换占位符内容
|
||||
TemplateExportParams templateExportParams = new TemplateExportParams();
|
||||
templateExportParams.setTemplateUrl(fileNowPath + File.separator + repFileName);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(templateExportParams, params);
|
||||
// poi方式
|
||||
// TemplateExportParams templateExportParams = new TemplateExportParams();
|
||||
// templateExportParams.setTemplateUrl(fileNowPath + File.separator + repFileName);
|
||||
// Workbook workbook = ExcelExportUtil.exportExcel(templateExportParams, params);
|
||||
|
||||
OutputStream word = new FileOutputStream(fileNowPath + File.separator + repFileName);
|
||||
workbook.write(word);
|
||||
|
||||
// OutputStream word = new FileOutputStream(fileNowPath + File.separator + repFileName);
|
||||
// workbook.write(word);
|
||||
wordOS.flush();
|
||||
wordOS.close();
|
||||
word.flush();
|
||||
word.close();
|
||||
// word.flush();
|
||||
// word.close();
|
||||
|
||||
// 打包导出压缩包
|
||||
response.setHeader("Content-Disposition",
|
||||
|
||||
Reference in New Issue
Block a user