!169 excel导出数据超过5000条报错修复

Merge pull request !169 from tantian/dev
This commit is contained in:
WongBin
2024-05-24 05:58:16 +00:00
committed by Gitee
2 changed files with 7 additions and 3 deletions

View File

@@ -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);

View File

@@ -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);