fix(测试跟踪): 缺陷管理导出EXCEL单元格TEXT长度大于POI限制的单元格长度时错误

This commit is contained in:
song-cc-rock 2022-11-24 19:27:14 +08:00 committed by 刘瑞斌
parent dd5dd16184
commit 82fc32af0d
2 changed files with 18 additions and 3 deletions

View File

@ -6,12 +6,11 @@ import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.exception.ExcelException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.ss.SpreadsheetVersion;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@ -98,4 +97,19 @@ public class EasyExcelExporter {
MSException.throwException(e.getMessage());
}
}
public static void resetCellMaxTextLength() {
SpreadsheetVersion excel2007 = SpreadsheetVersion.EXCEL2007;
if (excel2007.getMaxTextLength() < Integer.MAX_VALUE) {
Field field;
try {
field = excel2007.getClass().getDeclaredField("_maxTextLength");
field.setAccessible(Boolean.TRUE);
field.set(excel2007, Integer.MAX_VALUE);
}catch (Exception e){
LogUtil.error(e);
MSException.throwException(e.getMessage());
}
}
}
}

View File

@ -1462,6 +1462,7 @@ public class IssuesService {
}
public void issueExport(IssueExportRequest request, HttpServletResponse response) {
EasyExcelExporter.resetCellMaxTextLength();
Map<String, String> userMap = baseUserService.getProjectMemberOption(request.getProjectId()).stream().collect(Collectors.toMap(User::getId, User::getName));
// 获取缺陷模板及自定义字段
IssueTemplateDao issueTemplate = getIssueTemplateByProjectId(request.getProjectId());