Мои столбцы datagridview сравнивают некоторые данные и соответствуют разным цветам по красному или одинаковым данным по зеленому цвету. У меня проблема. Я хочу экспортировать datagridview в файл excel, но созданный файл excel содержит только текст. Я хочу показать, что excel сообщает то же, что и в datagridview, - с соответствующими данными по зеленому или красному. Вот мой кодЭкспорт Datagridview в файл Excel С измененными ячейками цвета
// comparing data in datagridview
public void Compare()
{
try
{
int rowCount = DataGridView.RowCount;
int colCount = DataGridView.ColumnCount;
string col1,
col2;
int c = 1;
for (int k = 0; k < rowCount - 1; k++)
{
for (int i = 0; i < colCount; i++, c++)
{
col1= Convert.ToString(DataGridView.Rows[k].Cells[0].Value);
col2= Convert.ToString(DataGridView.Rows[k].Cells[1].Value);
for (int j = 0; j < rowCount - 1; j++)
{
string col3= Convert.ToString(DataGridView.Rows[k].Cells[2].Value);
string col4= Convert.ToString(DataGridView.Rows[k].Cells[3].Value);
// comparing data in col1 and col3
if (col1 == col3 && (col1 != "" && col3 != ""))
{
DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
CellStyle.BackColor = Color.LightGreen;
DataGridView.Rows[k].Cells[0].Style = CellStyle;
DataGridView.Rows[k].Cells[2].Style = CellStyle;
}
else
{
DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
CellStyle.BackColor = Color.Red;
DataGridView.Rows[k].Cells[0].Style = CellStyle;
DataGridView.Rows[k].Cells[2].Style = CellStyle;
}
// comparing data in col2 and col4
if (col2 == col4 && (col2 != "" && col4 != ""))
{
DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
CellStyle.BackColor = Color.LightGreen;
DataGridView.Rows[k].Cells[1].Style = CellStyle;
DataGridView.Rows[k].Cells[3].Style = CellStyle;
}
else
{
DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
CellStyle.BackColor = Color.Red;
DataGridView.Rows[k].Cells[1].Style = CellStyle;
DataGridView.Rows[k].Cells[3].Style = CellStyle;
}
}
}
}
DataGridView.ClearSelection();
}
catch (Exception)
{
}
}
Как экспортировать это модифицированное datagridview в excel. Заранее спасибо за помощь