From 37d0ebc21e8a1c8bdd60bc90ab606e5692fd517f Mon Sep 17 00:00:00 2001 From: "weicw1996@qq.com" Date: Mon, 21 Sep 2026 05:52:31 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E5=AF=BC=E5=85=A5=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E6=98=8E=E7=BB=86=E5=8E=BB=E6=8E=89=E7=A9=BA=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=A0=BC=E5=BA=95=E7=BA=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 标红统一只改红色字体,不再对空单元格加浅红底纹(IndexedColors.ROSE)。 底纹原本是为「必填项为空时红字在屏幕上看不见」而加,但它超出 AGENTS.md §6.11「仅出错字段/列使用红色文字」的口径,视觉上也偏重。 - markRed(Cell, boolean) 简化为 markRed(Cell),删除 redFillStyleCache 与 isBlankValue - 空单元格的红色字体样式照旧写入 styles.xml,api-violation-xlsx-cols.js 按字体色判定,回归用例 03/04 不受影响 - 影响所有使用 ImportFailureExcelUtil 的导入模块(20+ 个) --- .../common/excel/ImportFailureExcelUtil.java | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/blade-common/src/main/java/org/springblade/common/excel/ImportFailureExcelUtil.java b/blade-common/src/main/java/org/springblade/common/excel/ImportFailureExcelUtil.java index e297cb5..6b0ad40 100644 --- a/blade-common/src/main/java/org/springblade/common/excel/ImportFailureExcelUtil.java +++ b/blade-common/src/main/java/org/springblade/common/excel/ImportFailureExcelUtil.java @@ -35,7 +35,6 @@ import cn.idev.excel.write.metadata.holder.WriteTableHolder; import jakarta.servlet.http.HttpServletResponse; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.Workbook; @@ -255,7 +254,6 @@ public class ImportFailureExcelUtil { private final List> rows; private final Map> redColumnsByRow = new HashMap<>(); private final Map redStyleCache = new HashMap<>(); - private final Map redFillStyleCache = new HashMap<>(); private final Map noWrapStyleCache = new HashMap<>(); private final Map columnWidthCache = new HashMap<>(); @@ -292,7 +290,7 @@ public class ImportFailureExcelUtil { return; } if (shouldMarkRed(relativeRowIndex, cell.getColumnIndex())) { - markRed(cell, isBlankValue(rows.get(relativeRowIndex), cell.getColumnIndex())); + markRed(cell); } } @@ -359,24 +357,15 @@ public class ImportFailureExcelUtil { return redColumns != null && redColumns.contains(columnIndex); } - private boolean isBlankValue(List row, int columnIndex) { - if (columnIndex < 0 || columnIndex >= row.size()) { - return true; - } - Object value = row.get(columnIndex); - return value == null || String.valueOf(value).isBlank(); - } - /** * 标红单元格 *

- * 单元格为空时只改字体颜色屏幕上什么也看不到(「必填项为空」正是这种情况), - * 因此对空单元格额外加浅红底纹,保证用户能定位到是哪一列出错。 + * 统一只改字体颜色,不加底纹;空单元格的红色字体在屏幕上不可见, + * 这类错误依靠失败原因列的文字定位。 */ - private void markRed(Cell cell, boolean blankValue) { + private void markRed(Cell cell) { CellStyle currentStyle = cell.getCellStyle(); - Map styleCache = blankValue ? redFillStyleCache : redStyleCache; - CellStyle redStyle = styleCache.computeIfAbsent(currentStyle.getIndex(), styleIndex -> { + CellStyle redStyle = redStyleCache.computeIfAbsent(currentStyle.getIndex(), styleIndex -> { Workbook workbook = cell.getSheet().getWorkbook(); CellStyle newStyle = workbook.createCellStyle(); newStyle.cloneStyleFrom(currentStyle); @@ -384,10 +373,6 @@ public class ImportFailureExcelUtil { font.setColor(IndexedColors.RED.getIndex()); newStyle.setFont(font); newStyle.setWrapText(true); - if (blankValue) { - newStyle.setFillForegroundColor(IndexedColors.ROSE.getIndex()); - newStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); - } return newStyle; }); cell.setCellStyle(redStyle);