我正在尝试使用 Apache POI在.xlsx文件中获取单元格颜色信息。
方法cellStyle.getFillBackgroundColor()返回很短。如何将 short 转换为java.awt.Color或任何其他格式(XSSFColor)。
最终我想根据其背景颜色存储单元格的值。
Workbook workbook = WorkbookFactory.create(new FileInputStream (new File(SAMPLE_XLSX_FILE_PATH)));
Sheet sheet = workbook.getSheetAt(0);
DataFormatter dataFormatter = new DataFormatter();
sheet.forEach(row -> {
row.forEach(cell -> {
String cellValue = dataFormatter.formatCellValue(cell);
CellStyle cellStyle = cell.getCellStyle();
System.out.println(cellStyle.getFillBackgroundColor());
//Color userColor = cellStyle.getFillBackgroundColor(); //ERROR
});
System.out.println();
});
我使用的是 3.6 版,我认为它不支持 getFillBackgroundColorColor()
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.6</version>
</dependency>
陪伴而非守候
相关分类