public static bool SaveExcelFile(IQuestion question, string filename, string sheetName) { ExcelInterop.Application excelApplication = null; try { /* Ref: https://stackoverflow.com/questions/7916711/get-the-current-workbook-object-in-c-sharp */ excelApplication = (ExcelInterop.Application)Marshal.GetActiveObject("Excel.Application"); excelApplication.Visible = true; excelApplication.DisplayAlerts = false; excelApplication.ScreenUpdating = false; ExcelInterop.Workbook excelWorkbook = excelApplication.ActiveWorkbook; ExcelInterop.Worksheet excelWorksheet = excelWorkbook.Sheets[sheetName]; if (excelWorksheet != null) { excelWorkbook.Close(true, filename); } return true; } catch (Exception) { return false; } finally { QuitApplication(excelApplication); } }
catch
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)