From 310c77a2705b1d27bef549da510a18e319b13483 Mon Sep 17 00:00:00 2001 From: Harryxzy Date: Fri, 11 Oct 2024 15:14:21 +0800 Subject: [PATCH] =?UTF-8?q?excel=E8=AE=BE=E7=BD=AE=E5=88=97=E5=AE=BD=20?= =?UTF-8?q?=E8=B6=85=E8=BF=87255=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/salary/util/excel/ExcelUtilPlus.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/com/engine/salary/util/excel/ExcelUtilPlus.java b/src/com/engine/salary/util/excel/ExcelUtilPlus.java index f301e8c23..9da402ce7 100644 --- a/src/com/engine/salary/util/excel/ExcelUtilPlus.java +++ b/src/com/engine/salary/util/excel/ExcelUtilPlus.java @@ -134,7 +134,7 @@ public class ExcelUtilPlus { rowZeroCell.setCellValue(columnGroupItem.getText().toString()); rowZeroCell.setCellStyle(titleCellStyle); //设置列宽 - sheet.setColumnWidth(i, Math.max(12, columnGroupItem.getText().length() * 4) * 256); + sheet.setColumnWidth(i, Math.min(255, Math.max(12, columnGroupItem.getText().length() * 4)) * 256); patternList.add(columnGroupItem.getPattern()); } @@ -262,7 +262,7 @@ public class ExcelUtilPlus { //遍历设置列宽 List header = rowList.get(0); for (int i = 0; i < header.size(); i++) { - sheet.setColumnWidth(i, Math.max(12, header.get(i).toString().length() * 4) * 256); + sheet.setColumnWidth(i, Math.min(255, Math.max(12, header.get(i).toString().length() * 4)) * 256); } for (int rowIndex = 0; rowIndex < rowList.size(); rowIndex++) { @@ -349,7 +349,7 @@ public class ExcelUtilPlus { //遍历设置列宽 List header = rowList.get(0); for (int i = 0; i < header.size(); i++) { - sheet.setColumnWidth(i, Math.max(12, header.get(i).toString().length() * 4) * 256); + sheet.setColumnWidth(i, Math.min(255, Math.max(12, header.get(i).toString().length() * 4)) * 256); } for (int rowIndex = 0; rowIndex < rowList.size(); rowIndex++) { @@ -454,7 +454,7 @@ public class ExcelUtilPlus { //遍历设置列宽 List header = rowList.get(0); for (int i = 0; i < header.size(); i++) { - sheet.setColumnWidth(i, Math.max(12, header.get(i).toString().length() * 4) * 256); + sheet.setColumnWidth(i, Math.min(255, Math.max(12, header.get(i).toString().length() * 4)) * 256); } for (int rowIndex = 0; rowIndex < rowList.size(); rowIndex++) { @@ -588,7 +588,7 @@ public class ExcelUtilPlus { rowOneCell.setCellValue(columnGroupItem.getText().toString()); rowOneCell.setCellStyle(titleCellStyle); //设置列宽 - sheet.setColumnWidth(startIndex, Math.max(12, columnGroupItem.getText().length() * 4) * 256); + sheet.setColumnWidth(startIndex, Math.min(255, Math.max(12, columnGroupItem.getText().length() * 4)) * 256); startIndex++; patternList.add(columnGroupItem.getPattern()); } else { @@ -610,7 +610,7 @@ public class ExcelUtilPlus { subHeader.setCellValue(childrenItem.getText().toString()); subHeader.setCellStyle(titleCellStyle); //设置列宽 - sheet.setColumnWidth(startIndex + j, Math.max(12, childrenItem.getText().length() * 4) * 256); + sheet.setColumnWidth(startIndex + j, Math.min(255, Math.max(12, childrenItem.getText().length() * 4)) * 256); patternList.add(childrenItem.getPattern()); } @@ -789,7 +789,7 @@ public class ExcelUtilPlus { rowOneCell.setCellValue(columnGroupItem.getText().toString()); rowOneCell.setCellStyle(titleCellStyle); //设置列宽 - sheet.setColumnWidth(startIndex, Math.max(12, columnGroupItem.getText().length() * 4) * 256); + sheet.setColumnWidth(startIndex, Math.min(255, Math.max(12, columnGroupItem.getText().length() * 4)) * 256); startIndex++; } else { List childrenList = columnGroupItem.getChildren(); @@ -810,7 +810,7 @@ public class ExcelUtilPlus { subHeader.setCellValue(childrenItem.getText().toString()); subHeader.setCellStyle(titleCellStyle); //设置列宽 - sheet.setColumnWidth(startIndex + j, Math.max(12, childrenItem.getText().length() * 4) * 256); + sheet.setColumnWidth(startIndex + j, Math.min(255, Math.max(12, childrenItem.getText().length() * 4)) * 256); } startIndex += childrenList.size();