2016-05-30 570 views
0

我正在使用NPOI使用C#(VS 2013)解析Excel文件。我希望得到一个细胞的backgroundColor和我这样做:使用NPOI的Excel:获取单元格的样式(backgroundcolor)

IEnumerator rows = sheet.GetRowEnumerator(); 

while (rows.MoveNext()) 
{ 
    IRow row = (IRow)rows.Current; 

    foreach (ICell cell in row.Cells) 
    { 
     if (cell.CellStyle.FillBackgroundColor == 64) 
     { 
      ... 
     } 
    } 
} 

问题是,不管细胞(黄,绿,没有颜色在所有),FillBackgroundColor值的backgroundColor的ist总是64.所以看起来,这不是存储颜色的地方。那我该如何得到它?

伊迪丝说:该cell.CellStyle.Index属性不同的所有细胞提前

感谢, 弗兰克

回答

0

的原因是,在Excel中CellStyle.FillBackgroundColor不是小区的填充颜色。要检查它,首先确保它有一个填充(CellStyle.FillPattern),然后检查CellStyle.FillForegroundColorColor属性。 F.E.

if (cell.CellStyle.FillPattern == FillPattern.SolidForeground) 
    byte[] cellBackground = cell.CellStyle.FillForegroundColorColor.RGB; 
相关问题