public static IWorkbook OpenWorkbookWithRetry(string path, bool closeThenReopen = false, bool readOnly = true) { var workbook = GetAlreadyOpenedWorkbook(path); if (workbook != null && !closeThenReopen) { return(workbook); } PerformOperationWithRecovery.PerformOperation(() => { workbook?.Close(); try { var xlWorkbook = ExcelApplication.Workbooks.Open(path, readOnly); workbook = new WorkbookProxy(xlWorkbook); } catch (Exception) { throw new ApplicationException($"Failed to open workbook=\"{path}\""); } }); return(workbook); }
public static Workbook GetWorkbook(string workbookName, string path) { Workbook workbook = null; PerformOperationWithRecovery.PerformOperation(() => { ExcelApplication.Workbooks.Open(path, ReadOnly: true); try { workbook = ExcelApplication.Workbooks.Open(path, ReadOnly: true); } catch (Exception) { throw new ApplicationException($"Failed to open workbook={workbookName} path=\"{path}\""); } }); return(workbook); }
public static void DisplayAlerts(bool displayAlerts) => PerformOperationWithRecovery.PerformOperation(() => ExcelApplication.DisplayAlerts = displayAlerts);
public static void ScreenUpdating(bool updateScreen) => PerformOperationWithRecovery.PerformOperation(() => ExcelApplication.Visible = updateScreen);
public static void MakeWorkbookVisible(bool visible) => PerformOperationWithRecovery.PerformOperation(() => ExcelApplication.Visible = visible);