//Application対象
Excel.Application excelApp = null;
//Workbooks対象
Excel.Workbooks excelBooks = null;
//Workbook対象
Excel.Workbook excelBook = null;
//Excel入力
Excel.Worksheet excelSheet = null;
//閉鎖します
excelApp.DisplayAlerts = false;
excelApp.AlertBeforeOverwriting = false;
//清空excelSheet対象
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelSheet);
excelSheet = null;
//清空excelBook対象
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelBook);
excelBook = null;
//清空excelApp対象
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
excelApp = null;
excelBooks.Close();
//清空excelBooks対象
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelBooks);
excelBooks = null;
//清空ごみ箱
GC.Collect();
转载于:https://www.cnblogs.com/jackywork/articles/1102679.html