Hi,
Thanks for your posting and using Aspose.Cells.
In order to get fill color of the cell, you must use foreground color of the cell not the background color of the cell. Please see the following sample code, its
source excel file and its console output for your reference. I have tested the code with the latest version:
Aspose.Cells for Java v16.10.6.
Please also read the comments inside the code for more help.
Java
Workbook wb = new Workbook(dirPath + “sample.xlsx”);
Worksheet ws = wb.getWorksheets().get(0);
Cell a1 = ws.getCells().get(“A1”);
Style st = null;
//Normally, GetStyle() is used but it does not work with conditional formatting
//st = a1.GetStyle();
//This also works with <span style=“font-family: “Courier New”; font-size: small;”>conditional formatting
st = a1.getDisplayStyle();
if(st.getPattern() == BackgroundType.SOLID)
{
//You must access cell fill color via foreground color property and not via background color property
Color clr = st.getForegroundColor();
System.out.println(clr);
}
C#
Workbook wb = new Workbook(“sample.xlsx”);
Worksheet ws = wb.Worksheets[0];
Cell a1 = ws.Cells[“A1”];
Style st = null;
//Normally, GetStyle() is used but it does not work for conditional formatting
//st = a1.GetStyle();
//This also works with conditional formatting
st = a1.GetDisplayStyle();
if(st.Pattern == BackgroundType.Solid)
{
//You must access cell fill color via foreground color property and not via background color property
Color clr = st.ForegroundColor;
Console.WriteLine(clr);
}
Console Output - Java
com.aspose.cells.Color@ffff00
Console Output - C#
Color [A=0, R=255, G=255, B=0]