コード例 #1
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();
        }