我阅读了所有关于 so 的问题,但没有答案有效。如果我更改 Excel 中的单元格颜色,我仍然会得到 0 和 64。我使用的是 excel 2007 和 poi 3.11。感谢您的帮助。
try{ File file = new File("C:\\Test\\poi.xlsx");
FileInputStream fis = new FileInputStream(file);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sh = wb.getSheet("Tabelle1");
XSSFCellStyle cs = sh.getRow(0).getCell(0).getCellStyle();
System.out.println("Color: "+cs.getFillForegroundColor()); // 0
System.out.println("Color: "+cs.getFillBackgroundColor()); // 64
}catch(Exception e){e.printStackTrace();}
最佳答案
cs.getFillForegroundColorColor().getARGBHex()
这将返回十六进制的 ARGB
更新
要检查颜色,您可以执行以下操作:
Color color = cs.getFillForegroundColorColor();
if (color.GREY_25_PERCENT || color.GREY_40_PERCENT || color.GREY_50_PERCENT || color.GREY_80_PERCENT)
// is grey
}
或者如果只使用 2 种颜色:
Color color = cs.getFillForegroundColorColor();
if (color.WHITE) {
// is white
}else {
// is grey
}
关于java - 使用poi获取Excel中的单元格颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27621527/