简体   繁体   中英

Export ListView to Excel (Cell colors)?

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? :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM