Kaynağa Gözat

修复导出excel的数量过大时报GC overhead limit exceeded问题

seyason 2 yıl önce
ebeveyn
işleme
9ee31631af

+ 2 - 2
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ExcelExportServiceImpl.java

@@ -62,7 +62,7 @@ public class ExcelExportServiceImpl implements ExcelExportService {
     public HttpRespMsg exportGeneralExcelByTitleAndList(WxCorpInfo wxCorpInfo, String title, List<List<String>> list, String downloadPath) throws Exception {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         String resp = ExcelUtil.exportGeneralExcelByTitleAndList(title, list, downloadPath);
-        String fileUrlSuffix = title + ".xls";
+        String fileUrlSuffix = title + ".xlsx";
         if(wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1){
             String mediaId = wxCorpInfoService.getTranslationMediaId(fileUrlSuffix);
             String jobId = wxCorpInfoService.syncTranslation(wxCorpInfo.getCorpid(),mediaId,fileUrlSuffix, null);
@@ -143,7 +143,7 @@ public class ExcelExportServiceImpl implements ExcelExportService {
     public  HttpRespMsg exportMultiSheetGeneralExcelByTitleAndList(WxCorpInfo wxCorpInfo,String title, List<List<String>>[] multiSheetList, String downloadPath,String[] sheetsName) throws Exception {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         String resp = ExcelUtil.exportMultiSheetGeneralExcelByTitleAndList(title,multiSheetList, downloadPath,sheetsName);
-        String fileUrlSuffix = title + ".xls";
+        String fileUrlSuffix = title + ".xlsx";
         if(wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1){
             String mediaId = wxCorpInfoService.getTranslationMediaId(fileUrlSuffix);
             String jobId = wxCorpInfoService.syncTranslation(wxCorpInfo.getCorpid(),mediaId,fileUrlSuffix, null);

+ 47 - 44
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/ExcelUtil.java

@@ -7,6 +7,7 @@ import com.management.platform.service.CorpwxJobResultService;
 import com.management.platform.service.WxCorpInfoService;
 import org.apache.poi.hssf.usermodel.*;
 import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.apache.poi.xssf.usermodel.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -27,7 +28,7 @@ public class ExcelUtil {
 
     public static String exportGeneralExcelByTitleAndList(String title, List<List<String>> list, String downloadPath) {
         String result="系统提示:Excel文件导出成功!";
-        String fileName= title+".xls";
+        String fileName= title+".xlsx";
         try {
 //            response.reset();
 //            response.setHeader("Content-disposition",
@@ -36,25 +37,26 @@ public class ExcelUtil {
 //            response.setContentType("APPLICATION/OCTET-STREAM;charset=UTF-8");//设置类型
 //            response.setHeader("Cache-Control","no-cache");//设置头
 //            response.setDateHeader("Expires", 0);//设置日期头
-            // 创建工作簿
-            HSSFWorkbook workBook = new HSSFWorkbook();
+            // 创建工作簿, 换成XSSSF 来支持万以上的数据
+            SXSSFWorkbook workBook = new SXSSFWorkbook();
+//            HSSFWorkbook workBook = new HSSFWorkbook();
             // 创建工作类
-            HSSFSheet sheet = workBook.createSheet();
+            Sheet sheet = workBook.createSheet();
             //设置首行冻结
             sheet.createFreezePane(0, 1);
             sheet.setDefaultColumnWidth(16);
             //设置字体样式
-            HSSFFont headFont = workBook.createFont();
+            Font headFont = workBook.createFont();
             headFont.setBold(true);
             headFont.setFontHeightInPoints((short) 10);
             headFont.setFontName("黑体");
 
-            HSSFFont titleFont = workBook.createFont();
+            Font titleFont = workBook.createFont();
             titleFont.setBold(true);
             titleFont.setFontHeightInPoints((short) 10);
             titleFont.setFontName("黑体");
 
-            HSSFFont font = workBook.createFont();
+            Font font = workBook.createFont();
             font.setFontHeightInPoints((short) 10);
             font.setFontName("宋体");
 
@@ -76,9 +78,9 @@ public class ExcelUtil {
             int b = Integer.parseInt((color.substring(4,6)),16);
 
             //自定义cell颜色
-            HSSFPalette palette = workBook.getCustomPalette();
+//            HSSFPalette palette = workBook.getCustomPalette();
             //这里的9是索引
-            palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
+//            palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
 
             CellStyle titleStyle = workBook.createCellStyle();
             titleStyle.setFont(titleFont);
@@ -122,11 +124,11 @@ public class ExcelUtil {
                 */
                 int start = 0;
                 for(List<String> rowList : list) {
-                    HSSFRow row = sheet.createRow(start);
+                    Row row = sheet.createRow(start);
                     row.setHeightInPoints(24);
 
                     for(int i = 0; i < rowList.size(); i++) {
-                        HSSFCell cell = row.createCell(i);
+                        Cell cell = row.createCell(i);
                         if(start == 0) {
                             cell.setCellStyle(titleStyle);
                         }else {
@@ -173,29 +175,30 @@ public class ExcelUtil {
 //            response.setHeader("Cache-Control","no-cache");//设置头
 //            response.setDateHeader("Expires", 0);//设置日期头
             // 创建工作簿
-            XSSFWorkbook workBook = new XSSFWorkbook();
+            SXSSFWorkbook workBook = new SXSSFWorkbook();
+//            XSSFWorkbook workBook = new XSSFWorkbook();
             // 创建工作类
-            XSSFSheet sheet = workBook.createSheet();
+            Sheet sheet = workBook.createSheet();
             //设置首行冻结
             sheet.createFreezePane(0, 1);
             sheet.setDefaultColumnWidth(16);
             //设置字体样式
-            XSSFFont headFont = workBook.createFont();
+            Font headFont = workBook.createFont();
             headFont.setBold(true);
             headFont.setFontHeightInPoints((short) 10);
             headFont.setFontName("黑体");
 
-            XSSFFont titleFont = workBook.createFont();
+            Font titleFont = workBook.createFont();
             titleFont.setBold(true);
             titleFont.setFontHeightInPoints((short) 10);
             titleFont.setFontName("黑体");
 
-            XSSFFont font = workBook.createFont();
+            Font font = workBook.createFont();
             font.setFontHeightInPoints((short) 10);
             font.setFontName("宋体");
 
             //设置单元格样式
-            XSSFCellStyle headStyle = workBook.createCellStyle();
+            CellStyle headStyle = workBook.createCellStyle();
             headStyle.setFont(headFont);
             headStyle.setAlignment(HorizontalAlignment.CENTER);
             headStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
@@ -206,7 +209,7 @@ public class ExcelUtil {
             headStyle.setBorderRight(BorderStyle.THIN);//右边框
 
 
-            XSSFCellStyle titleStyle = workBook.createCellStyle();
+            CellStyle titleStyle = workBook.createCellStyle();
             titleStyle.setFont(titleFont);
             titleStyle.setAlignment(HorizontalAlignment.CENTER);
             titleStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
@@ -218,7 +221,7 @@ public class ExcelUtil {
             titleStyle.setBorderTop(BorderStyle.THIN);//上边框
             titleStyle.setBorderRight(BorderStyle.THIN);//右边框
 
-            XSSFCellStyle cellStyle = workBook.createCellStyle();
+            CellStyle cellStyle = workBook.createCellStyle();
             cellStyle.setFont(font);
             cellStyle.setAlignment(HorizontalAlignment.CENTER);
             cellStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
@@ -248,11 +251,11 @@ public class ExcelUtil {
                 */
                 int start = 0;
                 for(List<String> rowList : list) {
-                    XSSFRow row = sheet.createRow(start);
+                    Row row = sheet.createRow(start);
                     row.setHeightInPoints(24);
 
                     for(int i = 0; i < rowList.size(); i++) {
-                        XSSFCell cell = row.createCell(i);
+                        Cell cell = row.createCell(i);
                         if(start == 0) {
                             cell.setCellStyle(titleStyle);
                         }else {
@@ -289,29 +292,29 @@ public class ExcelUtil {
 
     public static String exportTwoSheetGeneralExcelByTitleAndList(String title, List<List<String>> sheetOneList,List<List<String>> sheetTwoList, String downloadPath,String sheetOneName,String sheetTwoName) {
         String result="系统提示:Excel文件导出成功!";
-        String fileName= title+".xls";
+        String fileName= title+".xlsx";
         try {
             // 创建工作簿
-            HSSFWorkbook workBook = new HSSFWorkbook();
+            SXSSFWorkbook workBook = new SXSSFWorkbook();
             // 创建工作类
-            HSSFSheet sheetOne = workBook.createSheet();
+            Sheet sheetOne = workBook.createSheet();
             workBook.setSheetName(0,sheetOneName);
-            HSSFSheet sheetTwo = workBook.createSheet();
+            Sheet sheetTwo = workBook.createSheet();
             workBook.setSheetName(1,sheetTwoName);
             sheetOne.setDefaultColumnWidth(16);
             sheetTwo.setDefaultColumnWidth(16);
             //设置字体样式
-            HSSFFont headFont = workBook.createFont();
+            Font headFont = workBook.createFont();
             headFont.setBold(true);
             headFont.setFontHeightInPoints((short) 10);
             headFont.setFontName("黑体");
 
-            HSSFFont titleFont = workBook.createFont();
+            Font titleFont = workBook.createFont();
             titleFont.setBold(true);
             titleFont.setFontHeightInPoints((short) 10);
             titleFont.setFontName("黑体");
 
-            HSSFFont font = workBook.createFont();
+            Font font = workBook.createFont();
             font.setFontHeightInPoints((short) 10);
             font.setFontName("宋体");
 
@@ -333,9 +336,9 @@ public class ExcelUtil {
             int b = Integer.parseInt((color.substring(4,6)),16);
 
             //自定义cell颜色
-            HSSFPalette palette = workBook.getCustomPalette();
+//            HSSFPalette palette = workBook.getCustomPalette();
             //这里的9是索引
-            palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
+//            palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
 
             CellStyle titleStyle = workBook.createCellStyle();
             titleStyle.setFont(titleFont);
@@ -379,10 +382,10 @@ public class ExcelUtil {
                 */
                 int start = 0;
                 for(List<String> rowList : sheetOneList) {
-                    HSSFRow row = sheetOne.createRow(start);
+                    Row row = sheetOne.createRow(start);
                     row.setHeightInPoints(24);
                     for(int i = 0; i < rowList.size(); i++) {
-                        HSSFCell cell = row.createCell(i);
+                        Cell cell = row.createCell(i);
                         if(start == 0) {
                             cell.setCellStyle(titleStyle);
                         }else {
@@ -396,10 +399,10 @@ public class ExcelUtil {
             if(sheetTwoList.size()>0){
                 int start = 0;
                 for(List<String> rowList : sheetTwoList) {
-                    HSSFRow row = sheetTwo.createRow(start);
+                    Row row = sheetTwo.createRow(start);
                     row.setHeightInPoints(24);
                     for(int i = 0; i < rowList.size(); i++) {
-                        HSSFCell cell = row.createCell(i);
+                        Cell cell = row.createCell(i);
                         if(start == 0) {
                             cell.setCellStyle(titleStyle);
                         }else {
@@ -428,28 +431,28 @@ public class ExcelUtil {
 
     public static String exportMultiSheetGeneralExcelByTitleAndList(String title, List<List<String>>[] multiSheetList, String downloadPath,String[] sheetsName) {
         String result="系统提示:Excel文件导出成功!";
-        String fileName= title+".xls";
+        String fileName= title+".xlsx";
         try {
             // 创建工作簿
-            HSSFWorkbook workBook = new HSSFWorkbook();
+            SXSSFWorkbook workBook = new SXSSFWorkbook();
             // 创建工作类
             for (int sheetIndex=0;sheetIndex<multiSheetList.length; sheetIndex++) {
-                HSSFSheet sheetOne = workBook.createSheet();
+                Sheet sheetOne = workBook.createSheet();
                 workBook.setSheetName(sheetIndex,sheetsName[sheetIndex]);
                 sheetOne.setDefaultColumnWidth(16);
 
                 //设置字体样式
-                HSSFFont headFont = workBook.createFont();
+                Font headFont = workBook.createFont();
                 headFont.setBold(true);
                 headFont.setFontHeightInPoints((short) 10);
                 headFont.setFontName("黑体");
 
-                HSSFFont titleFont = workBook.createFont();
+                Font titleFont = workBook.createFont();
                 titleFont.setBold(true);
                 titleFont.setFontHeightInPoints((short) 10);
                 titleFont.setFontName("黑体");
 
-                HSSFFont font = workBook.createFont();
+                Font font = workBook.createFont();
                 font.setFontHeightInPoints((short) 10);
                 font.setFontName("宋体");
 
@@ -471,9 +474,9 @@ public class ExcelUtil {
                 int b = Integer.parseInt((color.substring(4,6)),16);
 
                 //自定义cell颜色
-                HSSFPalette palette = workBook.getCustomPalette();
+//                HSSFPalette palette = workBook.getCustomPalette();
                 //这里的9是索引
-                palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
+//                palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
 
                 CellStyle titleStyle = workBook.createCellStyle();
                 titleStyle.setFont(titleFont);
@@ -500,10 +503,10 @@ public class ExcelUtil {
                 if(multiSheetList[sheetIndex].size() > 0) {
                     int start = 0;
                     for(List<String> rowList : multiSheetList[sheetIndex]) {
-                        HSSFRow row = sheetOne.createRow(start);
+                        Row row = sheetOne.createRow(start);
                         row.setHeightInPoints(24);
                         for(int i = 0; i < rowList.size(); i++) {
-                            HSSFCell cell = row.createCell(i);
+                            Cell cell = row.createCell(i);
                             if(start == 0) {
                                 cell.setCellStyle(titleStyle);
                             }else {

+ 19 - 19
fhKeeper/formulahousekeeper/timesheet/src/views/corpreport/list.vue

@@ -1490,25 +1490,25 @@ export default {
         var fName = "";
         var sl = {}
         if (this.ins == 0) {  
-          fName = this.$t('projectreport') + '.xls';
+          fName = this.$t('projectreport') + '.xlsx';
           url += "/exportProject";
         } else if (this.ins == 1) {
-          fName = this.$t('projectTaskReport') + '.xls';
+          fName = this.$t('projectTaskReport') + '.xlsx';
           url += "/exportProjectTask";
           if(this.taskTypeId != 'null' && this.taskTypeId != null && this.taskTypeId != '') {
             sl.taskType = this.taskTypeId
           }
         } else if (this.ins == 2) {
-          fName = this.$t('projectcoststatement') + '.xls';
+          fName = this.$t('projectcoststatement') + '.xlsx';
           url += "/exportAllProjectCost";
         } else if (this.ins == 3) {
-          fName = this.$t('projectbalancesheet') + '.xls';
+          fName = this.$t('projectbalancesheet') + '.xlsx';
           url += "/exportProjectInAndOut";
         } else if (this.ins == 4) {
-          fName = this.$t('customerprojectprofitstatement') + '.xls';
+          fName = this.$t('customerprojectprofitstatement') + '.xlsx';
           url += "/exportCustomerProjectInAndOut";
         } else if (this.ins == 5) {
-          fName = this.$t('projectphasetimereport') + '.xls';
+          fName = this.$t('projectphasetimereport') + '.xlsx';
           url += "/exportProjectStagesCost";
           if(this.stageNames.length){
             let stagestr = ''
@@ -1521,7 +1521,7 @@ export default {
             sl.endDate = this.rangeDatas[1]
           }
         } else if (this.ins == 6) {
-          fName = this.$t('statisticalreportofovertimework')  + '.xls';
+          fName = this.$t('statisticalreportofovertimework')  + '.xlsx';
           url += "/exportOvertimeList";
           sl.startDate = this.rangeDatas[0]
           sl.endDate = this.rangeDatas[1]
@@ -1532,10 +1532,10 @@ export default {
           }
           sl.departmentId = deptid
         } else if (this.ins == 7) {
-          fName = this.$t('timecostearlywarningtable')  + '.xls';
+          fName = this.$t('timecostearlywarningtable')  + '.xlsx';
           url += "/exportBaseCostAndRealCost";
         } else if (this.ins == 8) {
-          fName = this.$t('personneltimeallocationtable')  + '.xls'
+          fName = this.$t('personneltimeallocationtable')  + '.xlsx'
           url += "/exportUserWorkingTimeList"
           sl.startDate = this.rangeDatas[0]
           sl.endDate = this.rangeDatas[1]
@@ -1546,12 +1546,12 @@ export default {
             sl.userId = this.userId
           }
         } else if (this.ins == 9) {
-          fName = this.$t('personnelfillingtimelyratestatistics')  + '.xls'
+          fName = this.$t('personnelfillingtimelyratestatistics')  + '.xlsx'
           url += "/exportReportTimelinessRate"
           sl.startDate = this.rangeDatas[0]
           sl.endDate = this.rangeDatas[1]
         } else if (this.ins == 10) {
-          fName = this.$t('dailyreporttobereviewedstatistics')  + '.xls'
+          fName = this.$t('dailyreporttobereviewedstatistics')  + '.xlsx'
           url += "/exportWaitingReviewList"
           sl.startDate = this.rangeDatas[0]
           sl.endDate = this.rangeDatas[1]
@@ -1560,7 +1560,7 @@ export default {
             sl.userId = this.userId
           }
         } else if(this.ins == 11){
-          fName = this.$t('personnelhourstatistics')  + '.xls'
+          fName = this.$t('personnelhourstatistics')  + '.xlsx'
           url += "/exportUserWorkingTimeStatic"
           sl.startDate = this.rangeDatas[0]
           sl.endDate = this.rangeDatas[1]
@@ -1571,33 +1571,33 @@ export default {
             sl.departmentId = this.departmentIdArray[this.departmentIdArray.length - 1]
           }
         }else if(this.ins == 12){
-          fName = this.$t('timestatisticsofaskgroups') + '.xls'
+          fName = this.$t('timestatisticsofaskgroups') + '.xlsx'
           url += "/exportGroupWithProjectTimeCost"
           sl.startDate = this.rangeDatas[0]
           sl.endDate = this.rangeDatas[1]
         }else if(this.ins == 13){
-          fName = this.$t('projectcostbaselinetable') + '.xls'
+          fName = this.$t('projectcostbaselinetable') + '.xlsx'
           url += "/exportProjectBaseCost"
         } else if(this.ins == 14) {
-          fName = this.$t('ren-yuan-yue-du-gong-shi-biao') + '.xls'
+          fName = this.$t('ren-yuan-yue-du-gong-shi-biao') + '.xlsx'
           url += "/exportEmpMonthHours"
           sl.userId= this.userId,
           sl.departmentId = this.departmentIdArray.length > 0 ? this.departmentIdArray[this.departmentIdArray.length - 1] : '',
           sl.month = this.monthPersonnel + '-01',
           sl.whether = this.whether
         } else if(this.ins == 15) {
-          fName = this.$t('bumenchanyuqingkuang') + '.xls'
+          fName = this.$t('bumenchanyuqingkuang') + '.xlsx'
           url += "/exportDeptPartInProjects"
           sl.month = this.monthPersonnel + '-01'
           sl.departmentId = this.departmentIdArray.length > 0 ? this.departmentIdArray[this.departmentIdArray.length - 1] : ''
         } else if(this.ins == 16) {
-          fName = this.$t('ge-fen-zu-jie-duan-gong-shi-biao') + '.xls'
+          fName = this.$t('ge-fen-zu-jie-duan-gong-shi-biao') + '.xlsx'
           url += "/exportProjectGroupAndCategoryWorkTime"
           sl.startDate = this.rangeDatas[0]
           sl.endDate = this.rangeDatas[1]
           sl.projectId = this.proJuctId
         } else if(this.ins == 17) {
-          fName = '子项目工时成本表' + '.xls'
+          fName = '子项目工时成本表' + '.xlsx'
           url += "/exportSubProjectTimeCost"
           sl.startDate = this.rangeDatas[0]
           sl.endDate = this.rangeDatas[1]
@@ -1634,7 +1634,7 @@ export default {
             res => {
                 if (res.code == "ok") {
                     var filePath = res.data;
-                    var fName = this.$t('personnelfillingtimelyratestatistics') + '(' + this.quarterParameter.year + this.$t('di') + this.quarterParameter.quarter  + '季度).xls'
+                    var fName = this.$t('personnelfillingtimelyratestatistics') + '(' + this.quarterParameter.year + this.$t('di') + this.quarterParameter.quarter  + '季度).xlsx'
                     const a = document.createElement('a'); // 创建a标签
                     a.setAttribute('download', fName);// download属性
                     a.setAttribute('href', filePath);// href链接