gpt4 book ai didi

java - 如何使用 apache poi 获取单元格的背景颜色?

转载 作者:搜寻专家 更新时间:2023-10-31 20:12:21 26 4
gpt4 key购买 nike

我们如何获得 XSSFCell背景颜色。我尝试使用 XSSFCellStyle 但没有成功。

FileInputStream fis = new FileInputStream(fileName);
XSSFWorkbook book = new XSSFWorkbook(fis);
XSSFSheet sheet = book.getSheetAt(0);
XSSFRow row = sheet.getRow(0);

System.out.println(row.getCell(0).getCellStyle().getFillForegroundColor());

使用这些步骤我无法获得 Short 类型的背景颜色表示。

最佳答案

检查这个 URL:

https://issues.apache.org/bugzilla/show_bug.cgi?id=45492

Cell cell = row.getCell(1);
CellStyle cellStyle = cell.getCellStyle();
System.out.println("color = " + getColorPattern(cellStyle.getFillForegroundColor()));




private short[] getColorPattern(short colorIdx){
short[] triplet = null;
HSSFColor color = palette.getColor(colorIdx);
triplet = color.getTriplet();
System.out.println("color : " + triplet[0] +"," + triplet[1] + "," + triplet[2]);
return triplet;
}

这会返回 RGB 代码,但不是准确的代码。但与 XLS 自定义颜色选择器中的实际颜色代码相比,它或多或少返回了相同的颜色。

关于java - 如何使用 apache poi 获取单元格的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19491231/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com