Пример #1
0
        public void TestClearFormatting()
        {
            XSSFRichTextString rt = new XSSFRichTextString("Apache POI");

            Assert.AreEqual("Apache POI", rt.String);
            Assert.AreEqual(false, rt.HasFormatting());

            rt.ClearFormatting();

            CT_Rst st = rt.GetCTRst();

            Assert.IsTrue(st.IsSetT());
            Assert.AreEqual("Apache POI", rt.String);
            Assert.AreEqual(0, rt.NumFormattingRuns);
            Assert.AreEqual(false, rt.HasFormatting());

            XSSFFont font = new XSSFFont();

            font.IsBold = true;

            rt.ApplyFont(7, 10, font);
            Assert.AreEqual(2, rt.NumFormattingRuns);
            Assert.AreEqual(true, rt.HasFormatting());

            rt.ClearFormatting();

            Assert.AreEqual("Apache POI", rt.String);
            Assert.AreEqual(0, rt.NumFormattingRuns);
            Assert.AreEqual(false, rt.HasFormatting());
        }
Пример #2
0
        public void TestCreate()
        {
            XSSFRichTextString rt = new XSSFRichTextString("Apache POI");

            Assert.AreEqual("Apache POI", rt.String);
            Assert.AreEqual(false, rt.HasFormatting());

            CT_Rst st = rt.GetCTRst();

            Assert.IsTrue(st.IsSetT());
            Assert.AreEqual("Apache POI", st.t);
            Assert.AreEqual(false, rt.HasFormatting());

            rt.Append(" is cool stuff");
            Assert.AreEqual(2, st.sizeOfRArray());
            Assert.IsFalse(st.IsSetT());

            Assert.AreEqual("Apache POI is cool stuff", rt.String);
            Assert.AreEqual(false, rt.HasFormatting());
        }
Пример #3
0
        public void TestApplyFont()
        {
            XSSFRichTextString rt = new XSSFRichTextString();

            rt.Append("123");
            rt.Append("4567");
            rt.Append("89");

            Assert.AreEqual("123456789", rt.String);
            Assert.AreEqual(false, rt.HasFormatting());

            XSSFFont font1 = new XSSFFont();

            font1.IsBold = (true);

            rt.ApplyFont(2, 5, font1);
            Assert.AreEqual(true, rt.HasFormatting());

            Assert.AreEqual(4, rt.NumFormattingRuns);
            Assert.AreEqual(0, rt.GetIndexOfFormattingRun(0));
            Assert.AreEqual("12", rt.GetCTRst().GetRArray(0).t);

            Assert.AreEqual(2, rt.GetIndexOfFormattingRun(1));
            Assert.AreEqual("345", rt.GetCTRst().GetRArray(1).t);

            Assert.AreEqual(5, rt.GetIndexOfFormattingRun(2));
            Assert.AreEqual(2, rt.GetLengthOfFormattingRun(2));
            Assert.AreEqual("67", rt.GetCTRst().GetRArray(2).t);

            Assert.AreEqual(7, rt.GetIndexOfFormattingRun(3));
            Assert.AreEqual(2, rt.GetLengthOfFormattingRun(3));
            Assert.AreEqual("89", rt.GetCTRst().GetRArray(3).t);

            Assert.AreEqual(-1, rt.GetIndexOfFormattingRun(9999));
            Assert.AreEqual(-1, rt.GetLengthOfFormattingRun(9999));
            Assert.IsNull(rt.GetFontAtIndex(9999));
        }