Browse Source

解决导出排班报错问题

zhongwei
tanghaihao 1 year ago
parent
commit
9b8f9dcc96
  1. 3
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyMainController.java
  2. 27
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/utils/ExcelTool.java

3
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyMainController.java

@ -10,6 +10,7 @@ import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity;
import com.hnac.hzims.operational.duty.entity.ImsDutyMainReportExcel; import com.hnac.hzims.operational.duty.entity.ImsDutyMainReportExcel;
import com.hnac.hzims.operational.duty.service.IImsDutyMainService; import com.hnac.hzims.operational.duty.service.IImsDutyMainService;
import com.hnac.hzims.operational.duty.utils.ExcelMergeHandler; import com.hnac.hzims.operational.duty.utils.ExcelMergeHandler;
import com.hnac.hzims.operational.duty.utils.ExcelTool;
import com.hnac.hzims.operational.duty.vo.ChangeDutyMainVo; import com.hnac.hzims.operational.duty.vo.ChangeDutyMainVo;
import com.hnac.hzims.operational.duty.vo.HomePageDutyMainInfoVo; import com.hnac.hzims.operational.duty.vo.HomePageDutyMainInfoVo;
import com.hnac.hzims.operational.duty.vo.ImsSchedulingVo; import com.hnac.hzims.operational.duty.vo.ImsSchedulingVo;
@ -246,6 +247,8 @@ public class ImsDutyMainController extends BladeController {
int mergeRowIndex = 2; int mergeRowIndex = 2;
// 需要合并的列 // 需要合并的列
int[] mergeColumeIndex = {0}; int[] mergeColumeIndex = {0};
ExcelTool.resetCellMaxTextLength();
// 导出Excel,合并第一列相同内容的单元格 // 导出Excel,合并第一列相同内容的单元格
EasyExcel.write(response.getOutputStream(), ImsDutyMainReportExcel.class) EasyExcel.write(response.getOutputStream(), ImsDutyMainReportExcel.class)
.registerWriteHandler(new ExcelMergeHandler(mergeRowIndex, mergeColumeIndex)).sheet().doWrite(list); .registerWriteHandler(new ExcelMergeHandler(mergeRowIndex, mergeColumeIndex)).sheet().doWrite(list);

27
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/utils/ExcelTool.java

@ -0,0 +1,27 @@
package com.hnac.hzims.operational.duty.utils;
import org.apache.poi.ss.SpreadsheetVersion;
import java.lang.reflect.Field;
/**
* 设置Excel导出的最大字符数
* @author tanghaihao
* @date 2023年08月18日 16:40
*/
public class ExcelTool {
public static void resetCellMaxTextLength() {
SpreadsheetVersion excel2007 = SpreadsheetVersion.EXCEL2007;
if (Integer.MAX_VALUE != excel2007.getMaxTextLength()) {
Field field;
try {
field = excel2007.getClass().getDeclaredField("_maxTextLength");
field.setAccessible(true);
field.set(excel2007, Integer.MAX_VALUE);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Loading…
Cancel
Save