Wednesday, April 18, 2012

Set Background color of Excel cell using C#

Here's how to set MS Excel cell or cells background color using C#.
chartRange = sheet.Cells[1, i + 1];  
 chartRange.Interior.Color = Color.LightBlue;
or using get_Range() function and ColorTranslator.ToOle() to set the background color.
Excel.Range chartRange;
chartRange = xlWorkSheet.get_Range("b1", "b3");
chartRange.Interior.Color = ColorTranslator.ToOle(Color.Red);
Where chartRange is a RangeObject.

5 comments:

  1. Gud Job.. it z working . Thank u

    ReplyDelete
  2. try this...

    Excel.Range formatRange;
    formatRange = xlWorkSheet.get_Range("b1", "b1");
    formatRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);

    More info....Excel Cell Formatting

    Ling



    ReplyDelete