From d9e60eb2703beab9f186324f9490ba04d4f933c8 Mon Sep 17 00:00:00 2001 From: chenjiahe <763432473@qq.com> Date: 星期五, 09 六月 2023 16:44:18 +0800 Subject: [PATCH] excel导出导致CPU爆炸优化 --- src/main/java/com/hx/util/ExcelUtil.java | 20 +++++++++----------- 1 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/hx/util/ExcelUtil.java b/src/main/java/com/hx/util/ExcelUtil.java index a21a8dc..760a342 100644 --- a/src/main/java/com/hx/util/ExcelUtil.java +++ b/src/main/java/com/hx/util/ExcelUtil.java @@ -5,10 +5,8 @@ import org.apache.poi.hssf.usermodel.*; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.usermodel.*; import org.springframework.web.multipart.MultipartFile; @@ -284,11 +282,11 @@ width = 5000; } // 鍒涘缓鏂扮殑Excel 宸ヤ綔绨� - XSSFWorkbook workbook = new XSSFWorkbook(); - + //XSSFWorkbook workbook = new XSSFWorkbook(); + SXSSFWorkbook workbook = new SXSSFWorkbook(1000); //鍚堝苟鐨勫崟鍏冩牸鏍峰紡 - XSSFCellStyle boderStyle = workbook.createCellStyle(); + CellStyle boderStyle = workbook.createCellStyle(); //鍨傜洿灞呬腑 boderStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); boderStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 鍒涘缓涓�涓眳涓牸寮� @@ -296,11 +294,11 @@ // 鍦‥xcel宸ヤ綔绨夸腑寤轰竴宸ヤ綔琛紝鍏跺悕涓虹己鐪佸�� // 濡傝鏂板缓涓�鍚嶄负"鏁堢泭鎸囨爣"鐨勫伐浣滆〃锛屽叾璇彞涓猴細 // HSSFSheet sheet = workbook.createSheet("鏁堢泭鎸囨爣"); - XSSFSheet sheet = workbook.createSheet(); + Sheet sheet = workbook.createSheet(); // 鍦ㄧ储寮�0鐨勪綅缃垱寤鸿锛堟渶椤剁鐨勮锛� - XSSFRow row = sheet.createRow(0); + Row row = sheet.createRow(0); // =============================================================== - XSSFCell cell; + Cell cell; for (int i = 0; i < headList.length; i++) { //楂樺害 row.setHeight(height.shortValue()); @@ -315,7 +313,7 @@ } // =============================================================== if (dataList != null) { - XSSFRow row_value; + Row row_value; Map<String, Object> dataMap; for (int n = 0; n < dataList.size(); n++) { // 鍦ㄧ储寮�1鐨勪綅缃垱寤鸿 -- Gitblit v1.8.0