/**
         * Applies a font to the specified characters of a string.
         *
         * @param startIndex    The start index to apply the font to (inclusive)
         * @param endIndex      The end index to apply to font to (exclusive)
         * @param font          The index of the font to use.
         */
        public void ApplyFont(int startIndex, int endIndex, IFont font)
        {
            if (startIndex > endIndex)
            {
                throw new ArgumentException("Start index must be less than end index.");
            }
            if (startIndex < 0 || endIndex > Length)
            {
                throw new ArgumentException("Start and end index not in range.");
            }
            if (startIndex == endIndex)
            {
                return;
            }

            if (st.sizeOfRArray() == 0 && st.IsSetT())
            {
                //convert <t>string</t> into a text Run: <r><t>string</t></r>
                st.AddNewR().t = (st.t);
                st.unsetT();
            }

            String   text     = this.String;
            XSSFFont xssfFont = (XSSFFont)font;

            SortedDictionary <int, CT_RPrElt> formats = GetFormatMap(st);
            CT_RPrElt fmt = new CT_RPrElt();

            SetRunAttributes(xssfFont.GetCTFont(), fmt);
            ApplyFont(formats, startIndex, endIndex, fmt);

            CT_Rst newSt = buildCTRst(text, formats);

            st.Set(newSt);
        }
Exemple #2
0
 public void SetStylesTableReference(StylesTable stylestable)
 {
     this.styles = stylestable;
     if (st.sizeOfRArray() > 0)
     {
         foreach (CT_RElt r in st.r)
         {
             CT_RPrElt pr = r.rPr;
             if (pr != null && pr.SizeOfRFontArray() > 0)
             {
                 String fontName = pr.GetRFontArray(0).val;
                 if (fontName.StartsWith("#"))
                 {
                     int      idx  = int.Parse(fontName.Substring(1));
                     XSSFFont font = styles.GetFontAt(idx);
                     pr.rFont = null;
                     SetRunAttributes(font.GetCTFont(), pr);
                 }
             }
         }
     }
 }
Exemple #3
0
        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);
        }