public void TestApplyFont() { XSSFRichTextString rt = new XSSFRichTextString(); rt.Append("123"); rt.Append("4567"); rt.Append("89"); Assert.AreEqual("123456789", rt.String); XSSFFont font1 = new XSSFFont(); font1.IsBold = (true); rt.ApplyFont(2, 5, font1); 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)); }
public void TestGetFonts() { XSSFRichTextString rt = new XSSFRichTextString(); XSSFFont font1 = new XSSFFont(); font1.FontName = ("Arial"); font1.IsItalic = (true); rt.Append("The quick", font1); XSSFFont font1FR = (XSSFFont)rt.GetFontOfFormattingRun(0); Assert.AreEqual(font1.IsItalic, font1FR.IsItalic); Assert.AreEqual(font1.FontName, font1FR.FontName); XSSFFont font2 = new XSSFFont(); font2.FontName = ("Courier"); font2.IsBold = (true); rt.Append(" brown fox", font2); XSSFFont font2FR = (XSSFFont)rt.GetFontOfFormattingRun(1); Assert.AreEqual(font2.IsBold, font2FR.IsBold); Assert.AreEqual(font2.FontName, font2FR.FontName); }
/** * make sure we insert xml:space="preserve" attribute * if a string has leading or trailing white spaces */ public void TestPreserveSpaces() { XSSFRichTextString rt = new XSSFRichTextString("Apache"); CT_Rst ct = rt.GetCTRst(); string t = ct.t; Assert.AreEqual("<t>Apache</t>", ct.XmlText); rt.String = " Apache"; Assert.AreEqual("<t xml:space=\"preserve\"> Apache</t>", ct.XmlText); rt.Append(" POI"); rt.Append(" "); Assert.AreEqual(" Apache POI ", rt.String); //Assert.AreEqual("<xml-fragment xml:space=\"preserve\"> Apache</t>", rt.GetCTRst().GetRArray(0).xmlText()); //Assert.AreEqual("<xml-fragment xml:space=\"preserve\"> POI</xml-fragment>", rt.getCTRst().getRArray(1).xgetT().xmlText()); //Assert.AreEqual("<xml-fragment xml:space=\"preserve\"> </xml-fragment>", rt.getCTRst().getRArray(2).xgetT().xmlText()); }
public void TestCreate() { XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); Assert.AreEqual("Apache POI", rt.String); CT_Rst st = rt.GetCTRst(); Assert.IsTrue(st.IsSetT()); Assert.AreEqual("Apache POI", st.t); rt.Append(" is cool stuff"); Assert.AreEqual(2, st.sizeOfRArray()); Assert.IsFalse(st.IsSetT()); Assert.AreEqual("Apache POI is cool stuff", rt.String); }