當前位置: 首頁>>代碼示例>>C#>>正文


C# XSSFWorkbook.GetSharedStringSource方法代碼示例

本文整理匯總了C#中NPOI.XSSF.UserModel.XSSFWorkbook.GetSharedStringSource方法的典型用法代碼示例。如果您正苦於以下問題:C# XSSFWorkbook.GetSharedStringSource方法的具體用法?C# XSSFWorkbook.GetSharedStringSource怎麽用?C# XSSFWorkbook.GetSharedStringSource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NPOI.XSSF.UserModel.XSSFWorkbook的用法示例。


在下文中一共展示了XSSFWorkbook.GetSharedStringSource方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: Bug57482

        public void Bug57482()
        {
            foreach (PackageAccess access in new PackageAccess[] {
                PackageAccess.READ_WRITE, PackageAccess.READ
        })
            {
                FileInfo file = HSSFTestDataSamples.GetSampleFile("57482-OnlyNumeric.xlsx");
                OPCPackage pkg = OPCPackage.Open(file, access);
                try
                {
                    XSSFWorkbook wb = new XSSFWorkbook(pkg);
                    Assert.IsNotNull(wb.GetSharedStringSource());
                    Assert.AreEqual(0, wb.GetSharedStringSource().Count);

                    DataFormatter fmt = new DataFormatter();
                    XSSFSheet s = wb.GetSheetAt(0) as XSSFSheet;
                    Assert.AreEqual("1", fmt.FormatCellValue(s.GetRow(0).GetCell(0)));
                    Assert.AreEqual("11", fmt.FormatCellValue(s.GetRow(0).GetCell(1)));
                    Assert.AreEqual("5", fmt.FormatCellValue(s.GetRow(4).GetCell(0)));

                    // Add a text cell
                    s.GetRow(0).CreateCell(3).SetCellValue("Testing");
                    Assert.AreEqual("Testing", fmt.FormatCellValue(s.GetRow(0).GetCell(3)));

                    // Try to Write-out and read again, should only work
                    //  in Read-write mode, not Read-only mode
                    try
                    {
                        wb = XSSFTestDataSamples.WriteOutAndReadBack(wb) as XSSFWorkbook;
                        if (access == PackageAccess.READ)
                            Assert.Fail("Shouln't be able to write from Read-only mode");
                    }
                    catch (InvalidOperationException e)
                    {
                        if (access == PackageAccess.READ)
                        {
                            // Expected
                        }
                        else
                        {
                            // Shouldn't occur in Write-mode
                            throw e;
                        }
                    }

                    // Check again
                    s = wb.GetSheetAt(0) as XSSFSheet;
                    Assert.AreEqual("1", fmt.FormatCellValue(s.GetRow(0).GetCell(0)));
                    Assert.AreEqual("11", fmt.FormatCellValue(s.GetRow(0).GetCell(1)));
                    Assert.AreEqual("5", fmt.FormatCellValue(s.GetRow(4).GetCell(0)));
                    Assert.AreEqual("Testing", fmt.FormatCellValue(s.GetRow(0).GetCell(3)));

                }
                finally
                {
                    pkg.Revert();
                }
            }
        }
開發者ID:age-soft,項目名稱:npoi,代碼行數:59,代碼來源:TestXSSFBugs.cs


注:本文中的NPOI.XSSF.UserModel.XSSFWorkbook.GetSharedStringSource方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。