Esempio n. 1
0
        public void Run()
        {
            // start application
            Excel.Application application = new Excel.Application();
            application.DisplayAlerts = false;

            // create new Workbook & attach close event trigger
            Excel.Workbook book = application.Workbooks.Add();
            book.BeforeCloseEvent += new Excel.Workbook_BeforeCloseEventHandler(book_BeforeCloseEvent);

            // we dispose the instance. the parameter false signals to api dont release the event listener
            // set parameter to true and the event listener will stopped and you dont get events for the instance
            // the DisposeChildInstances() method has the same method overload
            book.Close();
            book.Dispose(false);

            application.Quit();
            application.Dispose();

            // the application object is ouer root object
            // dispose them release himself and any childs of application, in this case workbooks and workbook
            // the excel instance are now removed from process list

            _hostApplication.ShowFinishDialog();
        }
Esempio n. 2
0
        public void Run()
        {
            // NetOffice instances implements the IClonable interface
            // and deal with underlying proxies as well

            Excel.Application application = new Excel.ApplicationClass();
            application.DisplayAlerts = false;
            Excel.Workbook book = application.Workbooks.Add();

            // clone the book
            Excel.Workbook cloneBook = book.Clone() as Excel.Workbook;

            // dispose the origin book keep the underlying proxy alive
            // until the clone is disposed
            book.Dispose();

            // alive and works even the origin book is disposed
            foreach (Excel.Worksheet sheet in cloneBook.Sheets)
            {
                Console.WriteLine(sheet);
            }

            application.Quit();
            application.Dispose();

            HostApplication.ShowFinishDialog();
        }
Esempio n. 3
0
 private void excelApplication_WorkbookDeactivate(Excel.Workbook Wb)
 {
     textBoxEvents.BeginInvoke(_updateDelegate, new object[] { "Event WorkbookDeactivate called." });
     Wb.Dispose();
 }
Esempio n. 4
0
 private void excelApplication_WorkbookBeforeClose(Excel.Workbook Wb, ref bool Cancel)
 {
     textBoxEvents.BeginInvoke(_updateDelegate, new object[] { "Event WorkbookBeforeClose called." });
     Wb.Dispose();
 }
Esempio n. 5
0
 void ExcelApplication_WorkbookDeactivate(Excel.Workbook Wb)
 {
     _workbookDeactivateEvent = true;
     Wb.Dispose();
 }
Esempio n. 6
0
 void ExcelApplication_WorkbookBeforeClose(Excel.Workbook Wb, ref bool Cancel)
 {
     _workbookBeforeCloseEvent = true;
     Wb.Dispose();
 }
Esempio n. 7
0
 void ExcelApplication_NewWorkbook(Excel.Workbook Wb)
 {
     _newWorkbookEvent = true;
     Wb.Dispose();
 }
Esempio n. 8
0
 void excelApplication_NewWorkbook(Excel.Workbook Wb)
 {
     textBoxEvents.BeginInvoke(_updateDelegate, new object[] { "Event NewWorkbook called." });
     Wb.Dispose();
 }