c# - Listview not exporting columns to excel -


i'm trying export listview excel file. information in listview exported successfully, columns not. here code:

stringbuilder sb = new stringbuilder(); 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 = 1; int i2 = 1; int x = 1; int x2 = 1; foreach (columnheader ch in listview1.columns) {     ws.cells[x2, x] = ch.text;     x++; }  foreach (listviewitem lvi in listview1.items) {     = 1;     foreach (listviewitem.listviewsubitem lvs in lvi.subitems)     {         ws.cells[i2, i] = lvs.text;         ws.cells.select();         ws.cells.entirecolumn.autofit();         i++;     }     i2++; } 

can try setting i2 = 2 instead of i2 = 1? may be, 2nd part overwriting columnheader because of i2 = 1.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -