public static void CloseWorkingWorkbook(Excel.Workbook workbook) { if (workbook != null) { if (!workbook.Saved) { workbook.Save(); } workbook.Close(); ExcelUtilies.ReleaseComObject(workbook); } }
public static void SaveTempWorkbook(Excel.Workbook tempWorkbook) { if (tempWorkbook != null) { //string folder = System.Reflection.Assembly.GetExecutingAssembly().CodeBase.Remove(System.Reflection.Assembly.GetExecutingAssembly().CodeBase.LastIndexOf("/")); //folder = folder.Replace(@"file:///", ""); //if (!Directory.Exists(folder + "/temp")) // Directory.CreateDirectory(folder + "/temp"); //tempWorkbook.SaveAs(folder + "/temp/book1.xls"); tempWorkbook.SaveAs("book1.xls"); string fullname = tempWorkbook.FullName; tempWorkbook.Close(); if (File.Exists(fullname)) { File.Delete(fullname); } ExcelUtilies.ReleaseComObject(tempWorkbook); } }