コード例 #1
0
        public void TestRichTextFontAndColor()
        {
            XSSFWorkbook wb      = new XSSFWorkbook();
            XSSFSheet    sheet   = wb.CreateSheet() as XSSFSheet;
            XSSFDrawing  Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;

            XSSFTextBox        shape = Drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4)) as XSSFTextBox;
            XSSFRichTextString rt    = new XSSFRichTextString("Test String");

            XSSFFont font = wb.CreateFont() as XSSFFont;

            font.SetColor(new XSSFColor(Color.FromRgb(0, 128, 128)));
            font.FontName = ("Arial");
            rt.ApplyFont(font);

            shape.SetText(rt);

            CT_TextParagraph pr = shape.GetCTShape().txBody.GetPArray(0);

            Assert.AreEqual(1, pr.SizeOfRArray());

            CT_TextCharacterProperties rPr = pr.GetRArray(0).rPr;

            Assert.AreEqual("Arial", rPr.latin.typeface);
            Assert.IsTrue(Arrays.Equals(
                              new byte[] { 0, (byte)128, (byte)128 },
                              rPr.solidFill.srgbClr.val));

            checkRewrite(wb);
            wb.Close();
        }
コード例 #2
0
        public static CT_TextBody Parse(XmlNode node, XmlNamespaceManager namespaceManager)
        {
            if (node == null)
            {
                return(null);
            }
            CT_TextBody ctObj = new CT_TextBody();

            ctObj.p = new List <CT_TextParagraph>();
            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.LocalName == "bodyPr")
                {
                    ctObj.bodyPr = CT_TextBodyProperties.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "lstStyle")
                {
                    ctObj.lstStyle = CT_TextListStyle.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "p")
                {
                    ctObj.p.Add(CT_TextParagraph.Parse(childNode, namespaceManager));
                }
            }
            return(ctObj);
        }
コード例 #3
0
        public void TestRichText()
        {
            XSSFWorkbook wb      = new XSSFWorkbook();
            XSSFSheet    sheet   = wb.CreateSheet() as XSSFSheet;
            XSSFDrawing  Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;

            XSSFTextBox        shape = Drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4)) as XSSFTextBox;
            XSSFRichTextString rt    = new XSSFRichTextString("Test String");

            XSSFFont font = wb.CreateFont() as XSSFFont;

            font.SetColor(new XSSFColor(Color.FromRgb(0, 128, 128)));
            font.IsItalic  = (true);
            font.IsBold    = (true);
            font.Underline = FontUnderlineType.Single;
            rt.ApplyFont(font);

            shape.SetText(rt);

            CT_TextParagraph pr = shape.GetCTShape().txBody.p[0];

            Assert.AreEqual(1, pr.SizeOfRArray());

            CT_TextCharacterProperties rPr = pr.r[0].rPr;

            Assert.AreEqual(true, rPr.b);
            Assert.AreEqual(true, rPr.i);
            Assert.AreEqual(ST_TextUnderlineType.sng, rPr.u);
            Assert.IsTrue(Arrays.Equals(
                              new byte[] { 0, (byte)128, (byte)128 },
                              rPr.solidFill.srgbClr.val));

            checkRewrite(wb);
            wb.Close();
        }
コード例 #4
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
            });
        }
コード例 #5
0
ファイル: XSSFSimpleShape.cs プロジェクト: Cy-Team/npoi
        /**
         * Add a new paragraph run to this shape
         *
         * @return Created paragraph run
         */
        public XSSFTextParagraph AddNewTextParagraph()
        {
            NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_TextBody txBody = ctShape.txBody;
            CT_TextParagraph  p         = txBody.AddNewP();
            XSSFTextParagraph paragraph = new XSSFTextParagraph(p, ctShape);

            _paragraphs.Add(paragraph);
            return(paragraph);
        }
コード例 #6
0
        public CT_TextParagraph AddNewP()
        {
            if (this.pField == null)
            {
                pField = new List <CT_TextParagraph>();
            }
            CT_TextParagraph tp = new CT_TextParagraph();

            pField.Add(tp);
            return(tp);
        }
コード例 #7
0
 internal static CT_Shape Prototype()
 {
     if (XSSFSimpleShape.prototype == null)
     {
         CT_Shape                 ctShape            = new CT_Shape();
         CT_ShapeNonVisual        ctShapeNonVisual   = ctShape.AddNewNvSpPr();
         CT_NonVisualDrawingProps visualDrawingProps = ctShapeNonVisual.AddNewCNvPr();
         visualDrawingProps.id   = 1U;
         visualDrawingProps.name = "Shape 1";
         ctShapeNonVisual.AddNewCNvSpPr();
         CT_ShapeProperties ctShapeProperties = ctShape.AddNewSpPr();
         CT_Transform2D     ctTransform2D     = ctShapeProperties.AddNewXfrm();
         CT_PositiveSize2D  ctPositiveSize2D  = ctTransform2D.AddNewExt();
         ctPositiveSize2D.cx = 0L;
         ctPositiveSize2D.cy = 0L;
         CT_Point2D ctPoint2D = ctTransform2D.AddNewOff();
         ctPoint2D.x = 0L;
         ctPoint2D.y = 0L;
         CT_PresetGeometry2D presetGeometry2D = ctShapeProperties.AddNewPrstGeom();
         presetGeometry2D.prst = ST_ShapeType.rect;
         presetGeometry2D.AddNewAvLst();
         CT_ShapeStyle  ctShapeStyle  = ctShape.AddNewStyle();
         CT_SchemeColor ctSchemeColor = ctShapeStyle.AddNewLnRef().AddNewSchemeClr();
         ctSchemeColor.val = ST_SchemeColorVal.accent1;
         ctSchemeColor.AddNewShade().val = 50000;
         ctShapeStyle.lnRef.idx = 2U;
         CT_StyleMatrixReference styleMatrixReference1 = ctShapeStyle.AddNewFillRef();
         styleMatrixReference1.idx = 1U;
         styleMatrixReference1.AddNewSchemeClr().val   = ST_SchemeColorVal.accent1;
         CT_StyleMatrixReference styleMatrixReference2 = ctShapeStyle.AddNewEffectRef();
         styleMatrixReference2.idx = 0U;
         styleMatrixReference2.AddNewSchemeClr().val = ST_SchemeColorVal.accent1;
         CT_FontReference ctFontReference            = ctShapeStyle.AddNewFontRef();
         ctFontReference.idx = ST_FontCollectionIndex.minor;
         ctFontReference.AddNewSchemeClr().val    = ST_SchemeColorVal.lt1;
         CT_TextBody           ctTextBody         = ctShape.AddNewTxBody();
         CT_TextBodyProperties textBodyProperties = ctTextBody.AddNewBodyPr();
         textBodyProperties.anchor = ST_TextAnchoringType.ctr;
         textBodyProperties.rtlCol = false;
         CT_TextParagraph ctTextParagraph = ctTextBody.AddNewP();
         ctTextParagraph.AddNewPPr().algn = ST_TextAlignType.ctr;
         CT_TextCharacterProperties characterProperties = ctTextParagraph.AddNewEndParaRPr();
         characterProperties.lang = "en-US";
         characterProperties.sz   = 1100;
         ctTextBody.AddNewLstStyle();
         XSSFSimpleShape.prototype = ctShape;
     }
     return(XSSFSimpleShape.prototype);
 }
コード例 #8
0
 XSSFTextParagraph(CT_TextParagraph p, CT_Shape ctShape)
 {
     _p     = p;
     _shape = ctShape;
     _Runs  = new List <XSSFTextRun>();
     foreach (object ch in _p.r)
     {
         if (ch is CT_RegularTextRun)
         {
             CT_RegularTextRun r = (CT_RegularTextRun)ch;
             _Runs.Add(new XSSFTextRun(r, this));
         }
         else if (ch is CT_TextLineBreak)
         {
             CT_TextLineBreak  br = (CT_TextLineBreak)ch;
             CT_RegularTextRun r  = new CT_RegularTextRun();
             r.rPr = (br.rPr);
             r.t   = ("\n");
             _Runs.Add(new XSSFTextRun(r, this));
         }
         else if (ch is CT_TextField)
         {
             CT_TextField      f = (CT_TextField)ch;
             CT_RegularTextRun r = new CT_RegularTextRun();
             r.rPr = (f.rPr);
             r.t   = (f.t);
             _Runs.Add(new XSSFTextRun(r, this));
         }
     }
     //foreach(XmlObject ch in _p.selectPath("*")){
     //    if(ch is CTRegularTextRun){
     //        CTRegularTextRun r = (CTRegularTextRun)ch;
     //        _Runs.add(new XSSFTextRun(r, this));
     //    } else if (ch is CTTextLineBreak){
     //        CTTextLineBreak br = (CTTextLineBreak)ch;
     //        CTRegularTextRun r = CTRegularTextRun.Factory.newInstance();
     //        r.SetRPr(br.GetRPr());
     //        r.SetT("\n");
     //        _Runs.add(new XSSFTextRun(r, this));
     //    } else if (ch is CTTextField){
     //        CTTextField f = (CTTextField)ch;
     //        CTRegularTextRun r = CTRegularTextRun.Factory.newInstance();
     //        r.SetRPr(f.GetRPr());
     //        r.SetT(f.GetT());
     //        _Runs.add(new XSSFTextRun(r, this));
     //    }
     //}
 }
コード例 #9
0
ファイル: XSSFSimpleShape.cs プロジェクト: zzy092/npoi
        /**
         * Prototype with the default structure of a new auto-shape.
         */
        protected internal static CT_Shape Prototype()
        {
            // in poi, method XmlObject set(XmlObject srcObj) will create a copy of XmlObject
            // so this prototype object would be newly set to shape object
            // but in .net, the prototype object will be modified and keep its contents, would
            // affect next usage. so comment the following code, and create a new prototype object
            // for every calling of Prototype().
            //if (prototype == null)
            {
                CT_Shape shape = new CT_Shape();

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

                NPOI.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.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);
        }
コード例 #10
0
ファイル: XSSFSimpleShape.cs プロジェクト: Cy-Team/npoi
        /**
         * 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.OpenXmlFormats.Dml.Spreadsheet.CT_NonVisualDrawingProps nvp = nv.AddNewCNvPr();
                nvp.id   = (/*setter*/ 1);
                nvp.name = (/*setter*/ "Shape 1");
                nv.AddNewCNvSpPr();

                NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_ShapeProperties sp  = shape.AddNewSpPr();
                NPOI.OpenXmlFormats.Dml.Spreadsheet.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.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);
        }
コード例 #11
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);
        }
コード例 #12
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));
        }
コード例 #13
0
ファイル: XSSFSimpleShape.cs プロジェクト: purehzj/npoi-1
        /**
         * Prototype with the default structure of a new auto-shape.
         */
        internal static CT_Shape Prototype()
        {
            if (prototype == null)
            {
                CT_Shape shape = new CT_Shape();


                CT_ShapeNonVisual        nv  = shape.AddNewNvSpPr();
                CT_NonVisualDrawingProps nvp = nv.AddNewCNvPr();
                nvp.id   = (1);
                nvp.name = ("Shape 1");
                nv.AddNewCNvSpPr();

                CT_ShapeProperties sp  = shape.AddNewSpPr();
                CT_Transform2D     t2d = sp.AddNewXfrm();
                CT_PositiveSize2D  p1  = t2d.AddNewExt();
                p1.cx = (0);
                p1.cy = (0);
                CT_Point2D p2 = t2d.AddNewOff();
                p2.x = (0);
                p2.y = (0);

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

                CT_ShapeStyle  style  = shape.AddNewStyle();
                CT_SchemeColor scheme = style.AddNewLnRef().AddNewSchemeClr();
                scheme.val = (ST_SchemeColorVal.accent1);
                scheme.AddNewShade().val = 50000;
                style.lnRef.idx = (2);

                CT_StyleMatrixReference Fillref = style.AddNewFillRef();
                Fillref.idx = (1);
                Fillref.AddNewSchemeClr().val = (ST_SchemeColorVal.accent1);

                CT_StyleMatrixReference effectRef = style.AddNewEffectRef();
                effectRef.idx = (0);
                effectRef.AddNewSchemeClr().val = (ST_SchemeColorVal.accent1);

                CT_FontReference fontRef = style.AddNewFontRef();
                fontRef.idx = (ST_FontCollectionIndex.minor);
                fontRef.AddNewSchemeClr().val = (ST_SchemeColorVal.lt1);

                CT_TextBody           body   = shape.AddNewTxBody();
                CT_TextBodyProperties bodypr = body.AddNewBodyPr();
                bodypr.anchor = (ST_TextAnchoringType.ctr);
                bodypr.rtlCol = (false);
                CT_TextParagraph p = body.AddNewP();

                p.AddNewPPr().algn = (ST_TextAlignType.ctr);
                CT_TextCharacterProperties endPr = p.AddNewEndParaRPr();
                endPr.lang = ("en-US");
                endPr.sz   = (1100);

                body.AddNewLstStyle();

                prototype = shape;
            }
            return(prototype);
        }
コード例 #14
0
ファイル: Chart.cs プロジェクト: runningwater/npoi
 public CT_TextParagraph AddNewP()
 {
     if (this.pField == null)
         pField = new List<CT_TextParagraph>();
     CT_TextParagraph tp = new CT_TextParagraph();
     pField.Add(tp);
     return tp;
 }
コード例 #15
0
ファイル: Chart.cs プロジェクト: runningwater/npoi
 public void SetPArray(CT_TextParagraph[] array)
 {
     pField = new List<CT_TextParagraph>(array);
 }
コード例 #16
0
ファイル: spreadsheetShape.cs プロジェクト: Reinakumiko/npoi
 public void SetPArray(CT_TextParagraph[] array)
 {
     if (array == null)
         pField.Clear();
     else
         pField = new List<CT_TextParagraph>(array);
 }