Ver Fonte

fix excel及pdf数据超过5000条 excel样式超出excel限制问题,pdf导出 excel转pdf zipbom问题

tanjunjun há 1 ano atrás
pai
commit
7324a0c5bb

+ 3 - 0
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java

@@ -32,6 +32,7 @@ import com.itextpdf.text.pdf.PdfPCell;
 import com.itextpdf.text.pdf.PdfPTable;
 import com.itextpdf.text.pdf.PdfWriter;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.openxml4j.util.ZipSecureFile;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
@@ -215,6 +216,8 @@ public class ReportExcelServiceImpl implements ReportExcelService {
     // 将Excel文件转换为PDF
     public File convertExcelToPdf(String excelFilePath, String pdfFilePath, List<List<ReportExcelStyleDto>> reportExcelStyleList) {
         try {
+            //  解决excel转换为pdf zipboom问题
+            ZipSecureFile.setMinInflateRatio(0);
             // 读取Excel文件
             Workbook workbook = new XSSFWorkbook(excelFilePath);
             Sheet sheet = workbook.getSheetAt(0);

+ 4 - 3
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/util/XlsSheetUtil.java

@@ -48,11 +48,13 @@ public class XlsSheetUtil {
             List<JSONObject> cells_json = (List<JSONObject>) dbObject.get("celldata");
             Map<Integer, List<JSONObject>> cellMap = cellGroup(cells_json);
             //循环每一行
+            // 样式创建放到循环外层,防止样式过多,超出excel最大样式限制
+            CellStyle style = wb.createCellStyle();
             for (Integer r : cellMap.keySet()) {
                 Row row = sheet.createRow(r);
                 //循环每一列
                 for (JSONObject col : cellMap.get(r)) {
-                    createCell(wb, sheet, row, col);
+                    createCell(wb, sheet, row, col,style);
                 }
             }
         }
@@ -73,7 +75,7 @@ public class XlsSheetUtil {
      * @param row
      * @param dbObject
      */
-    private static void createCell(Workbook wb, Sheet sheet, Row row, JSONObject dbObject) {
+    private static void createCell(Workbook wb, Sheet sheet, Row row, JSONObject dbObject, CellStyle style) {
         if (dbObject.containsKey("c")) {
             Integer c = getStrToInt(dbObject.get("c"));
             if (c != null) {
@@ -97,7 +99,6 @@ public class XlsSheetUtil {
                     //转换v为对象(v是一个对象)
                     JSONObject v_json = (JSONObject) obj;
                     //样式
-                    CellStyle style = wb.createCellStyle();
                     cell.setCellStyle(style);