public void CloseExcelControl(ref Excel.Worksheet ws, ref Excel.Workbook wb, ref Excel.Application app, ref List<Process> processes) { if (ws != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(ws); } if (wb != null) { g_Util.DebugPrint("I'm saving Excel File..."); if (wb.ReadOnly == false) { wb.Save(); } wb.Close(); System.Runtime.InteropServices.Marshal.ReleaseComObject(wb); wb = null; } if (app != null) { g_Util.DebugPrint("I'm closing Excel File..."); app.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(app); app = null; } if (processes != null && processes.Count > 0) { g_Util.DebugPrint("I'm killing Excel processes..."); foreach (Process Iter in processes) { if (Iter.ProcessName == "EXCEL") { try { Process.GetProcessById(Iter.Id); Iter.Kill(); } catch { continue; } } } } }
private void CloseAll() { if (g_ExcelTool != null) { g_ExcelTool.CloseExcelControl(ref processes); } if (processes != null) { foreach (Process Iter in processes) { System.Diagnostics.Debug.WriteLine("Kill " + Iter.ProcessName); try { Process.GetProcessById(Iter.Id); Iter.Kill(); } catch { continue; } } } }