We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to Change a Cell's Color on the Fly


I have the following method that I would like to call to change the Color of the referenced cell. (See bottom of method).

The logic is to use a Case statment to determine which Color to use. I will eventually have up to TEN Colors to pick from.

When I run against the method below, the referenced cells color displays as BLACK not the nice hue of Yellow I wanted for example.

I appreciate any ideas. In short, I want to change the Color on the fly so, to speak.


private void setCertNameStyle(Worksheet s, Workbook b) {

Font font = null;

Color cCertColor = null;


String colorPickerName = String.valueOf(gColorPicker);

//Adding a new Style to the styles collection of the Excel object

Style style = b.createStyle();


switch (gColorPicker) {

case 1: cCertColor = new Color((short)255,(short)204,(short)153); break;

case 2: cCertColor = new Color((short)255,(short)255,(short)153); break;

default: cCertColor = new Color((short)255,(short)204,(short)153); break;


// set selected cell color


// set text to center


// set font

font = style.getFont();




// set the final style for the cell




Kindly try our latest version v2.3.0: http://www.aspose.com/community/files/72/java-components/aspose.cells-for-java/entry243913.aspx, we have tested and your code and it works fine with it.

Well, MS Excel (97-2003) standard color palette has only 56 colors, and
if you
need to apply custom colors for different objects, you need to add
these colors to the MS Excel standard color palette first. It is to
be noted here, if you save the file in MS Excel 2007 format e.g XLSX,
then you don’t need to do that

See the topic for your reference: http://www.aspose.com/documentation/java-components/aspose.cells-for-java/colors-and-palette.html

Thank you.