Public void ExportToExecl () {System. windows. forms. saveFileDialog sfd = new SaveFileDialog (); sfd. defaultExt = "xls"; sfd. filter = "Excel file (*. xls) | *. xls "; if (sfd. showDialog () = DialogResult. OK) {DoExport (this. lvreport, sfd. fileName) ;}# region Kill Special Excel Process [DllImport ("user32.dll", SetLastError = true)] static extern int GetWindowThreadProcessId (IntPtr hWnd, out int lpdwProcessId); Private void DoExport (ListView listView, string strFileName) {int rowNum = listView. items. count; int columnNum = listView. items [0]. subItems. count; int rowIndex = 1; int columnIndex = 0; if (rowNum = 0 | string. isNullOrEmpty (strFileName) {return;} if (rowNum> 0) {Microsoft. office. interop. excel. application xlApp = new Microsoft. office. interop. excel. application (); if (xlApp = null) {Messa GeBox. show ("an excel object cannot be created, maybe excel is not installed in your system"); return;} xlApp. defaultFilePath = ""; xlApp. displayAlerts = true; xlApp. sheetsInNewWorkbook = 1; Microsoft. office. interop. excel. workbook xlBook = xlApp. workbooks. add (true); // import the column name of the ListView to the foreach (ColumnHeader dc in listView. columns) {columnIndex ++; xlApp. cells [rowIndex, columnIndex] = dc. text;} // import the data in ListView to Excel for (int I = 0; I <row Num; I ++) {rowIndex ++; columnIndex = 0; for (int j = 0; j <columnNum; j ++) {columnIndex ++; // note that the purpose of adding "\ t" to the export is to prevent the exported data from being displayed as scientific notation. It can be placed at the beginning and end of each line. XlApp. cells [rowIndex, columnIndex] = Convert. toString (listView. items [I]. subItems [j]. text) + "\ t" ;}// the exception must be noted that strFileName, Excel. xlFileFormat. when xlExcel9795 is saved, an error is returned when your Excel versions are not 95, 97, but 2003 and 2007. The exception is HRESULT: 0x800A03EC. The solution is to replace strFileName with Microsoft. Office. Interop. Excel. XlFileFormat. xlWorkbookNormal. XlBook. saveAs (strFileName, Microsoft. office. interop. excel. xlFileFormat. xlWorkbookNormal, Type. missing, Type. missing, Type. missing, Type. missing, Microsoft. office. interop. excel. xlSaveAsAccessMode. xlExclusive, Type. missing, Type. missing, Type. missing, Type. missing, Type. missing); xlApp = null; xlBook = null; MessageBox. show ("report exported successfully! "); Try {if (xlApp! = Null) {int lpdwPeocessId; GetWindowThreadProcessId (new IntPtr (xlApp. hwnd), out lpdwPeocessId); System. diagnostics. process. getprocpolicyid (lpdwPeocessId ). kill () ;}} catch (System. exception ex) {Console. writeLine ("Delete Excel Process Error:" + ex. message) ;}}# endregion