From 82fc32af0dc0d32c81246ed640f543072f16a4c6 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Thu, 24 Nov 2022 19:27:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86=E5=AF=BC=E5=87=BAEXCEL?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=A0=BCTEXT=E9=95=BF=E5=BA=A6=E5=A4=A7?= =?UTF-8?q?=E4=BA=8EPOI=E9=99=90=E5=88=B6=E7=9A=84=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=A0=BC=E9=95=BF=E5=BA=A6=E6=97=B6=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excel/utils/EasyExcelExporter.java | 20 ++++++++++++++++--- .../io/metersphere/service/IssuesService.java | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/excel/utils/EasyExcelExporter.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/excel/utils/EasyExcelExporter.java index 6a52c6ef59..884bc84646 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/excel/utils/EasyExcelExporter.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/excel/utils/EasyExcelExporter.java @@ -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()); + } + } + } } diff --git a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java index e7c04b528a..44d1cba6dd 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java @@ -1462,6 +1462,7 @@ public class IssuesService { } public void issueExport(IssueExportRequest request, HttpServletResponse response) { + EasyExcelExporter.resetCellMaxTextLength(); Map userMap = baseUserService.getProjectMemberOption(request.getProjectId()).stream().collect(Collectors.toMap(User::getId, User::getName)); // 获取缺陷模板及自定义字段 IssueTemplateDao issueTemplate = getIssueTemplateByProjectId(request.getProjectId());