应用使用“十六进制颜色codeS'提供POI自定义颜色 [英] Apply POI Custom color using 'Hexadecimal Color Codes' provided

查看:961
本文介绍了应用使用“十六进制颜色codeS'提供POI自定义颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用HSSFColor / HSSFPalette和XSSFColor设置现有/自定义颜色。实现如下:
为例如
font.setColor(HSSFColor.WHITE.index);为HSSF
要么
cs.setFillForegroundColor(xssfColor);对于XSSF

I am currently using HSSFColor/HSSFPalette and XSSFColor to set the Existing/Custom Colors. Implementation is as follows : for e.g. font.setColor(HSSFColor.WHITE.index); for HSSF or cs.setFillForegroundColor(xssfColor); for XSSF

我想通过在上述两种情况下的十六进制颜色codeS的参数。

I want to pass parameters in both the above cases for "Hexadecimal Color Codes".

我爱:的HSSF:font.setColor()/ font.setColor(getShortIndexFromHexColor codeS())
 为XSSF:cs.setFillForegroundColor();

有没有办法做出来的上述事情,在那里我可以通过十六进制颜色code和颜色HSSF XSSF和应用。

Is there any way out to do the above thing, where I can pass Hexadecimal Color Code and the colors are applied in HSSF and XSSF.

请指引我感谢提前:)

Please guide me and thanks in advance:)

推荐答案

当涉及到code例子的试试这里

When it comes to code examples, try here.

现在有轻微的解释。在的情况下, font.setColor(短)参数是一个索引标准调色板中的位置。通过与 HSSFPalette 工作,你可以可以调用 setColorAtIndex 这需要四个参数。首先是默认的线程现有的指数点(即现有的颜色,你将替换)。其他三个分别是红,绿,蓝值你想要的颜色。因此,在您的自定义创建默认调色板替换当场将允许您使用自己的十六进制值。这是HSSF情况。

Now a slight explanation. In the case of font.setColor(short) the parameter is an index to a spot in the standard palette. By working with HSSFPalette, you can can call setColorAtIndex which takes four parameters. The first is an existing index spot in the default thread (meaning the existing color you will replace). The other three are red, green and blue values respectively for the color you want. Therefore, replacing a spot in the default palette with your custom creating will allow you to use your own hexadecimal values. This is the HSSF case.

该XSSF情况真的是微不足道,下面是一个例子 setFillForegroundColor(新XSSFColor(新java.awt.Color中(128,0,128)))你不'吨有使你在HSSF做出同样的牺牲。刚刚创建的颜色对象,对R您所需的十六进制值,G和B

The XSSF case really is trivial and here is an example setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128))) You don't have to make the same sacrifice that you have to make in HSSF. Just create that Color object with your required hex values for R, G and B

这篇关于应用使用“十六进制颜色codeS'提供POI自定义颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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