Hi,
How do I get the color or fill color of a cell in a spreadsheet? I tried accessing it via the following:
s.ForegroundColor
s.ForegroundArgbColor
The values works well with most cases except when the cell has no fill or color. I'm getting the value 000000 or black which is not correct.
Thanks.
Hi,
Thank you for sharing the sample spreadsheet.
I have evaluated the presented scenario while using the latest version of Aspose.Cells for .NET 8.9.0.4 (attached) and the following piece of code. The results I have received are correct as per the input spreadsheet (please check attached snapshot). Please note, the cell A1 has the cell shading as Black, B1 has none & C1 has White the returned values in ARGB are {0, 0, 0, 0}, Null & {0, 255, 255, 255} respectively.
C#
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>var book = <span class=“kwrd” style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>new<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> Workbook(dir + “cellColor.xls”);
var sheet = book.Worksheets[0];
var cells = sheet.Cells;
var style = cells[“A1”].GetStyle();
Console.WriteLine(“Cell A1: Fill Color (Foreground):” + style.ForegroundColor + " Fill Pattern:" + style.Pattern);
style = cells[“B1”].GetStyle();
Console.WriteLine(“Cell B1: Fill Color (Foreground):” + style.ForegroundColor + " Fill Pattern:" + style.Pattern);
style = cells[“C1”].GetStyle();
Console.WriteLine(“Cell C1: Fill Color (Foreground):” + style.ForegroundColor + " Fill Pattern:" + style.Pattern);
Thanks, I’ll try this out.