⚡ 导入失败明细去掉空单元格底纹
标红统一只改红色字体,不再对空单元格加浅红底纹(IndexedColors.ROSE)。 底纹原本是为「必填项为空时红字在屏幕上看不见」而加,但它超出 AGENTS.md §6.11「仅出错字段/列使用红色文字」的口径,视觉上也偏重。 - markRed(Cell, boolean) 简化为 markRed(Cell),删除 redFillStyleCache 与 isBlankValue - 空单元格的红色字体样式照旧写入 styles.xml,api-violation-xlsx-cols.js 按字体色判定,回归用例 03/04 不受影响 - 影响所有使用 ImportFailureExcelUtil 的导入模块(20+ 个)
This commit is contained in:
+5
-20
@@ -35,7 +35,6 @@ import cn.idev.excel.write.metadata.holder.WriteTableHolder;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
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.Font;
|
||||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
@@ -255,7 +254,6 @@ public class ImportFailureExcelUtil {
|
|||||||
private final List<List<Object>> rows;
|
private final List<List<Object>> rows;
|
||||||
private final Map<Integer, Set<Integer>> redColumnsByRow = new HashMap<>();
|
private final Map<Integer, Set<Integer>> redColumnsByRow = new HashMap<>();
|
||||||
private final Map<Short, CellStyle> redStyleCache = new HashMap<>();
|
private final Map<Short, CellStyle> redStyleCache = new HashMap<>();
|
||||||
private final Map<Short, CellStyle> redFillStyleCache = new HashMap<>();
|
|
||||||
private final Map<Short, CellStyle> noWrapStyleCache = new HashMap<>();
|
private final Map<Short, CellStyle> noWrapStyleCache = new HashMap<>();
|
||||||
private final Map<Integer, Integer> columnWidthCache = new HashMap<>();
|
private final Map<Integer, Integer> columnWidthCache = new HashMap<>();
|
||||||
|
|
||||||
@@ -292,7 +290,7 @@ public class ImportFailureExcelUtil {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (shouldMarkRed(relativeRowIndex, cell.getColumnIndex())) {
|
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);
|
return redColumns != null && redColumns.contains(columnIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBlankValue(List<Object> row, int columnIndex) {
|
|
||||||
if (columnIndex < 0 || columnIndex >= row.size()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Object value = row.get(columnIndex);
|
|
||||||
return value == null || String.valueOf(value).isBlank();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标红单元格
|
* 标红单元格
|
||||||
* <p>
|
* <p>
|
||||||
* 单元格为空时只改字体颜色屏幕上什么也看不到(「必填项为空」正是这种情况),
|
* 统一只改字体颜色,不加底纹;空单元格的红色字体在屏幕上不可见,
|
||||||
* 因此对空单元格额外加浅红底纹,保证用户能定位到是哪一列出错。
|
* 这类错误依靠失败原因列的文字定位。
|
||||||
*/
|
*/
|
||||||
private void markRed(Cell cell, boolean blankValue) {
|
private void markRed(Cell cell) {
|
||||||
CellStyle currentStyle = cell.getCellStyle();
|
CellStyle currentStyle = cell.getCellStyle();
|
||||||
Map<Short, CellStyle> styleCache = blankValue ? redFillStyleCache : redStyleCache;
|
CellStyle redStyle = redStyleCache.computeIfAbsent(currentStyle.getIndex(), styleIndex -> {
|
||||||
CellStyle redStyle = styleCache.computeIfAbsent(currentStyle.getIndex(), styleIndex -> {
|
|
||||||
Workbook workbook = cell.getSheet().getWorkbook();
|
Workbook workbook = cell.getSheet().getWorkbook();
|
||||||
CellStyle newStyle = workbook.createCellStyle();
|
CellStyle newStyle = workbook.createCellStyle();
|
||||||
newStyle.cloneStyleFrom(currentStyle);
|
newStyle.cloneStyleFrom(currentStyle);
|
||||||
@@ -384,10 +373,6 @@ public class ImportFailureExcelUtil {
|
|||||||
font.setColor(IndexedColors.RED.getIndex());
|
font.setColor(IndexedColors.RED.getIndex());
|
||||||
newStyle.setFont(font);
|
newStyle.setFont(font);
|
||||||
newStyle.setWrapText(true);
|
newStyle.setWrapText(true);
|
||||||
if (blankValue) {
|
|
||||||
newStyle.setFillForegroundColor(IndexedColors.ROSE.getIndex());
|
|
||||||
newStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
||||||
}
|
|
||||||
return newStyle;
|
return newStyle;
|
||||||
});
|
});
|
||||||
cell.setCellStyle(redStyle);
|
cell.setCellStyle(redStyle);
|
||||||
|
|||||||
Reference in New Issue
Block a user