1 Microsoft. office. interop. excel. application excelApp = new Microsoft. office. interop. excel. application (); 2 excelApp. visible = true; 3 // get the WorkBook object and open the existing file 4 Microsoft. office. interop. excel. workbook excelBook = excelApp. workbooks. _ Open (@ "e: \ excel.xls"); 5 // specify the Sheet 6 Microsoft. office. interop. excel. worksheet excelSheet = (Microsoft. office. interop. excel. worksheet) excelApp. activeSheet; 7 8 // you can add operations on files 9 10 excelSheet = null; 11 excelBook = null; 12 excelSheet = null; 13 excelBook = null; 14 // This sentence is very important, otherwise the Excel object cannot be interpreted from the memory 15 // if you just open the file and wait for the user to operate the Excel file, you can remove it, allow users to automatically release Excel Object Memory 16 excelBook when they close the file. quit (); 17 excelBook = null;
References: C # Excel operations (1)