Below is my code where i am trying to loop all the rows and columns in datagridview.
the problem is i need to apply color for the text in excel sheet after export that is after exporting i need to see the blue color for particular cell how can i do this can anyone help me out.
public void ExportToExcel(DataGridView gridviewID, string excelFilename)
{
Microsoft.Office.Interop.Excel.Application objexcelapp = new Microsoft.Office.Interop.Excel.Application();
objexcelapp.Application.Workbooks.Add(Type.Missing);
objexcelapp.Columns.ColumnWidth = 25;
for (int i = 1; i < gridviewID.Columns.Count + 1; i++)
{
objexcelapp.Cells[1, i] = gridviewID.Columns[i - 1].HeaderText;
}
/*For storing Each row and column value to excel sheet*/
for (int i = 0; i < gridviewID.Rows.Count; i++)
{
for (int j = 0; j < gridviewID.Columns.Count; j++)
{
if (gridviewID.Rows[i].Cells[j].Value != null)
{
objexcelapp.Cells[i + 2, j + 1] = gridviewID.Rows[i].Cells[j].Value.ToString();
}
}
progressBar1.PerformStep();
label3.Text = i + "/" + Convert.ToInt32(gridviewID.Rows.Count);
}
objexcelapp.ActiveWorkbook.SaveCopyAs("\\Desktop\\" + FileName + ".xlsx");
MessageBox.Show("Your excel file exported successfully at FileName + ".xlsx");
objexcelapp.ActiveWorkbook.Saved = true;
progressBar1.Visible = false;
label3.Visible = false;
}