コード例 #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
        /**
         * Add a new run of text
         *
         * @return a new run of text
         */
        public XSSFTextRun AddNewTextRun()
        {
            CT_RegularTextRun          r   = _p.AddNewR();
            CT_TextCharacterProperties rPr = r.AddNewRPr();

            rPr.lang = ("en-US");
            XSSFTextRun run = new XSSFTextRun(r, this);

            _Runs.Add(run);
            return(run);
        }
コード例 #3
0
ファイル: XSSFSimpleShape.cs プロジェクト: Cy-Team/npoi
        /**
         * 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
ファイル: XSSFSimpleShape.cs プロジェクト: Cy-Team/npoi
        /**
         * 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));
        }