Ver Fonte

导出Excel优化

ZHGYL_GKPT há 4 anos atrás
pai
commit
679678dba2
1 ficheiros alterados com 8 adições e 6 exclusões
  1. 8 6
      src/main/java/com/minpay/common/util/ExportUtils.java

+ 8 - 6
src/main/java/com/minpay/common/util/ExportUtils.java

@@ -163,20 +163,21 @@ public class ExportUtils {
             if(!"".equals(title)){//标题行
                 row = sheet.createRow((int) rowIndex);// 行数从0开始
                 row.setHeightInPoints(30);//设置行的高度
-                XSSFCell celldesc = row.createCell(0);
+                cell = row.createCell(0);
+                cell.setCellValue(StringUtil.ObjectToString(title));
+                cell.setCellStyle(descCellStyle);
                 sheet.addMergedRegion(new CellRangeAddress(0,0,0,titleArray.length - 1));//合并单元格
-                celldesc.setCellValue(StringUtil.ObjectToString(title));
-                celldesc.setCellStyle(descCellStyle);
+
                 rowIndex ++;
             }
             if(!"".equals(descStr)){//描述行
                 //添加描述行
                 row = sheet.createRow((int) rowIndex);// 行数从0开始
                 row.setHeightInPoints(30);//设置行的高度
-                XSSFCell celldesc = row.createCell(0);
+                cell = row.createCell(0);
+                cell.setCellValue(StringUtil.ObjectToString(descStr));
+                cell.setCellStyle(descCellStyle);
                 sheet.addMergedRegion(new CellRangeAddress(0,0,0,titleArray.length - 1));//合并单元格
-                celldesc.setCellValue(StringUtil.ObjectToString(descStr));
-                celldesc.setCellStyle(descCellStyle);
                 rowIndex++;
             }
             int manyTitle = 1;// 表头默认一行
@@ -204,6 +205,7 @@ public class ExportUtils {
                 }
             }
             rowLock = rowIndex;
+            //固定标题列
             sheet.createFreezePane(0, rowLock, 0, 0);
             int rowLength		= 0;	//导出excel的总行数
             if(ii < favg){