poi 校验单元格数据 不满足 上色加批注, 没报错的地方也会上色.

图片说明

如果不满足正则 上色 加批注 这俩都是在一个方法里 错误的地点都有批注,
但是debug看 别的单元格没出错也没进入到方法里 但是上色了...

下面我这个设置背景色方法出问题了么 大佬们...


   //设置单元格颜色
    private static void setUp(Cell cell, int row, int column, XSSFSheet sheetAt) {

        Drawing draw = sheetAt.createDrawingPatriarch();

        if (column == 12) {
            Comment comment = draw.createCellComment(new XSSFClientAnchor(255, 125, 1023, 150, row + 1, column - 1, row + 2, column + 4));

            comment.setString(new XSSFRichTextString("字数不可超过255"));//设置批注内容

            cell.setCellComment(comment);
        } else {
            Comment comment = draw.createCellComment(new XSSFClientAnchor(255, 125, 1023, 150, row + 1, column - 1, row + 2, column + 4));

            comment.setString(new XSSFRichTextString("单元格内容支持小数或整数"));//设置批注内容

            cell.setCellComment(comment);
        }

        CellStyle cellStyle = cell.getCellStyle();

        cellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());

        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

        cell.setCellStyle(cellStyle);
    }

CellStyle cellStyle = cell.getCellStyle();这是获取的 cellStyle 后面设置了颜色和填充方式。
而后面 if 和 else 分支都使用该 Style 重新设置了 cell ,所以无论是那一列都设置了当前单元格前景色为黄色。
需要检查下你的业务逻辑,这里看来是 对所有的列都重新设置了 cell style 只是 12 列和其他列的 comment 内容不一样。