1

Hi i want to export the color of a few buttons into excel the buttons represent a grid and are created dynamically.

The code I have seem to give me the name of the color and not the actual color of the cells when exported to Excel.

for (int i = 0; i < row; i++)
{   
     for (int j = 0; j < col; j++)
     {
          worksheet.Cells[i + 2, j + 1] = (buttons[i][j].BackColor); 
     }
}
Omar
  • 16,329
  • 10
  • 48
  • 66
Tacit
  • 890
  • 6
  • 17
  • 42

2 Answers2

4

You should use following code:

for (int i = 0; i < row; i++)
{   
     for (int j = 0; j < col; j++)
     {
        Range range = worksheet.Cells[i + 2, j + 1];
        range.Interior.Color = buttons[i][j].BackColor.ToArgb();
     }
}
kmatyaszek
  • 19,016
  • 9
  • 60
  • 65
0

Can you try assigning the back color? = Color.Red

DataGridView1.Rows(4).DefaultCellStyle.BackColor = Color.Red

What i mean is if you are getting the name of the color assign it to the back color. not a good solution but consider it as a workaround

Jhigs
  • 147
  • 4