The following is an example of a complete shutdown Excel process

zhaozj2021-02-16  171

I just used it, no problem. Excel.Application myExcel; Excel._Workbook myWB; Excel._Worksheet myWS = null; Excel.Range myRrange = null; try {myExcel = new Excel.ApplicationClass (); myWB = (Excel._Workbook) myExcel.Workbooks.Open (file. Fullname, Type.Missing, Type.Missing, Type.missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing Catch (Exception E) {e.tostring ();} int sheetnum = mywb.worksheets.count; if (SheetNum> 0) {for (int i = 1; i <= sheetnum; i ) {mYws = (Excel) ._Worksheet) MYWB.WORKSHEETS [I];

Int rownum = myws.used management; if (rownum> = 2) {for (int J = 2; j <= rower; j ) {myRrange = myws.get_range ("a" j.toString ), "E" j. Tostring ()); array myvalues ​​= (array) MyRrange.cells.Value;}}}

// The following content can not be less! ! myWB.Close (false, Type.Missing, Type.Missing); myExcel.Workbooks.Close (); myExcel.Quit (); System.Runtime.InteropServices.Marshal.ReleaseComObject (myRrange); System.Runtime.InteropServices.Marshal. ReleaseComObject (myExcel); System.Runtime.InteropServices.Marshal.ReleaseComObject (myWS); System.Runtime.InteropServices.Marshal.ReleaseComObject (myWB); myWS = null; myWB = null; myExcel = null; GC.Collect ();

转载请注明原文地址:https://www.9cbs.com/read-8933.html

New Post(0)