Many people often see posts on how to end the Excel process in forums.
The method is to first obtain the system process list, and then match "Excel", which is Excel
The process is killed, I personally think this method is not feasible, if the software uses this method
Killing processes started by yourself is a Bug (it is possible to kill the Excel process ).
I found another way to kill the Excel process on the Internet, as shown below:
System. Runtime. InteropServices. Marshal. ReleaseComObject (worksheets );
System. Runtime. InteropServices. Marshal. ReleaseComObject (worksheet );
...
System. Runtime. InteropServices. Marshal. ReleaseComObject (excelApp );
System. Runtime. InteropServices. Marshal. ReleaseComObject (range );
Worksheets = null;
Worksheet = null;
...
ExcelApp = null;
Range = null;
Release all the object instances used to operate Excel files.
Then the resources are recycled!
GC. Collect ();
The above code is best placed in finally to prevent the Excel file from being executed due to exceptions!
Open the task manager and check if the excel process is no longer there!
If any of you have a better method, please contribute and learn together!