CellStyle类型的setFillForegroundColor(short)方法不适用于参数(XSSFColor) [英] The method setFillForegroundColor(short) in the type CellStyle is not applicable for the arguments (XSSFColor)

查看:626
本文介绍了CellStyle类型的setFillForegroundColor(short)方法不适用于参数(XSSFColor)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to get custom colours to work in Apache POI but I got into a small problem. So far I have been using IndexedColors, but as a palette, it is pretty drab. Thus using an RGB format for colour selection would help me to make my spreadsheets look much better.

我一直在使用问题的答案,因为它可以解决我的问题从理论上讲.但是,我面临着一个非常愚蠢的问题,我真的不知道如何解决.

I have been using this question's answer, as it solves my problem theoretically. However, I am facing a very silly problem that I do not really know how to solve.

我收到的错误是:

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

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

这不应该真的发生,因为我已经在许多其他有关Apache POI的示例和文档中使用了它.IDE(Eclipse)建议将 setFillForegroundColor 更改为 setFillBackgroundColor ,但是这样做只能使建议反之亦然.我的IDE可以成为一个小丑!

This should not really be happening, as I have seen it being used in many other examples and documentation about Apache POI. The IDE (Eclipse) suggests changing setFillForegroundColor to setFillBackgroundColor but doing this, only makes the idea suggest the vice versa as a solution. What a joker can my IDE be...

我已经为我的样式创建了一个 Map ,这可能使所有内容难以理解,但是我并不真正相信这是问题所在.还是可以?

I have created a Map for my styles and that could be somehow convoluting everything but I do not really believe that this is the issue. Or could it?

我该怎么做才能解决这个废话?

What can I do to solve this nonsense?

代码摘录:

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库.

Thanks to Axel Richter I solved the issue. The problem is that I should have sticked to the XSSF libraries.

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; 
}

这篇关于CellStyle类型的setFillForegroundColor(short)方法不适用于参数(XSSFColor)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆