1

嗨,我想将几​​个按钮的颜色导出到 excel 中,这些按钮代表一个网格并且是动态创建的。

导出到 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); 
     }
}
4

2 回答 2

4

您应该使用以下代码:

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();
     }
}
于 2013-03-20T21:32:47.907 回答
0

您可以尝试分配背景颜色吗?= 颜色.红色

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

我的意思是,如果您要获得颜色的名称,请将其分配给背面颜色。不是一个好的解决方案,但将其视为一种解决方法

于 2013-03-20T21:28:43.113 回答