Exemple #1
0
        public static CT_Shape Parse(XElement node, XmlNamespaceManager namespaceManager)
        {
            if (node == null)
            {
                return(null);
            }
            CT_Shape ctObj = new CT_Shape();

            ctObj.macro      = XmlHelper.ReadString(node.Attribute("macro"));
            ctObj.textlink   = XmlHelper.ReadString(node.Attribute("textlink"));
            ctObj.fLocksText = XmlHelper.ReadBool(node.Attribute("fLocksText"));
            ctObj.fPublished = XmlHelper.ReadBool(node.Attribute("fPublished"));
            foreach (XElement childNode in node.ChildElements())
            {
                if (childNode.Name.LocalName == "nvSpPr")
                {
                    ctObj.nvSpPr = CT_ShapeNonVisual.Parse(childNode, namespaceManager);
                }
                else if (childNode.Name.LocalName == "spPr")
                {
                    ctObj.spPr = CT_ShapeProperties.Parse(childNode, namespaceManager);
                }
                else if (childNode.Name.LocalName == "txBody")
                {
                    ctObj.txBody = CT_TextBody.Parse(childNode, namespaceManager);
                }
                else if (childNode.Name.LocalName == "style")
                {
                    ctObj.style = CT_ShapeStyle.Parse(childNode, namespaceManager);
                }
            }
            return(ctObj);
        }
Exemple #2
0
        public static CT_TextBody Parse(XElement node, XmlNamespaceManager namespaceManager)
        {
            if (node == null)
            {
                return(null);
            }
            CT_TextBody ctObj = new CT_TextBody();

            ctObj.p = new List <CT_TextParagraph>();
            foreach (XElement childNode in node.ChildElements())
            {
                if (childNode.Name.LocalName == "bodyPr")
                {
                    ctObj.bodyPr = CT_TextBodyProperties.Parse(childNode, namespaceManager);
                }
                else if (childNode.Name.LocalName == "lstStyle")
                {
                    ctObj.lstStyle = CT_TextListStyle.Parse(childNode, namespaceManager);
                }
                else if (childNode.Name.LocalName == "p")
                {
                    ctObj.p.Add(CT_TextParagraph.Parse(childNode, namespaceManager));
                }
            }
            return(ctObj);
        }
Exemple #3
0
        /**
         * Add a new paragraph run to this shape
         *
         * @return Created paragraph run
         */

        public XSSFTextParagraph AddNewTextParagraph()
        {
            Npoi.Core.OpenXmlFormats.Dml.Spreadsheet.CT_TextBody txBody = ctShape.txBody;
            CT_TextParagraph  p         = txBody.AddNewP();
            XSSFTextParagraph paragraph = new XSSFTextParagraph(p, ctShape);

            _paragraphs.Add(paragraph);
            return(paragraph);
        }
Exemple #4
0
        public void Set(CT_Shape obj)
        {
            this.macroField      = obj.macro;
            this.textlinkField   = obj.textlink;
            this.fLocksTextField = obj.fLocksText;
            this.fPublishedField = obj.fPublished;

            this.nvSpPrField = obj.nvSpPr;
            this.spPrField   = obj.spPr;
            this.styleField  = obj.style;
            this.txBodyField = obj.txBody;
        }
Exemple #5
0
        protected internal XSSFSimpleShape(XSSFDrawing Drawing, CT_Shape ctShape)
        {
            this.drawing = Drawing;
            this.ctShape = ctShape;

            _paragraphs = new List <XSSFTextParagraph>();

            // Initialize any existing paragraphs - this will be the default body paragraph in a new shape,
            // or existing paragraphs that have been loaded from the file
            Npoi.Core.OpenXmlFormats.Dml.Spreadsheet.CT_TextBody body = ctShape.txBody;
            if (body != null)
            {
                for (int i = 0; i < body.SizeOfPArray(); i++)
                {
                    _paragraphs.Add(new XSSFTextParagraph(body.GetPArray(i), ctShape));
                }
            }
        }
Exemple #6
0
        /**
         * Prototype with the default structure of a new auto-shape.
         */

        protected internal static CT_Shape GetPrototype()
        {
            if (prototype == null)
            {
                CT_Shape shape = new CT_Shape();

                CT_ShapeNonVisual nv = shape.AddNewNvSpPr();
                Npoi.Core.OpenXmlFormats.Dml.Spreadsheet.CT_NonVisualDrawingProps nvp = nv.AddNewCNvPr();
                nvp.id   = (/*setter*/ 1);
                nvp.name = (/*setter*/ "Shape 1");
                nv.AddNewCNvSpPr();

                Npoi.Core.OpenXmlFormats.Dml.Spreadsheet.CT_ShapeProperties sp = shape.AddNewSpPr();
                CT_Transform2D    t2d = sp.AddNewXfrm();
                CT_PositiveSize2D p1  = t2d.AddNewExt();
                p1.cx = (/*setter*/ 0);
                p1.cy = (/*setter*/ 0);
                CT_Point2D p2 = t2d.AddNewOff();
                p2.x = (/*setter*/ 0);
                p2.y = (/*setter*/ 0);

                CT_PresetGeometry2D geom = sp.AddNewPrstGeom();
                geom.prst = (/*setter*/ ST_ShapeType.rect);
                geom.AddNewAvLst();

                Npoi.Core.OpenXmlFormats.Dml.Spreadsheet.CT_TextBody body = shape.AddNewTxBody();
                CT_TextBodyProperties bodypr = body.AddNewBodyPr();
                bodypr.anchor = (/*setter*/ ST_TextAnchoringType.t);
                bodypr.rtlCol = (/*setter*/ false);
                CT_TextParagraph p = body.AddNewP();
                p.AddNewPPr().algn = (/*setter*/ ST_TextAlignType.l);
                CT_TextCharacterProperties endPr = p.AddNewEndParaRPr();
                endPr.lang = (/*setter*/ "en-US");
                endPr.sz   = (/*setter*/ 1100);
                CT_SolidColorFillProperties scfpr = endPr.AddNewSolidFill();
                scfpr.AddNewSrgbClr().val         = (/*setter*/ new byte[] { 0, 0, 0 });

                body.AddNewLstStyle();

                prototype = shape;
            }
            return(prototype);
        }
Exemple #7
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.Core.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);
        }
Exemple #8
0
        /**
         * Clear all text from this shape
         */

        public void ClearText()
        {
            _paragraphs.Clear();
            Npoi.Core.OpenXmlFormats.Dml.Spreadsheet.CT_TextBody txBody = ctShape.txBody;
            txBody.SetPArray(null); // remove any existing paragraphs
        }
Exemple #9
0
 public CT_TextBody AddNewTxBody()
 {
     this.txBodyField = new CT_TextBody();
     return(this.txBodyField);
 }