I am trying to get cell color info in .xlsx file using Apache POI.
Method cellStyle.getFillBackgroundColor() is returning short. How can I convert short to java.awt.Color or any other format(XSSFColor).
Ultimately I want to store the value of cell based on its background color.
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();
});
I am using version 3.6 which I think do not support getFillBackgroundColorColor()
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.6</version>
</dependency>