コード例 #1
0
        public void TestRecoverInvalidHostApplication()
        {
            using (ExcelApplicationController applicationController = new ExcelApplicationController(true))
            {
                applicationController.CreateHostApplication(2000);
                Excel._Application application = (Excel._Application)applicationController.HostApplication;
                Assert.IsNotNull(application);
                Assert.IsTrue(applicationController.IsHostApplicationValid);

                // User kills all excel processes
                foreach (Process process in Process.GetProcessesByName("excel"))
                {
                    process.Kill();
                }

                Assert.IsFalse(applicationController.IsHostApplicationValid);

                object officeDocument = applicationController.OpenDocument(m_testPath + "test.xls", false);
                Assert.IsNotNull(officeDocument);
                Assert.IsTrue(applicationController.IsHostApplicationValid);

                application = (Excel._Application)applicationController.HostApplication;
                try
                {
                    Assert.AreEqual(1, application.Workbooks.Count);
                    Assert.IsInstanceOf(typeof(Excel.Workbook), officeDocument);
                }
                finally
                {
                    if (null != officeDocument)
                        Marshal.ReleaseComObject(officeDocument);

                    officeDocument = null;
                }
            }
        }
コード例 #2
0
        public void TestOpenDocument()
        {
            using (ExcelApplicationController applicationController = new ExcelApplicationController(true))
            {
                applicationController.CreateHostApplication(2000);
                object officeDocument = applicationController.OpenDocument(m_testPath + "test.xls", false);
                Assert.IsNotNull(officeDocument);
                try
                {
                    Assert.IsInstanceOf(typeof(Excel.Workbook), officeDocument);
                }
                finally
                {
                    if (null != officeDocument)
                        Marshal.ReleaseComObject(officeDocument);

                    officeDocument = null;
                }
            }
        }
コード例 #3
0
        public void TestEventsDisabledForAutoMacros()
        {
            using (ExcelApplicationController applicationController = new ExcelApplicationController(true))
            {
                applicationController.CreateHostApplication(2000);

                Excel.Workbook workbook = null;

                try
                {
                    workbook = (Excel.Workbook)applicationController.OpenDocument(m_testPath + "McKinzie bounce-test2.xls", false);
                    Assert.IsNotNull(workbook);
                    Assert.IsTrue(workbook.Saved);
                    Excel._Application application = (Excel._Application)applicationController.HostApplication;
                    Assert.IsNotNull(application);
                    Assert.IsFalse(application.EnableEvents);
                    applicationController.CloseDocument(workbook, false);
                }
                finally
                {
                    if (null != workbook)
                        Marshal.ReleaseComObject(workbook);

                    workbook = null;
                }
            }
        }
コード例 #4
0
        public void TestScreenUpdate()
        {
            using (ExcelApplicationController applicationController = new ExcelApplicationController(true))
            {
                applicationController.CreateHostApplication(2000);
                object officeDocument = null;
                try
                {
                    Excel._Application application = (Excel._Application)applicationController.HostApplication;
                    Assert.IsTrue(application.ScreenUpdating);

                    officeDocument = applicationController.OpenDocument(m_testPath + "test.xls", false);
                    Assert.IsNotNull(officeDocument);

                    Assert.IsFalse(application.ScreenUpdating);

                    applicationController.CloseDocument(officeDocument, false);

                    Assert.IsTrue(application.ScreenUpdating);
                }
                finally
                {
                    if (null != officeDocument)
                        Marshal.ReleaseComObject(officeDocument);

                    officeDocument = null;
                }
            }
        }
コード例 #5
0
 public void TestCloseInvalidDocument()
 {
     using(ExcelApplicationController applicationController = new ExcelApplicationController(true))
     {
         applicationController.CreateHostApplication(2000);
         applicationController.CloseDocument(new object(), false);
     }
 }
コード例 #6
0
        public void TestQuit()
        {
            using (ExcelApplicationController applicationController = new ExcelApplicationController(true))
            {
                applicationController.CreateHostApplication(2000);
                Assert.IsTrue(applicationController.IsHostApplicationValid, "Expected a valid host application");

                applicationController.Quit();

                Assert.IsFalse(applicationController.IsHostApplicationValid, "Expected the host application to be invalid after a quit");
            }
        }
コード例 #7
0
        public void TestCloseDocumentOnAlreadyClosedDocument()
        {
            using (ExcelApplicationController applicationController = new ExcelApplicationController(true))
            {
                applicationController.CreateHostApplication(2000);
                Excel.Workbook workbook = (Excel.Workbook)applicationController.OpenDocument(m_testPath + "test.xls", false);
                Assert.IsNotNull(workbook);

                try
                {
                    object vtMissing = Missing.Value;
                    workbook.Close(vtMissing, vtMissing, vtMissing);

                    applicationController.CloseDocument(workbook, false);
                }
                finally
                {
                    if (null != workbook)
                        Marshal.ReleaseComObject(workbook);

                    workbook = null;
                }
            }
        }
コード例 #8
0
 public void TestCloseNullDocument()
 {
     using (ExcelApplicationController applicationController = new ExcelApplicationController(true))
     {
         applicationController.CreateHostApplication(2000);
         applicationController.CloseDocument(null, false);
     }
 }
コード例 #9
0
        public void TestCloseDocument()
        {
            using (ExcelApplicationController applicationController = new ExcelApplicationController(true))
            {
                applicationController.CreateHostApplication(2000);
                object officeDocument = applicationController.OpenDocument(m_testPath + "test.xls", false);
                Assert.IsNotNull(officeDocument);

                Excel.Workbooks workbooks = null;
                try
                {
                    Assert.IsInstanceOf(typeof(Excel.Workbook), officeDocument);
                    Excel._Application application = (Excel._Application)applicationController.HostApplication;
                    workbooks = (Excel.Workbooks)application.Workbooks;
                    Assert.AreEqual(1, workbooks.Count);

                    applicationController.CloseDocument(officeDocument, false);
                    Assert.AreEqual(0, workbooks.Count);
                }
                finally
                {
                    if (null != officeDocument)
                        Marshal.ReleaseComObject(officeDocument);

                    officeDocument = null;

                    if (null != workbooks)
                        Marshal.ReleaseComObject(workbooks);

                    workbooks = null;
                }
            }
        }
コード例 #10
0
        private void TestOpenWithMergableDoc_Worker()
        {
			using (ExcelApplicationController controller = new ExcelApplicationController(true))
            {
                controller.CreateHostApplication(2000);
				object officeDocument = controller.OpenDocument(CopyFile(Path.Combine(m_testPath, "DoYouWantToMerge.xls")), false);
                Assert.IsNotNull(officeDocument);
                try
                {
                    Assert.IsInstanceOf(typeof(Excel.Workbook), officeDocument);
                }
                finally
                {
                    if (null != officeDocument)
                        Marshal.ReleaseComObject(officeDocument);

                    officeDocument = null;
                }
            }
        }
コード例 #11
0
 public void TestOpenDocumentInvalidHostApplication()
 {
     using(ExcelApplicationController applicationController = new ExcelApplicationController(true))
     {
         applicationController.OpenDocument(m_testPath + "test.xls", false);
     }
 }
コード例 #12
0
 public void TestOpenDocumentMissingFile()
 {
     using(ExcelApplicationController applicationController = new ExcelApplicationController(true))
     {
         applicationController.CreateHostApplication(2000);
         applicationController.OpenDocument(m_testPath + "doesNotExist.xls", false);
     }
 }
コード例 #13
0
 public void TestOpenInvalidDocument()
 {
     using(ExcelApplicationController applicationController = new ExcelApplicationController(true))
     {
         applicationController.CreateHostApplication(2000);
         applicationController.OpenDocument(null, false);
     }
 }