认证-上报库-自定义导出excel模板-图片处理

This commit is contained in:
liyawei
2022-07-29 18:18:55 +08:00
parent 5627ff30ac
commit 32730675dc
3 changed files with 384 additions and 45 deletions
@@ -53,6 +53,7 @@ public interface IParamsReportDetailEOService extends IService<ParamsReportDetai
// 自定义导出-word模板
void exportCustomWord(ParamsReportDetailVO paramsReportDetailVO, HttpServletResponse response, HttpServletRequest request);
// 自定义导出-excel模板
void exportCustomExcel(ParamsReportDetailVO paramsReportDetailVO, HttpServletResponse response, HttpServletRequest request);
}
@@ -36,11 +36,14 @@ 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.ss.usermodel.WorkbookFactory;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.usermodel.*;
import org.aspectj.util.FileUtil;
import org.docx4j.Docx4J;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -795,6 +798,7 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
// 查询导出数据
List<Map> allParamsInfoList = queryForExportCustom(paramsReportDetailVO);
HashMap<String, String> params = (HashMap<String, String>) allParamsInfoList.get(0);
List<Map<String, Object>> imgListAll = (List<Map<String, Object>>) allParamsInfoList.get(1).get("imgListAll");
String templateUrl = "";
ParamsExportTemplateEO paramsExportTemplateEO = paramsExportTemplateEOService.getById(paramsReportDetailVO.getExportTemplateId());
@@ -820,7 +824,14 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
InputStream wordTemplate = CosBootUtil.download(templateUrl);
// com.qcloud.cos.utils.IOUtils.copy(wordTemplate, wordOS);
ExcelUtil.variableReplace(wordTemplate, wordOS, params);
// 替换占位符内容
// docx4j方式
InputStream excelTemplate = CosBootUtil.download(templateUrl);
SpreadsheetMLPackage pkg = SpreadsheetMLPackage.load(wordTemplate);
Workbook workbook = WorkbookFactory.create(excelTemplate);
ExcelUtil.replacePictureBatchPOI(workbook, pkg, imgListAll);
ExcelUtil.variableReplace(pkg, params);
pkg.save(wordOS);
}