Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 public static void DisplayAlerts(bool displayAlerts) => PerformOperationWithRecovery.PerformOperation(() => ExcelApplication.DisplayAlerts = displayAlerts);
Esempio n. 4
0
 public static void ScreenUpdating(bool updateScreen) => PerformOperationWithRecovery.PerformOperation(() => ExcelApplication.Visible       = updateScreen);
Esempio n. 5
0
 public static void MakeWorkbookVisible(bool visible) => PerformOperationWithRecovery.PerformOperation(() => ExcelApplication.Visible       = visible);