[C #] Method for ending Excel process

xiaoxiao2021-03-06  24

Transfer from: http://blog.9cbs.net/ac669/archive/2005/01/22/263670.aspx often sees how to end the post of the Excel process, many people give the method to get the system process List, then match "Excel", is Excel's process to kill, I personally think this method is not feasible. If the software uses this method to kill the process of starting, it should be bug (possibly using the user Excel process) Kill). I found online another method to kill the Excel process, as follows: System.Runtime.InteropServices.Marshal.ReleaseComObject (worksheets); System.Runtime.InteropServices.Marshal.ReleaseComObject (worksheet); ... System.Runtime. InteropServices.Marshal.ReleaseComObject (excelApp); worksheets = null;; worksheet = null; ... excelApp = null; range = null; Excel file operation objects used in the examples System.Runtime.InteropServices.Marshal.ReleaseComObject (range) All released.

Then resource recovery! Gc.collect (); The above code is best placed in finally, preventing an exception when an Excel file does not perform! Take a look at the task manager, the Excel process is not there! If a friend has a better way, please contribute it, everyone study together!

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

New Post(0)