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


C# XSSFWorkbook.GetCTWorkbook方法代码示例

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


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

示例1: TestSaveLoadNew

        public void TestSaveLoadNew()
        {
            XSSFWorkbook workbook = new XSSFWorkbook();

            //check that the default date system is Set to 1900
            CT_WorkbookPr pr = workbook.GetCTWorkbook().workbookPr;
            Assert.IsNotNull(pr);
            Assert.IsTrue(pr.IsSetDate1904());
            Assert.IsFalse(pr.date1904, "XSSF must use the 1900 date system");

            ISheet sheet1 = workbook.CreateSheet("sheet1");
            ISheet sheet2 = workbook.CreateSheet("sheet2");
            workbook.CreateSheet("sheet3");

            IRichTextString rts = workbook.GetCreationHelper().CreateRichTextString("hello world");

            sheet1.CreateRow(0).CreateCell((short)0).SetCellValue(1.2);
            sheet1.CreateRow(1).CreateCell((short)0).SetCellValue(rts);
            sheet2.CreateRow(0);

            Assert.AreEqual(0, workbook.GetSheetAt(0).FirstRowNum);
            Assert.AreEqual(1, workbook.GetSheetAt(0).LastRowNum);
            Assert.AreEqual(0, workbook.GetSheetAt(1).FirstRowNum);
            Assert.AreEqual(0, workbook.GetSheetAt(1).LastRowNum);
            Assert.AreEqual(0, workbook.GetSheetAt(2).FirstRowNum);
            Assert.AreEqual(0, workbook.GetSheetAt(2).LastRowNum);

            FileInfo file = TempFile.CreateTempFile("poi-", ".xlsx");
            Stream out1 = File.OpenWrite(file.Name);
            workbook.Write(out1);
            out1.Close();

            // Check the namespace Contains what we'd expect it to
            OPCPackage pkg = OPCPackage.Open(file.ToString());
            PackagePart wbRelPart =
                pkg.GetPart(PackagingUriHelper.CreatePartName("/xl/_rels/workbook.xml.rels"));
            Assert.IsNotNull(wbRelPart);
            Assert.IsTrue(wbRelPart.IsRelationshipPart);
            Assert.AreEqual(ContentTypes.RELATIONSHIPS_PART, wbRelPart.ContentType);

            PackagePart wbPart =
                pkg.GetPart(PackagingUriHelper.CreatePartName("/xl/workbook.xml"));
            // Links to the three sheets, shared strings and styles
            Assert.IsTrue(wbPart.HasRelationships);
            Assert.AreEqual(5, wbPart.Relationships.Size);

            // Load back the XSSFWorkbook
            workbook = new XSSFWorkbook(pkg);
            Assert.AreEqual(3, workbook.NumberOfSheets);
            Assert.IsNotNull(workbook.GetSheetAt(0));
            Assert.IsNotNull(workbook.GetSheetAt(1));
            Assert.IsNotNull(workbook.GetSheetAt(2));

            Assert.IsNotNull(workbook.GetSharedStringSource());
            Assert.IsNotNull(workbook.GetStylesSource());

            Assert.AreEqual(0, workbook.GetSheetAt(0).FirstRowNum);
            Assert.AreEqual(1, workbook.GetSheetAt(0).LastRowNum);
            Assert.AreEqual(0, workbook.GetSheetAt(1).FirstRowNum);
            Assert.AreEqual(0, workbook.GetSheetAt(1).LastRowNum);
            Assert.AreEqual(0, workbook.GetSheetAt(2).FirstRowNum);
            Assert.AreEqual(0, workbook.GetSheetAt(2).LastRowNum);

            sheet1 = workbook.GetSheetAt(0);
            Assert.AreEqual(1.2, sheet1.GetRow(0).GetCell(0).NumericCellValue, 0.0001);
            Assert.AreEqual("hello world", sheet1.GetRow(1).GetCell(0).RichStringCellValue.String);
        }
开发者ID:kahinke,项目名称:npoi,代码行数:67,代码来源:TestXSSFWorkbook.cs

示例2: TestSetForceFormulaRecalculation

        public void TestSetForceFormulaRecalculation()
        {
            XSSFWorkbook workbook = new XSSFWorkbook();
            XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet("Sheet 1");

            // Set
            sheet.ForceFormulaRecalculation = (true);
            Assert.AreEqual(true, sheet.ForceFormulaRecalculation);

            // calcMode="manual" is unset when forceFormulaRecalculation=true
            CT_CalcPr calcPr = workbook.GetCTWorkbook().AddNewCalcPr();
            calcPr.calcMode = (ST_CalcMode.manual);
            sheet.ForceFormulaRecalculation=(true);
            Assert.AreEqual(ST_CalcMode.auto, calcPr.calcMode);

            // Check
            sheet.ForceFormulaRecalculation = (false);
            Assert.AreEqual(false, sheet.ForceFormulaRecalculation);


            // Save, re-load, and re-check
            workbook = (XSSFWorkbook)XSSFTestDataSamples.WriteOutAndReadBack(workbook);
            sheet = (XSSFSheet)workbook.GetSheet("Sheet 1");
            Assert.AreEqual(false, sheet.ForceFormulaRecalculation);
        }
开发者ID:WPG,项目名称:npoi,代码行数:25,代码来源:TestXSSFSheet.cs

示例3: TestRecalcId

        public void TestRecalcId()
        {
            XSSFWorkbook wb = new XSSFWorkbook();
            Assert.IsFalse(wb.GetForceFormulaRecalculation());
            CT_Workbook ctWorkbook = wb.GetCTWorkbook();
            Assert.IsFalse(ctWorkbook.IsSetCalcPr());

            wb.SetForceFormulaRecalculation(true); // resets the EngineId flag to zero

            CT_CalcPr calcPr = ctWorkbook.calcPr;
            Assert.IsNotNull(calcPr);
            Assert.AreEqual(0, (int)calcPr.calcId);

            calcPr.calcId = 100;
            Assert.IsTrue(wb.GetForceFormulaRecalculation());

            wb.SetForceFormulaRecalculation(true); // resets the EngineId flag to zero
            Assert.AreEqual(0, (int)calcPr.calcId);
            Assert.IsFalse(wb.GetForceFormulaRecalculation());

            // calcMode="manual" is unset when forceFormulaRecalculation=true
            calcPr.calcMode = (ST_CalcMode.manual);
            wb.SetForceFormulaRecalculation(true);
            Assert.AreEqual(ST_CalcMode.auto, calcPr.calcMode);
        }
开发者ID:kahinke,项目名称:npoi,代码行数:25,代码来源:TestXSSFWorkbook.cs

示例4: AddPivotCache

 public void AddPivotCache()
 {
     XSSFWorkbook wb = new XSSFWorkbook();
     try
     {
         CT_Workbook ctWb = wb.GetCTWorkbook();
         CT_PivotCache pivotCache = wb.AddPivotCache("0");
         //Ensures that pivotCaches is Initiated
         Assert.IsTrue(ctWb.IsSetPivotCaches());
         Assert.AreSame(pivotCache, ctWb.pivotCaches.GetPivotCacheArray(0));
         Assert.AreEqual("0", pivotCache.id);
     }
     finally
     {
         wb.Close();
     }
 }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:17,代码来源:TestXSSFWorkbook.cs


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