当前位置: 首页>>代码示例>>C#>>正文


C# Application.CalculateFullRebuild方法代码示例

本文整理汇总了C#中Application.CalculateFullRebuild方法的典型用法代码示例。如果您正苦于以下问题:C# Application.CalculateFullRebuild方法的具体用法?C# Application.CalculateFullRebuild怎么用?C# Application.CalculateFullRebuild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Application的用法示例。


在下文中一共展示了Application.CalculateFullRebuild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExcelTest

        public void ExcelTest(string workbook)
        {
            var outDir = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            m_xlApp = new Application();
            Assert.IsNotNull(m_xlApp, "Could not create an Excel Application object");

            var xlWorkbooks = m_xlApp.Workbooks;
            var testMacrosPath = Path.Combine(outDir, "testMacros.xlsm");
            var testMacros = xlWorkbooks.Open(testMacrosPath, 0, true, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            var pidAsObject = m_xlApp.Run(testMacros.Name + "!getpid");
            m_xlProcess = Process.GetProcessById(pidAsObject);
            var xldnaToLoad = PrepareXlDna(outDir);

            workbook = Path.Combine(outDir, "testWorkbooks", workbook);
            var workbookName = Path.GetFileName(workbook);

            Assert.IsTrue(File.Exists(workbook));
            Assert.IsTrue(m_xlApp.RegisterXLL(xldnaToLoad));

            m_xlApp.DisplayAlerts = false;

            m_xlWorkbook = xlWorkbooks.Open(workbook, 0, true, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            var workDir = Path.Combine(outDir, "evidence");
            if (!Directory.Exists(workDir))
            {
                try { Directory.CreateDirectory(workDir); } catch (Exception) { }; // more than 1 thread might get here, but only 1 will succeed
            }
            Assert.IsTrue(Directory.Exists(workDir));
            m_xlApp.Run(testMacros.Name + "!setProcessCurrentDirectory", workDir);

            m_xlApp.CalculateBeforeSave = false;

            bool vbaResult = false;
            try
            {
                vbaResult = m_xlApp.Run(m_xlWorkbook.Name + "!VBATest");
            }
            catch (COMException x)
            {
                // This HR means "Programmatic access to Visual Basic is not trusted"
                // It is returned also in case the macro does not exist
                // If we get anything other than this type of error, we rethrow.
                // Otherwise there's nothing to test and we carry on.
                if ((uint)x.HResult != 0x800a03ec)
                    throw;
                vbaResult = true;
            }
            Assert.IsTrue(vbaResult);

            Range resultRange = m_xlApp.Range["RESULT"];
            Assert.AreEqual(1, resultRange.Count);
            resultRange.Dirty();
            m_xlApp.CalculateFullRebuild();
            dynamic testResult = resultRange.Value;
            if (typeof(int) == testResult.GetType())
                Assert.Fail("RESULT={0}", hashErrorToString((uint)testResult));
            Assert.AreEqual(typeof(bool), testResult.GetType(), "RESULT={0}", testResult.ToString());
            Assert.IsTrue((bool)testResult);

            // the test has passed. we don't need to leave the xlsm around
            m_xlWorkbook.Close(false);
            m_xlWorkbook = null;
            File.Delete(workbook);
        }
开发者ID:Excel-DNA,项目名称:ExcelDna,代码行数:65,代码来源:Tests.cs


注:本文中的Application.CalculateFullRebuild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。