示例#1
0
        private void InternalDispose()
        {
            lock (syncObj)
            {
                if (!isDisposed)
                {
                    templateManager?.Dispose();
                    //  RequestsManager?.Dispose();
                    contextualMenuManager?.Dispose();

                    managedWorkbooks.Clear();

                    if (excelApplication != null)
                    {
                        if (excelApplication.Application != null)
                        {
                            excelApplication.Application.WorkbookBeforeClose -= OnWorkbookBeforeClose;
                            excelApplication.Application.WorkbookOpen        -= Instance.AddManagedWorkbook;
                        }
                        excelApplication.Dispose();
                    }

                    isDisposed = true;
                    Instance   = null;
                }
            }
        }
示例#2
0
        /// <summary>Init the framework. Must be called before any other uses of the framework</summary>
        /// <param name="application">A reference to the current Excel application instance</param>
        public static void Init(ExcelInterop.Application application)
        {
            try
            {
                if (application == null)
                {
                    throw new ArgumentException("the 'application' parameter is mandatory");
                }

                lock (syncObj)
                {
                    if (Instance == null)
                    {
                        // Inject the Excel application reference
                        CompositionManager.Instance.ComposeExportedValue(application);

                        Instance = new ETKExcel();
                        // Compose the current instance
                        CompositionManager.Instance.ComposeParts(Instance);

                        Instance.AddManagedWorkbook(application.ActiveWorkbook);

                        application.WorkbookOpen        += Instance.AddManagedWorkbook;
                        application.WorkbookBeforeClose += Instance.OnWorkbookBeforeClose;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new EtkException($"'ETKExcel' initialization failed:{ex.Message}", ex);
            }
        }