Apply POI Custom color using 'Hexadecimal Color Codes' provided

怎甘沉沦 提交于 2019-12-12 15:12:46

问题


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

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

Like : for HSSF: font.setColor()/font.setColor(getShortIndexFromHexColorCodes()) for XSSF: cs.setFillForegroundColor();

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:)


回答1:


When it comes to code examples, try here.

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.

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



来源:https://stackoverflow.com/questions/11188840/apply-poi-custom-color-using-hexadecimal-color-codes-provided

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!