I am using NPOI to parse an Excel-File with C# (VS 2013). I want to get the backgroundcolor of a cell and I am doing this:
IEnumerator rows = sheet.GetRowEnumerator();
while (rows.MoveNext())
{
IRow row = (IRow)rows.Current;
foreach (ICell cell in row.Cells)
{
if (cell.CellStyle.FillBackgroundColor == 64)
{
...
}
}
}
Problem is, that regardless of the background-color of the cell (yellow, green, no color at all), the value of FillBackgroundColor ist always 64. So it seems, that isn't the place, where the color is stored. How do I get it then?
Edith says: The cell.CellStyle.Index property differs for all cells
Thanks in advance, Frank
The reason is, that in Excel the CellStyle.FillBackgroundColor is not the FillColor of the Cell. To check it, first make sure it has a Fill at all (CellStyle.FillPattern) and then check the CellStyle.FillForegroundColorColor property. f.e.
if (cell.CellStyle.FillPattern == FillPattern.SolidForeground)
byte[] cellBackground = cell.CellStyle.FillForegroundColorColor.RGB;