【发布时间】:2018-09-10 18:49:07
【问题描述】:
我正在尝试使用 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();
});
我正在使用我认为不支持 getFillBackgroundColorColor() 的 3.6 版
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.6</version>
</dependency>
【问题讨论】:
-
您为什么使用 3.6 版?该版本于 2009 年发布。
-
生产中的旧版应用程序。在我更改任何 jar 的版本之前需要进行大量测试。
标签: java excel apache apache-poi xlsx