Reputation: 367
I am using the following method to export my ListView to Excel:
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
app.Visible = true;
Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Add(1);
Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1];
int i = 1;
int i2 = 1;
foreach (ListViewItem lvi in listView1.Items)
{
i = 1;
foreach (ListViewItem.ListViewSubItem lvs in lvi.SubItems)
{
ws.Cells[i2, i] = lvs.Text;
i++;
}
i2++;
}
In my ListView i have set background colors for each cell, i want these colors to export over to Excel as well. The method above works perfectly but does not include the color in the export.
Any ideas? :)
Upvotes: 0
Views: 1321
Reputation: 383
Try these posts it will help you: Export to Excel with Grid Color in Winforms using C#
Retain cell background colour when exporting GridView to Excel
Upvotes: 1