locked
Changing Cell color of excel sheet programatically ?? RRS feed

  • Question

  • User-1511216082 posted

    hi,

    i want to change the cell color of the excel sheet according to the values we are getting from dataTable in C#....so my code goes here.....

    Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1];

    ws.Name = conntype;

    wb.Worksheets.Add(
    Type.Missing, Type.Missing, Type.Missing, Type.Missing);

    int startRow = 1;

    for (i = 0; i < dtMain.Rows.Count; i++)

    {

    for (j = 0; j < dtMain.Columns.Count; j++)

    {

    string comp1=dtMain.Rows[i][j].ToString();if(comp1> 30 && comp1<40) // i have to change color of the values between 30 and 40 to yellow ......

    ws.Cells.

    ws.Cells[startRow, j + 1] = dtMain.Rows[i][j].ToString();

    }

    startRow++;

    }

    how can i change the color...?

    thanks,

    rajiv

    Monday, August 25, 2008 1:32 AM

Answers

  • User-1203469223 posted

    ((Range)(wb.Cells[totaalRij + i, row])).Interior.Color = color;
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 25, 2008 5:08 AM

All replies

  • User-1203469223 posted

    ((Range)(wb.Cells[totaalRij + i, row])).Interior.Color = color;
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 25, 2008 5:08 AM
  • User2024808565 posted
    oXL = new Excel.Application();

    oXL.Visible = false;

    //Get a new workbook.

    oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));

    oSheet = (Excel._Worksheet)oWB.ActiveSheet;

    oRng = oSheet.get_Range("A1", "BZ1");

    oRng.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Silver);

    Friday, December 5, 2008 3:59 AM