使用 Interop.Excel 時就算相關資源都已釋放,但除非 winform 關閉否則還是會殘留一個process
這裡有一篇文章教你強制關閉process
以下為釋放資源範例
for (int i = 1; i <= sheets.Count; i++) Marshal.FinalReleaseComObject(sheets[i]);
Marshal.FinalReleaseComObject(sheets);
Marshal.FinalReleaseComObject(xlsbook);
xlsbooks.Close();
Marshal.FinalReleaseComObject(xlsbooks);
xlsapp.Quit();
Marshal.FinalReleaseComObject(xlsapp);
GC.Collect();