在 Java 中使用 POI 获取 Excel 单元格背景颜色不匹配



我正在将Excel表转换为HTML。我在Java中使用POI来获取xls工作簿中单元格的颜色。问题是颜色不匹配:在Excel中,我的RGB值为242,220和219,但当我使用POI获得它们时,我得到RGB(255,153,204)。

你知道如何得到确切的颜色吗?

  HSSFCellStyle cs = (HSSFCellStyle) style;
    out.format("  /* fill pattern = %d */%n", cs.getFillPattern());
    styleColorback(out, "background-color", cs.getFillForegroundColorColor())
 private void styleColorback(Formatter out, String attr, HSSFColor color) {
   short[] rgb = color.getTriplet();
   out.format("  %s: #%02x%02x%02x; ", attr, rgb[0], rgb[1], rgb[2]);
 }

我认为不可能获得单元格的确切颜色,因为Excel 2003调色板只包含56种颜色。我发现获得准确颜色的独特方法是,当你在Excel的选项中将Excel格式保存为。xls,然后在保存菜单中,我们可以将调色板的颜色更改为所需的颜色。

最新更新