Jins Peter
Jins Peter

Reputation: 2469

Excel Interop C#: I want to select a range of cells with colored background as ExcelRange

I want to select a range of cells Using Excel Interop C# in which background color is "LightBlue".? How do I do that.

Upvotes: 1

Views: 667

Answers (1)

Minh Bui
Minh Bui

Reputation: 1030

Try

    Microsoft.Office.Interop.Excel._Worksheet worksheet;
    int endColumn = 16384;
    int endRow = 65536;
    var results= new List<Excel.Range>();
    for(var i=0;i<=endColumn;i++)
    {
       for(var j=0;j<=endRow;j++)
       {  
          if(worksheet.Cells[j,i].Interior.Color ==   System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightBlue))
         {
          result.Add(worksheet.Cells[j,i]);
         }
       }
     }

Upvotes: 2

Related Questions