예제 #1
0
        public void TestReadWrite()
        {
            XSSFWorkbook       wb   = XSSFTestDataSamples.OpenSampleWorkbook("sample.xlsx");
            SharedStringsTable sst1 = wb.GetSharedStringSource();

            //Serialize, read back and compare with the original
            SharedStringsTable sst2 = ((XSSFWorkbook)XSSFTestDataSamples.WriteOutAndReadBack(wb)).GetSharedStringSource();

            Assert.AreEqual(sst1.GetCount(), sst2.GetCount());
            Assert.AreEqual(sst1.GetUniqueCount(), sst2.GetUniqueCount());

            List <CT_Rst> items1 = sst1.GetItems();
            List <CT_Rst> items2 = sst2.GetItems();

            Assert.AreEqual(items1.Count, items2.Count);
            for (int i = 0; i < items1.Count; i++)
            {
                CT_Rst st1 = items1[i];
                CT_Rst st2 = items2[i];
                Assert.AreEqual(st1.ToString(), st2.ToString());
            }
        }
예제 #2
0
        public void TestCreateNew()
        {
            SharedStringsTable sst = new SharedStringsTable();

            CT_Rst st;
            int    idx;

            // Check defaults
            Assert.IsNotNull(sst.GetItems());
            Assert.AreEqual(0, sst.GetItems().Count);
            Assert.AreEqual(0, sst.GetCount());
            Assert.AreEqual(0, sst.GetUniqueCount());

            st   = new CT_Rst();
            st.t = ("Hello, World!");

            idx = sst.AddEntry(st);
            Assert.AreEqual(0, idx);
            Assert.AreEqual(1, sst.GetCount());
            Assert.AreEqual(1, sst.GetUniqueCount());

            //add the same entry again
            idx = sst.AddEntry(st);
            Assert.AreEqual(0, idx);
            Assert.AreEqual(2, sst.GetCount());
            Assert.AreEqual(1, sst.GetUniqueCount());

            //and again
            idx = sst.AddEntry(st);
            Assert.AreEqual(0, idx);
            Assert.AreEqual(3, sst.GetCount());
            Assert.AreEqual(1, sst.GetUniqueCount());

            st   = new CT_Rst();
            st.t = ("Second string");

            idx = sst.AddEntry(st);
            Assert.AreEqual(1, idx);
            Assert.AreEqual(4, sst.GetCount());
            Assert.AreEqual(2, sst.GetUniqueCount());

            //add the same entry again
            idx = sst.AddEntry(st);
            Assert.AreEqual(1, idx);
            Assert.AreEqual(5, sst.GetCount());
            Assert.AreEqual(2, sst.GetUniqueCount());

            st = new CT_Rst();
            CT_RElt   r  = st.AddNewR();
            CT_RPrElt pr = r.AddNewRPr();

            pr.AddNewColor().SetRgb(new byte[] { (byte)0xFF, 0, 0 }); //red
            pr.AddNewI().val = (true);                                //bold
            pr.AddNewB().val = (true);                                //italic
            r.t = ("Second string");

            idx = sst.AddEntry(st);
            Assert.AreEqual(2, idx);
            Assert.AreEqual(6, sst.GetCount());
            Assert.AreEqual(3, sst.GetUniqueCount());

            idx = sst.AddEntry(st);
            Assert.AreEqual(2, idx);
            Assert.AreEqual(7, sst.GetCount());
            Assert.AreEqual(3, sst.GetUniqueCount());

            //OK. the sst table is Filled, check the contents
            Assert.AreEqual(3, sst.GetItems().Count);
            Assert.AreEqual("Hello, World!", new XSSFRichTextString(sst.GetEntryAt(0)).ToString());
            Assert.AreEqual("Second string", new XSSFRichTextString(sst.GetEntryAt(1)).ToString());
            Assert.AreEqual("Second string", new XSSFRichTextString(sst.GetEntryAt(2)).ToString());
        }
예제 #3
0
        public void TestCreateNew()
        {
            SharedStringsTable sst = new SharedStringsTable();

            CT_Rst st;
            int idx;

            // Check defaults
            Assert.IsNotNull(sst.GetItems());
            Assert.AreEqual(0, sst.GetItems().Count);
            Assert.AreEqual(0, sst.GetCount());
            Assert.AreEqual(0, sst.GetUniqueCount());

            st = new CT_Rst();
            st.t = ("Hello, World!");

            idx = sst.AddEntry(st);
            Assert.AreEqual(0, idx);
            Assert.AreEqual(1, sst.GetCount());
            Assert.AreEqual(1, sst.GetUniqueCount());

            //add the same entry again
            idx = sst.AddEntry(st);
            Assert.AreEqual(0, idx);
            Assert.AreEqual(2, sst.GetCount());
            Assert.AreEqual(1, sst.GetUniqueCount());

            //and again
            idx = sst.AddEntry(st);
            Assert.AreEqual(0, idx);
            Assert.AreEqual(3, sst.GetCount());
            Assert.AreEqual(1, sst.GetUniqueCount());

            st = new CT_Rst();
            st.t = ("Second string");

            idx = sst.AddEntry(st);
            Assert.AreEqual(1, idx);
            Assert.AreEqual(4, sst.GetCount());
            Assert.AreEqual(2, sst.GetUniqueCount());

            //add the same entry again
            idx = sst.AddEntry(st);
            Assert.AreEqual(1, idx);
            Assert.AreEqual(5, sst.GetCount());
            Assert.AreEqual(2, sst.GetUniqueCount());

            st = new CT_Rst();
            CT_RElt r = st.AddNewR();
            CT_RPrElt pr = r.AddNewRPr();
            pr.AddNewColor().SetRgb(new byte[] { (byte)0xFF, 0, 0 }); //red
            pr.AddNewI().val = (true);  //bold
            pr.AddNewB().val = (true);  //italic
            r.t = ("Second string");

            idx = sst.AddEntry(st);
            Assert.AreEqual(2, idx);
            Assert.AreEqual(6, sst.GetCount());
            Assert.AreEqual(3, sst.GetUniqueCount());

            idx = sst.AddEntry(st);
            Assert.AreEqual(2, idx);
            Assert.AreEqual(7, sst.GetCount());
            Assert.AreEqual(3, sst.GetUniqueCount());

            //OK. the sst table is Filled, check the contents
            Assert.AreEqual(3, sst.GetItems().Count);
            Assert.AreEqual("Hello, World!", new XSSFRichTextString(sst.GetEntryAt(0)).ToString());
            Assert.AreEqual("Second string", new XSSFRichTextString(sst.GetEntryAt(1)).ToString());
            Assert.AreEqual("Second string", new XSSFRichTextString(sst.GetEntryAt(2)).ToString());
        }