poi 4.1 不存在CellType.PICTURE
时间: 2023-07-29 14:12:21 浏览: 130
非常抱歉,我的回答又有误了。在POI 4.1版本中,CellType.PICTURE已经被废弃。正确的做法是使用CellType枚举类中的FORMULA和BLANK枚举值,以及判断单元格是否含有图片的方式来判断单元格是否是图片类型。以下是一个示例代码:
```
XSSFCell cell = row.getCell(columnIndex);
if (cell.getCellType() == CellType.BLANK || (cell.getCellType() == CellType.FORMULA && cell.getCachedFormulaResultTypeEnum() == CellType.ERROR)) {
// 空白单元格或者公式计算结果为错误类型的单元格
} else if (cell.getCellStyle().getFillForegroundColorColor() instanceof XSSFColor) {
XSSFColor color = (XSSFColor) cell.getCellStyle().getFillForegroundColorColor();
if (color.getCTColor().getPatternType() == STPatternType.Enum.forString("solid")) {
// 填充类型为纯色填充
byte[] rgb = color.getRGB();
if (rgb != null && rgb.length == 3 && rgb[0] == rgb[1] && rgb[1] == rgb[2]) {
// 颜色为灰度颜色
if (cell.getPictureData() != null) {
// 单元格含有图片
}
}
}
}
```
需要注意的是,这种判断方式只适用于使用POI库读取Excel文件时,单元格类型为CELL_TYPE_BLANK、CELL_TYPE_FORMULA等的情况。如果直接判断单元格的值是否为图片,可能会出现误判的情况。