예제 #1
0
        public void SetText(XSSFRichTextString str)
        {
            XSSFWorkbook parent = (XSSFWorkbook)this.GetDrawing().GetParent().GetParent();

            str.SetStylesTableReference(parent.GetStylesSource());
            CT_TextParagraph ctTextParagraph = new CT_TextParagraph();

            if (str.NumFormattingRuns == 0)
            {
                CT_RegularTextRun          ctRegularTextRun    = ctTextParagraph.AddNewR();
                CT_TextCharacterProperties characterProperties = ctRegularTextRun.AddNewRPr();
                characterProperties.lang = "en-US";
                characterProperties.sz   = 1100;
                ctRegularTextRun.t       = str.String;
            }
            else
            {
                for (int index = 0; index < str.GetCTRst().sizeOfRArray(); ++index)
                {
                    CT_RElt                    rarray           = str.GetCTRst().GetRArray(index);
                    CT_RPrElt                  pr               = rarray.rPr ?? rarray.AddNewRPr();
                    CT_RegularTextRun          ctRegularTextRun = ctTextParagraph.AddNewR();
                    CT_TextCharacterProperties rPr              = ctRegularTextRun.AddNewRPr();
                    rPr.lang = "en-US";
                    XSSFSimpleShape.ApplyAttributes(pr, rPr);
                    ctRegularTextRun.t = rarray.t;
                }
            }
            this.ctShape.txBody.SetPArray(new CT_TextParagraph[1]
            {
                ctTextParagraph
            });
        }
예제 #2
0
        /**
         * Append new text to this text run and apply the specify font to it
         *
         * @param text  the text to append
         * @param font  the font to apply to the Appended text or <code>null</code> if no formatting is required
         */
        public void Append(String text, XSSFFont font)
        {
            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();
            }
            CT_RElt lt = st.AddNewR();

            lt.t = (text);
            CT_RPrElt pr = lt.AddNewRPr();

            if (font != null)
            {
                SetRunAttributes(font.GetCTFont(), pr);
            }
        }
예제 #3
0
        /**
         * Add a new paragraph run to this shape, Set to the provided rich text string
         *
         * @return Created paragraph run
         */
        public XSSFTextParagraph AddNewTextParagraph(XSSFRichTextString str)
        {
            NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_TextBody txBody = ctShape.txBody;
            CT_TextParagraph p = txBody.AddNewP();

            if (str.NumFormattingRuns == 0)
            {
                CT_RegularTextRun          r   = p.AddNewR();
                CT_TextCharacterProperties rPr = r.AddNewRPr();
                rPr.lang = (/*setter*/ "en-US");
                rPr.sz   = (/*setter*/ 1100);
                r.t      = (/*setter*/ str.String);
            }
            else
            {
                for (int i = 0; i < str.GetCTRst().SizeOfRArray(); i++)
                {
                    CT_RElt   lt   = str.GetCTRst().GetRArray(i);
                    CT_RPrElt ltPr = lt.rPr;
                    if (ltPr == null)
                    {
                        ltPr = lt.AddNewRPr();
                    }

                    CT_RegularTextRun          r   = p.AddNewR();
                    CT_TextCharacterProperties rPr = r.AddNewRPr();
                    rPr.lang = (/*setter*/ "en-US");

                    ApplyAttributes(ltPr, rPr);

                    r.t = (/*setter*/ lt.t);
                }
            }

            // Note: the XSSFTextParagraph constructor will create its required XSSFTextRuns from the provided CTTextParagraph
            XSSFTextParagraph paragraph = new XSSFTextParagraph(p, ctShape);

            _paragraphs.Add(paragraph);

            return(paragraph);
        }
예제 #4
0
        /**
         * Set a single paragraph of text on the shape. Note this will replace all existing paragraphs Created on the shape.
         * @param str	rich text string representing the paragraph text
         */
        public void SetText(XSSFRichTextString str)
        {
            XSSFWorkbook wb = (XSSFWorkbook)GetDrawing().GetParent().GetParent();

            str.SetStylesTableReference(wb.GetStylesSource());

            CT_TextParagraph p = new CT_TextParagraph();

            if (str.NumFormattingRuns == 0)
            {
                CT_RegularTextRun          r   = p.AddNewR();
                CT_TextCharacterProperties rPr = r.AddNewRPr();
                rPr.lang = (/*setter*/ "en-US");
                rPr.sz   = (/*setter*/ 1100);
                r.t      = (/*setter*/ str.String);
            }
            else
            {
                for (int i = 0; i < str.GetCTRst().SizeOfRArray(); i++)
                {
                    CT_RElt   lt   = str.GetCTRst().GetRArray(i);
                    CT_RPrElt ltPr = lt.rPr;
                    if (ltPr == null)
                    {
                        ltPr = lt.AddNewRPr();
                    }

                    CT_RegularTextRun          r   = p.AddNewR();
                    CT_TextCharacterProperties rPr = r.AddNewRPr();
                    rPr.lang = (/*setter*/ "en-US");

                    ApplyAttributes(ltPr, rPr);

                    r.t = (/*setter*/ lt.t);
                }
            }

            ClearText();
            ctShape.txBody.SetPArray(new CT_TextParagraph[] { p });
            _paragraphs.Add(new XSSFTextParagraph(ctShape.txBody.GetPArray(0), ctShape));
        }
예제 #5
0
        public void Append(string text, XSSFFont font)
        {
            if (this.st.sizeOfRArray() == 0 && this.st.IsSetT())
            {
                CT_RElt ctRelt = this.st.AddNewR();
                ctRelt.t = this.st.t;
                XSSFRichTextString.PreserveSpaces(ctRelt.t);
                this.st.unsetT();
            }
            CT_RElt ctRelt1 = this.st.AddNewR();

            ctRelt1.t = text;
            XSSFRichTextString.PreserveSpaces(ctRelt1.t);
            CT_RPrElt pr = ctRelt1.AddNewRPr();

            if (font == null)
            {
                return;
            }
            this.SetRunAttributes(font.GetCTFont(), pr);
        }
예제 #6
0
        public void TestCreateNew()
        {
            SharedStringsTable sst = new SharedStringsTable();

            CT_Rst st;
            int    idx;

            // Check defaults
            Assert.IsNotNull(sst.Items);
            Assert.AreEqual(0, sst.Items.Count);
            Assert.AreEqual(0, sst.Count);
            Assert.AreEqual(0, sst.UniqueCount);

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

            idx = sst.AddEntry(st);
            Assert.AreEqual(0, idx);
            Assert.AreEqual(1, sst.Count);
            Assert.AreEqual(1, sst.UniqueCount);

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

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

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

            idx = sst.AddEntry(st);
            Assert.AreEqual(1, idx);
            Assert.AreEqual(4, sst.Count);
            Assert.AreEqual(2, sst.UniqueCount);

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

            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.Count);
            Assert.AreEqual(3, sst.UniqueCount);

            idx = sst.AddEntry(st);
            Assert.AreEqual(2, idx);
            Assert.AreEqual(7, sst.Count);
            Assert.AreEqual(3, sst.UniqueCount);

            //OK. the sst table is Filled, check the contents
            Assert.AreEqual(3, sst.Items.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());
        }