Problem with getting Excel cell background colors in C#

前端 未结 2 945
情书的邮戳
情书的邮戳 2020-12-19 08:47

I am trying to get background color of some cells in an Excel sheet in C#. I am using follwoing code for it:

Excel.Range r = (Excel.Range)m_objRange[i, j];           


        
相关标签:
2条回答
  • 2020-12-19 08:58

    try this:

    System.Color col = System.Drawing.ColorTranslator.FromOle((int) r.Interior.Color);
    string htmlCol = System.Drawing.ColorTranslator.ToHtml(col);
    

    (warning, I didn't test this)

    0 讨论(0)
  • 2020-12-19 09:08

    This work for me:

    
    int colorNumber = System.Convert.ToInt32(((Range) worksheet.Cells[rowNumber,columnNumber]).Interior.Color);
    Color color = System.Drawing.ColorTranslator.FromOle(colorNumber);
    

    0 讨论(0)
提交回复
热议问题