gpt4 book ai didi

java - CellStyle 类型中的方法 setFillForegroundColor(short) 不适用于参数 (XSSFColor)

转载 作者:行者123 更新时间:2023-11-30 01:43:48 25 4
gpt4 key购买 nike

我正在尝试让自定义颜色在 Apache POI 中工作,但遇到了一个小问题。到目前为止,我一直在使用 IndexedColors,但作为调色板,它相当单调。因此,使用 RGB 格式进行颜色选择将帮助我使电子表格看起来更好。

我一直在使用this问题的答案,因为它从理论上解决了我的问题。然而,我面临着一个非常愚蠢的问题,我真的不知道如何解决。

我收到的错误是:

The method setFillForegroundColor(short) in the type CellStyle is not applicable for the arguments (XSSFColor)

这实际上不应该发生,因为我已经看到它在许多其他有关 Apache POI 的示例和文档中使用。 IDE (Eclipse) 建议将 setFillForegroundColor 更改为 setFillBackgroundColor,但这样做只会使想法建议反之亦然作为解决方案。我的 IDE 真是个 clown 啊...

我为我的样式创建了一个Map,这可能会以某种方式使一切变得复杂,但我并不真正相信这就是问题所在。或者可以吗?

我能做些什么来解决这个废话?

<小时/>

代码摘录:

private static Map<String, CellStyle> styling(Workbook wb)
{
Map<String, CellStyle> styles = new HashMap<>();
CellStyle style;

Font font1 = wb.createFont();
font1.setBold(true);

style = createBorderedStyle(wb);
style.setAlignment(HorizontalAlignment.RIGHT);
style.setFont(font1);
style.setFillBackgroundColor(new XSSFColor(new java.awt.Color(255, 255, 0), new DefaultIndexedColorMap()));
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
styles.put("column_headers", style);

return styles;
}

一些视觉喜剧

setFillBackgroundColor

setFillForegroundColor

最佳答案

感谢Axel Richter我解决了这个问题。问题是我应该坚持使用 XSSF 库。

private static Map<String, CellStyle> styling(Workbook wb)
{
Map<String, CellStyle> styles = new HashMap<>();
XSSFCellStyle style;

Font font1 = wb.createFont();
font1.setBold(true);
style = (XSSFCellStyle) createBorderedStyle(wb);
style.setAlignment(HorizontalAlignment.RIGHT);
style.setFont(font1);
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128), new DefaultIndexedColorMap()));
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
styles.put("cell_g", style);

return styles;
}

关于java - CellStyle 类型中的方法 setFillForegroundColor(short) 不适用于参数 (XSSFColor),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58952888/

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