Exemplo n.º 1
0
        public void TestFindCommentShape()
        {
            XSSFVMLDrawing vml = new XSSFVMLDrawing();
            vml.Read(POIDataSamples.GetSpreadSheetInstance().OpenResourceAsStream("vmlDrawing1.vml"));

            CT_Shape sh_a1 = vml.FindCommentShape(0, 0);
            Assert.IsNotNull(sh_a1);
            Assert.AreEqual("_x0000_s1025", sh_a1.id);

            CT_Shape sh_b1 = vml.FindCommentShape(0, 1);
            Assert.IsNotNull(sh_b1);
            Assert.AreEqual("_x0000_s1026", sh_b1.id);

            CT_Shape sh_c1 = vml.FindCommentShape(0, 2);
            Assert.IsNull(sh_c1);

            CT_Shape sh_d1 = vml.newCommentShape();
            Assert.AreEqual("_x0000_s1027", sh_d1.id);
            sh_d1.GetClientDataArray(0).SetRowArray(0, 0);
            sh_d1.GetClientDataArray(0).SetColumnArray(0, 3);
            Assert.AreSame(sh_d1, vml.FindCommentShape(0, 3));

            //newly created drawing
            XSSFVMLDrawing newVml = new XSSFVMLDrawing();
            Assert.IsNull(newVml.FindCommentShape(0, 0));

            sh_a1 = newVml.newCommentShape();
            Assert.AreEqual("_x0000_s1025", sh_a1.id);
            sh_a1.GetClientDataArray(0).SetRowArray(0, 0);
            sh_a1.GetClientDataArray(0).SetColumnArray(0, 1);
            Assert.AreSame(sh_a1, newVml.FindCommentShape(0, 1));
        }
Exemplo n.º 2
0
        internal CT_Shape newCommentShape()
        {
            CT_Shape ctShape = new CT_Shape();

            ctShape.id        = "_x0000_s" + (object)++this._shapeId;
            ctShape.type      = "#" + this._shapeTypeId;
            ctShape.style     = "position:absolute; visibility:hidden";
            ctShape.fillcolor = "#ffffe1";
            ctShape.insetmode = ST_InsetMode.auto;
            ctShape.AddNewFill().color = "#ffffe1";
            CT_Shadow ctShadow         = ctShape.AddNewShadow();

            ctShadow.on       = ST_TrueFalse.t;
            ctShadow.color    = "black";
            ctShadow.obscured = ST_TrueFalse.t;
            ctShape.AddNewPath().connecttype = ST_ConnectType.none;
            ctShape.AddNewTextbox().style    = "mso-direction-alt:auto";
            CT_ClientData ctClientData       = ctShape.AddNewClientData();

            ctClientData.ObjectType = ST_ObjectType.Note;
            ctClientData.AddNewMoveWithCells();
            ctClientData.AddNewSizeWithCells();
            ctClientData.AddNewAnchor("1, 15, 0, 2, 3, 15, 3, 16");
            ctClientData.AddNewAutoFill(ST_TrueFalseBlank.@false);
            ctClientData.AddNewRow(0);
            ctClientData.AddNewColumn(0);
            this._items.Add((object)ctShape);
            return(ctShape);
        }
Exemplo n.º 3
0
        internal CT_Shape newCommentShape()
        {
            CT_Shape shape = new CT_Shape();

            shape.id        = "_x0000_s" + (++_shapeId);
            shape.type      = "#" + _shapeTypeId;
            shape.style     = "position:absolute; visibility:hidden";
            shape.fillcolor = ("#ffffe1");
            shape.insetmode = (ST_InsetMode.auto);
            shape.AddNewFill().color = ("#ffffe1");
            CT_Shadow shadow         = shape.AddNewShadow();

            shadow.on       = NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t;
            shadow.color    = "black";
            shadow.obscured = NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t;
            shape.AddNewPath().connecttype = (ST_ConnectType.none);
            shape.AddNewTextbox().style    = ("mso-direction-alt:auto");
            CT_ClientData cldata           = shape.AddNewClientData();

            cldata.ObjectType = ST_ObjectType.Note;
            cldata.AddNewMoveWithCells();
            cldata.AddNewSizeWithCells();
            cldata.AddNewAnchor("1, 15, 0, 2, 3, 15, 3, 16");
            cldata.AddNewAutoFill(ST_TrueFalseBlank.@false);
            cldata.AddNewRow(0);
            cldata.AddNewColumn(0);
            _items.Add(shape);

            return(shape);
        }
Exemplo n.º 4
0
        internal void Read(Stream is1)
        {
            StreamReader sr   = new StreamReader(is1);
            string       data = sr.ReadToEnd().Replace("<br>", "");
            XDocument    doc  = XDocument.Load(new StringReader(data));

            //InflaterInputStream iis = (InflaterInputStream)is1;

            //Stream vmlsm = new EvilUnclosedBRFixingInputStream(is1); --TODO:: add later

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable());

            nsmgr.AddNamespace("o", "urn:schemas-microsoft-com:office:office");
            nsmgr.AddNamespace("x", "urn:schemas-microsoft-com:office:excel");
            nsmgr.AddNamespace("v", "urn:schemas-microsoft-com:vml");
            _items = new ArrayList();
            var nodes = doc.XPathSelectElements("/xml/*", nsmgr);

            foreach (XElement nd in nodes)
            {
                string xmltext = nd.OuterXml();
                if (nd.Name.LocalName == QNAME_SHAPE_LAYOUT.Name)
                {
                    CT_ShapeLayout sl = CT_ShapeLayout.Parse(nd, nsmgr);
                    _items.Add(sl);
                }
                else if (nd.Name.LocalName == QNAME_SHAPE_TYPE.Name)
                {
                    CT_Shapetype st     = CT_Shapetype.Parse(nd, nsmgr);
                    String       typeid = st.id;
                    if (typeid != null)
                    {
                        MatchCollection m = ptrn_shapeTypeId.Matches(typeid);
                        if (m.Count > 0)
                        {
                            _shapeTypeId = Math.Max(_shapeTypeId, int.Parse(m[0].Groups[1].Value));
                        }
                    }
                    _items.Add(st);
                }
                else if (nd.Name.LocalName == QNAME_SHAPE.Name)
                {
                    CT_Shape shape = CT_Shape.Parse(nd, nsmgr);
                    String   id    = shape.id;
                    if (id != null)
                    {
                        MatchCollection m = ptrn_shapeId.Matches(id);
                        if (m.Count > 0)
                        {
                            _shapeId = Math.Max(_shapeId, int.Parse(m[0].Groups[1].Value));
                        }
                    }
                    _items.Add(shape);
                }
                else
                {
                    _items.Add(nd);
                }
            }
        }
Exemplo n.º 5
0
        public static CT_Bar3DChart Parse(XElement node, XmlNamespaceManager namespaceManager)
        {
            if (node == null)
            {
                return(null);
            }
            CT_Bar3DChart ctObj = new CT_Bar3DChart();

            ctObj.ser    = new List <CT_BarSer>();
            ctObj.axId   = new List <CT_UnsignedInt>();
            ctObj.extLst = new List <CT_Extension>();
            foreach (XElement childNode in node.ChildElements())
            {
                if (childNode.Name.LocalName == "barDir")
                {
                    ctObj.barDir = CT_BarDir.Parse(childNode, namespaceManager);
                }
                else if (childNode.Name.LocalName == "grouping")
                {
                    ctObj.grouping = CT_BarGrouping.Parse(childNode, namespaceManager);
                }
                else if (childNode.Name.LocalName == "varyColors")
                {
                    ctObj.varyColors = CT_Boolean.Parse(childNode, namespaceManager);
                }
                else if (childNode.Name.LocalName == "dLbls")
                {
                    ctObj.dLbls = CT_DLbls.Parse(childNode, namespaceManager);
                }
                else if (childNode.Name.LocalName == "gapWidth")
                {
                    ctObj.gapWidth = CT_GapAmount.Parse(childNode, namespaceManager);
                }
                else if (childNode.Name.LocalName == "gapDepth")
                {
                    ctObj.gapDepth = CT_GapAmount.Parse(childNode, namespaceManager);
                }
                else if (childNode.Name.LocalName == "shape")
                {
                    ctObj.shape = CT_Shape.Parse(childNode, namespaceManager);
                }
                else if (childNode.Name.LocalName == "ser")
                {
                    ctObj.ser.Add(CT_BarSer.Parse(childNode, namespaceManager));
                }
                else if (childNode.Name.LocalName == "axId")
                {
                    ctObj.axId.Add(CT_UnsignedInt.Parse(childNode, namespaceManager));
                }
                else if (childNode.Name.LocalName == "extLst")
                {
                    ctObj.extLst.Add(CT_Extension.Parse(childNode, namespaceManager));
                }
            }
            return(ctObj);
        }
Exemplo n.º 6
0
        public void TestNew()
        {
            XSSFVMLDrawing vml = new XSSFVMLDrawing();
            ArrayList items = vml.GetItems();
            Assert.AreEqual(2, items.Count);
            Assert.IsTrue(items[0] is CT_ShapeLayout);
            CT_ShapeLayout layout = (CT_ShapeLayout)items[0];
            Assert.AreEqual(ST_Ext.edit, layout.ext);
            Assert.AreEqual(ST_Ext.edit, layout.idmap.ext);
            Assert.AreEqual("1", layout.idmap.data);

            Assert.IsTrue(items[1] is CT_Shapetype);
            CT_Shapetype type = (CT_Shapetype)items[1];
            Assert.AreEqual("21600,21600", type.coordsize);
            Assert.AreEqual(202.0f, type.spt);
            Assert.AreEqual("m,l,21600r21600,l21600,xe", type.path2);
            Assert.AreEqual("_xssf_cell_comment", type.id);
            Assert.AreEqual(ST_TrueFalse.t, type.path.gradientshapeok);
            Assert.AreEqual(ST_ConnectType.rect, type.path.connecttype);

            CT_Shape shape = vml.newCommentShape();
            Assert.AreEqual(3, items.Count);
            Assert.AreSame(items[2], shape);
            Assert.AreEqual("#_xssf_cell_comment", shape.type);
            Assert.AreEqual("position:absolute; visibility:hidden", shape.style);
            Assert.AreEqual("#ffffe1", shape.fillcolor);
            Assert.AreEqual(ST_InsetMode.auto, shape.insetmode);
            Assert.AreEqual("#ffffe1", shape.fill.color);
            CT_Shadow shadow = shape.shadow;
            Assert.AreEqual(ST_TrueFalse.t, shadow.on);
            Assert.AreEqual("black", shadow.color);
            Assert.AreEqual(ST_TrueFalse.t, shadow.obscured);
            Assert.AreEqual(ST_ConnectType.none, shape.path.connecttype);
            Assert.AreEqual("mso-direction-alt:auto", shape.textbox.style);
            CT_ClientData cldata = shape.GetClientDataArray(0);
            Assert.AreEqual(ST_ObjectType.Note, cldata.ObjectType);
            Assert.AreEqual(1, cldata.SizeOfMoveWithCellsArray());
            Assert.AreEqual(1, cldata.SizeOfSizeWithCellsArray());
            Assert.AreEqual("1, 15, 0, 2, 3, 15, 3, 16", cldata.anchor);
            Assert.AreEqual(ST_TrueFalseBlank.@false, cldata.autoFill);
            Assert.AreEqual(0, cldata.GetRowArray(0));
            Assert.AreEqual(0, cldata.GetColumnArray(0));

            //serialize and read again
            MemoryStream out1 = new MemoryStream();
            vml.Write(out1);

            XSSFVMLDrawing vml2 = new XSSFVMLDrawing();
            vml2.Read(new MemoryStream(out1.ToArray()));
            ArrayList items2 = vml2.GetItems();
            Assert.AreEqual(3, items2.Count);
            Assert.IsTrue(items2[0] is CT_ShapeLayout);
            Assert.IsTrue(items2[1] is CT_Shapetype);
            Assert.IsTrue(items2[2] is CT_Shape);
        }
Exemplo n.º 7
0
        public void TestRemoveCommentShape()
        {
            XSSFVMLDrawing vml = new XSSFVMLDrawing();
            vml.Read(POIDataSamples.GetSpreadSheetInstance().OpenResourceAsStream("vmlDrawing1.vml"));

            CT_Shape sh_a1 = vml.FindCommentShape(0, 0);
            Assert.IsNotNull(sh_a1);

            Assert.IsTrue(vml.RemoveCommentShape(0, 0));
            Assert.IsNull(vml.FindCommentShape(0, 0));
        }
Exemplo n.º 8
0
        internal bool RemoveCommentShape(int row, int col)
        {
            CT_Shape commentShape = this.FindCommentShape(row, col);

            if (commentShape == null)
            {
                return(false);
            }
            this._items.Remove((object)commentShape);
            return(true);
        }
Exemplo n.º 9
0
        internal bool RemoveCommentShape(int row, int col)
        {
            CT_Shape shape = FindCommentShape(row, col);

            if (shape == null)
            {
                return(false);
            }
            _items.Remove(shape);
            return(true);
        }
Exemplo n.º 10
0
        public XSSFSimpleShape CreateSimpleShape(XSSFChildAnchor anchor)
        {
            CT_Shape ctShape = this.ctGroup.AddNewSp();

            ctShape.Set(XSSFSimpleShape.Prototype());
            XSSFSimpleShape xssfSimpleShape = new XSSFSimpleShape(this.GetDrawing(), ctShape);

            xssfSimpleShape.parent = this;
            xssfSimpleShape.anchor = (XSSFAnchor)anchor;
            xssfSimpleShape.GetCTShape().spPr.xfrm = anchor.GetCTTransform2D();
            return(xssfSimpleShape);
        }
Exemplo n.º 11
0
 public CT_Bar3DChart()
 {
     this.extLstField     = new List <CT_Extension>();
     this.axIdField       = new List <CT_UnsignedInt>();
     this.shapeField      = new CT_Shape();
     this.gapDepthField   = new CT_GapAmount();
     this.gapWidthField   = new CT_GapAmount();
     this.dLblsField      = new CT_DLbls();
     this.serField        = new List <CT_BarSer>();
     this.varyColorsField = new CT_Boolean();
     this.groupingField   = new CT_BarGrouping();
     this.barDirField     = new CT_BarDir();
 }
Exemplo n.º 12
0
        /**
         * Constructs a textbox.
         *
         * @param anchor the child anchor describes how this shape is attached
         *               to the group.
         * @return      the newly Created textbox.
         */
        public XSSFTextBox CreateTextbox(XSSFChildAnchor anchor)
        {
            CT_Shape ctShape = ctGroup.AddNewSp();

            ctShape.Set(XSSFSimpleShape.Prototype());

            XSSFTextBox shape = new XSSFTextBox(GetDrawing(), ctShape);

            shape.parent = this;
            shape.anchor = anchor;
            shape.GetCTShape().spPr.xfrm = (anchor.GetCTTransform2D());
            return(shape);
        }
Exemplo n.º 13
0
        /**
         * Constructs a textbox under the Drawing.
         *
         * @param anchor    the client anchor describes how this group is attached
         *                  to the sheet.
         * @return      the newly Created textbox.
         */
        public ITextbox CreateTextbox(IClientAnchor anchor)
        {
            long             shapeId  = newShapeId();
            CT_TwoCellAnchor ctAnchor = CreateTwoCellAnchor(anchor);
            CT_Shape         ctShape  = ctAnchor.AddNewSp();

            ctShape.Set(XSSFSimpleShape.Prototype());
            ctShape.nvSpPr.cNvPr.id = (uint)shapeId;
            XSSFTextBox shape = new XSSFTextBox(this, ctShape);

            shape.anchor = (XSSFClientAnchor)anchor;
            return(shape);
        }
Exemplo n.º 14
0
        /**
         * Creates a simple shape.  This includes such shapes as lines, rectangles,
         * and ovals.
         *
         * @param anchor    the client anchor describes how this group is attached
         *                  to the sheet.
         * @return  the newly Created shape.
         */
        public XSSFSimpleShape CreateSimpleShape(XSSFClientAnchor anchor)
        {
            long             shapeId  = newShapeId();
            CT_TwoCellAnchor ctAnchor = CreateTwoCellAnchor(anchor);
            CT_Shape         ctShape  = ctAnchor.AddNewSp();

            ctShape.Set(XSSFSimpleShape.Prototype());
            ctShape.nvSpPr.cNvPr.id = (uint)(shapeId);
            XSSFSimpleShape shape = new XSSFSimpleShape(this, ctShape);

            shape.anchor = anchor;
            return(shape);
        }
Exemplo n.º 15
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);
 }
Exemplo n.º 16
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));
     //    }
     //}
 }
Exemplo n.º 17
0
        /**
         * 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);
        }
Exemplo n.º 18
0
        internal void Read(Stream is1)
        {
            XmlDocument xmlDocument = new XmlDocument();
            string      end         = new StreamReader(is1).ReadToEnd();

            xmlDocument.LoadXml(end.Replace("<br>", ""));
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);

            nsmgr.AddNamespace("o", "urn:schemas-microsoft-com:office:office");
            nsmgr.AddNamespace("x", "urn:schemas-microsoft-com:office:excel");
            nsmgr.AddNamespace("v", "urn:schemas-microsoft-com:vml");
            this._items = new ArrayList();
            foreach (XmlNode selectNode in xmlDocument.SelectNodes("/xml/*", nsmgr))
            {
                string outerXml = selectNode.OuterXml;
                if (selectNode.LocalName == XSSFVMLDrawing.QNAME_SHAPE_LAYOUT.Name)
                {
                    this._items.Add((object)CT_ShapeLayout.Parse(outerXml));
                }
                else if (selectNode.LocalName == XSSFVMLDrawing.QNAME_SHAPE_TYPE.Name)
                {
                    CT_Shapetype ctShapetype = CT_Shapetype.Parse(outerXml);
                    this._shapeTypeId = ctShapetype.id;
                    this._items.Add((object)ctShapetype);
                }
                else if (selectNode.LocalName == XSSFVMLDrawing.QNAME_SHAPE.Name)
                {
                    CT_Shape ctShape = CT_Shape.Parse(outerXml);
                    string   id      = ctShape.id;
                    if (id != null)
                    {
                        MatchCollection matchCollection = XSSFVMLDrawing.ptrn_shapeId.Matches(id);
                        if (matchCollection.Count > 0)
                        {
                            this._shapeId = Math.Max(this._shapeId, int.Parse(matchCollection[0].Groups[1].Value));
                        }
                    }
                    this._items.Add((object)ctShape);
                }
                else
                {
                    this._items.Add((object)selectNode);
                }
            }
        }
Exemplo n.º 19
0
        public void TestConstructor()
        {
            CommentsTable sheetComments = new CommentsTable();
            Assert.IsNotNull(sheetComments.GetCTComments().commentList);
            Assert.IsNotNull(sheetComments.GetCTComments().authors);
            Assert.AreEqual(1, sheetComments.GetCTComments().authors.SizeOfAuthorArray());
            Assert.AreEqual(1, sheetComments.GetNumberOfAuthors());

            CT_Comment ctComment = sheetComments.CreateComment();
            CT_Shape vmlShape = new CT_Shape();

            XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape);
            Assert.AreEqual(null, comment.String.String);
            Assert.AreEqual(0, comment.Row);
            Assert.AreEqual(0, comment.Column);
            Assert.AreEqual("", comment.Author);
            Assert.AreEqual(false, comment.Visible);
        }
Exemplo n.º 20
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.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));
                }
            }
        }
Exemplo n.º 21
0
        public void GetSetRow()
        {
            CommentsTable  sheetComments = new CommentsTable();
            XSSFVMLDrawing vml           = new XSSFVMLDrawing();
            CT_Comment     ctComment     = sheetComments.NewComment("A1");
            CT_Shape       vmlShape      = vml.newCommentShape();

            XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape);

            comment.Row = (1);
            Assert.AreEqual(1, comment.Row);
            Assert.AreEqual(1, new CellReference(ctComment.@ref).Row);
            Assert.AreEqual(1, vmlShape.GetClientDataArray(0).GetRowArray(0));

            comment.Row = (5);
            Assert.AreEqual(5, comment.Row);
            Assert.AreEqual(5, new CellReference(ctComment.@ref).Row);
            Assert.AreEqual(5, vmlShape.GetClientDataArray(0).GetRowArray(0));
        }
Exemplo n.º 22
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.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);
        }
Exemplo n.º 23
0
        public void GetSetCol()
        {
            CommentsTable  sheetComments = new CommentsTable();
            XSSFVMLDrawing vml           = new XSSFVMLDrawing();
            CT_Comment     ctComment     = sheetComments.NewComment(CellAddress.A1);
            CT_Shape       vmlShape      = vml.newCommentShape();

            XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape);

            comment.Column = (1);
            Assert.AreEqual(1, comment.Column);
            Assert.AreEqual(1, new CellReference(ctComment.@ref).Col);
            Assert.AreEqual(1, vmlShape.GetClientDataArray(0).GetColumnArray(0));

            comment.Column = (5);
            Assert.AreEqual(5, comment.Column);
            Assert.AreEqual(5, new CellReference(ctComment.@ref).Col);
            Assert.AreEqual(5, vmlShape.GetClientDataArray(0).GetColumnArray(0));
        }
Exemplo n.º 24
0
        public void Constructor()
        {
            CommentsTable sheetComments = new CommentsTable();

            Assert.IsNotNull(sheetComments.GetCTComments().commentList);
            Assert.IsNotNull(sheetComments.GetCTComments().authors);
            Assert.AreEqual(1, sheetComments.GetCTComments().authors.SizeOfAuthorArray());
            Assert.AreEqual(1, sheetComments.GetNumberOfAuthors());

            CT_Comment ctComment = sheetComments.NewComment("A1");
            CT_Shape   vmlShape  = new CT_Shape();

            XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape);

            Assert.AreEqual(null, comment.String.String);
            Assert.AreEqual(0, comment.Row);
            Assert.AreEqual(0, comment.Column);
            Assert.AreEqual("", comment.Author);
            Assert.AreEqual(false, comment.Visible);
        }
Exemplo n.º 25
0
        /**
         * Creates a new XSSFComment, associated with a given
         *  low level comment object.
         */
        public XSSFComment(CommentsTable comments, CT_Comment comment, CT_Shape vmlShape)
        {
            _comment  = comment;
            _comments = comments;
            _vmlShape = vmlShape;

            // we potentially need to adjust the column/row information in the shape
            // the same way as we do in setRow()/setColumn()
            if (vmlShape != null && vmlShape.SizeOfClientDataArray() > 0)
            {
                CellReference ref1       = new CellReference(comment.@ref);
                CT_ClientData clientData = vmlShape.GetClientDataArray(0);
                clientData.SetRowArray(0, ref1.Row);

                clientData.SetColumnArray(0, ref1.Col);

                // There is a very odd xmlbeans bug when changing the row
                //  arrays which can lead to corrupt pointer
                // This call seems to fix them again... See bug #50795
                //vmlShape.GetClientDataList().ToString();
            }
        }
Exemplo n.º 26
0
 internal CT_Shape FindCommentShape(int row, int col)
 {
     foreach (object obj in this._items)
     {
         if (obj is CT_Shape)
         {
             CT_Shape ctShape = (CT_Shape)obj;
             if (ctShape.sizeOfClientDataArray() > 0)
             {
                 CT_ClientData clientDataArray = ctShape.GetClientDataArray(0);
                 if (clientDataArray.ObjectType == ST_ObjectType.Note)
                 {
                     int rowArray    = clientDataArray.GetRowArray(0);
                     int columnArray = clientDataArray.GetColumnArray(0);
                     if (rowArray == row && columnArray == col)
                     {
                         return(ctShape);
                     }
                 }
             }
         }
     }
     return((CT_Shape)null);
 }
Exemplo n.º 27
0
 /**
  * Find a shape with ClientData of type "NOTE" and the specified row and column
  *
  * @return the comment shape or <code>null</code>
  */
 internal CT_Shape FindCommentShape(int row, int col)
 {
     foreach (object itm in _items)
     {
         if (itm is CT_Shape)
         {
             CT_Shape sh = (CT_Shape)itm;
             if (sh.sizeOfClientDataArray() > 0)
             {
                 CT_ClientData cldata = sh.GetClientDataArray(0);
                 if (cldata.ObjectType == ST_ObjectType.Note)
                 {
                     int crow = cldata.GetRowArray(0);
                     int ccol = cldata.GetColumnArray(0);
                     if (crow == row && ccol == col)
                     {
                         return(sh);
                     }
                 }
             }
         }
     }
     return(null);
 }
Exemplo n.º 28
0
        /**
         * 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);
        }
Exemplo n.º 29
0
        internal void Read(Stream is1)
        {
            XmlDocument doc = new XmlDocument();

            //InflaterInputStream iis = (InflaterInputStream)is1;
            StreamReader sr   = new StreamReader(is1);
            string       data = sr.ReadToEnd();

            //Stream vmlsm = new EvilUnclosedBRFixingInputStream(is1); --TODO:: add later

            doc.LoadXml(
                data.Replace("<br>", "")
                );

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

            nsmgr.AddNamespace("o", "urn:schemas-microsoft-com:office:office");
            nsmgr.AddNamespace("x", "urn:schemas-microsoft-com:office:excel");
            nsmgr.AddNamespace("v", "urn:schemas-microsoft-com:vml");
            _items = new ArrayList();
            XmlNodeList nodes = doc.SelectNodes("/xml/*", nsmgr);

            foreach (XmlNode nd in nodes)
            {
                string xmltext = nd.OuterXml;
                if (nd.LocalName == QNAME_SHAPE_LAYOUT.Name)
                {
                    CT_ShapeLayout sl = CT_ShapeLayout.Parse(nd, nsmgr);
                    _items.Add(sl);
                }
                else if (nd.LocalName == QNAME_SHAPE_TYPE.Name)
                {
                    CT_Shapetype st = CT_Shapetype.Parse(nd, nsmgr);
                    _items.Add(st);
                    _shapeTypeId = st.id;
                }
                else if (nd.LocalName == QNAME_SHAPE.Name)
                {
                    CT_Shape shape = CT_Shape.Parse(nd, nsmgr);
                    String   id    = shape.id;
                    if (id != null)
                    {
                        MatchCollection m = ptrn_shapeId.Matches(id);
                        if (m.Count > 0)
                        {
                            _shapeId = Math.Max(_shapeId, int.Parse(m[0].Groups[1].Value));
                        }
                    }
                    _items.Add(shape);
                }
                else
                {
                    /// How to port following java code??
                    //Document doc2;
                    //try
                    //{
                    //    InputSource is2 = new InputSource(new StringReader(obj.xmlText()));
                    //    doc2 = DocumentHelper.readDocument(is2);
                    //}
                    //catch (SAXException e)
                    //{
                    //    throw new XmlException(e.getMessage(), e);
                    //}

                    _items.Add(nd);
                }
            }
        }
Exemplo n.º 30
0
 /**
  * Creates a new XSSFComment, associated with a given
  *  low level comment object.
  */
 public XSSFComment(CommentsTable comments, CT_Comment comment, CT_Shape vmlShape)
 {
     _comment = comment;
     _comments = comments;
     _vmlShape = vmlShape;
 }
Exemplo n.º 31
0
        internal CT_Shape newCommentShape()
        {
            CT_Shape shape = new CT_Shape();

            shape.id = "_x0000_s" + (++_shapeId);
            shape.type ="#_x0000_t" + (++_shapeTypeId);
            shape.style="position:absolute; visibility:hidden";
            shape.fillcolor = ("#ffffe1");
            shape.insetmode = (ST_InsetMode.auto);
            shape.AddNewFill().color=("#ffffe1");
            CT_Shadow shadow = shape.AddNewShadow();
            shadow.on= ST_TrueFalse.t;
            shadow.color = "black";
            shadow.obscured = ST_TrueFalse.t;
            shape.AddNewPath().connecttype = (ST_ConnectType.none);
            shape.AddNewTextbox().style = ("mso-direction-alt:auto");
            CT_ClientData cldata = shape.AddNewClientData();
            cldata.ObjectType=ST_ObjectType.Note;
            cldata.AddNewMoveWithCells();
            cldata.AddNewSizeWithCells();
            cldata.AddNewAnchor("1, 15, 0, 2, 3, 15, 3, 16");
            cldata.AddNewAutoFill(ST_TrueFalseBlank.@false);
            cldata.AddNewRow(0);
            cldata.AddNewColumn(0);
            _items.Add(shape);

            return shape;
        }
Exemplo n.º 32
0
        public void TestBug58175()
        {
            IWorkbook wb = new SXSSFWorkbook();

            try
            {
                ISheet sheet = wb.CreateSheet();
                IRow   row   = sheet.CreateRow(1);
                ICell  cell  = row.CreateCell(3);
                cell.SetCellValue("F4");
                ICreationHelper factory = wb.GetCreationHelper();
                // When the comment box is visible, have it show in a 1x3 space
                IClientAnchor anchor = factory.CreateClientAnchor();
                anchor.Col1 = (cell.ColumnIndex);
                anchor.Col2 = (cell.ColumnIndex + 1);
                anchor.Row1 = (row.RowNum);
                anchor.Row2 = (row.RowNum + 3);
                XSSFClientAnchor ca = (XSSFClientAnchor)anchor;
                // create comments and vmlDrawing parts if they don't exist
                CommentsTable comments = (((SXSSFWorkbook)wb).XssfWorkbook
                                          .GetSheetAt(0) as XSSFSheet).GetCommentsTable(true);
                XSSFVMLDrawing vml = (((SXSSFWorkbook)wb).XssfWorkbook
                                      .GetSheetAt(0) as XSSFSheet).GetVMLDrawing(true);
                CT_Shape vmlShape1 = vml.newCommentShape();
                if (ca.IsSet())
                {
                    String position = ca.Col1 + ", 0, " + ca.Row1
                                      + ", 0, " + ca.Col2 + ", 0, " + ca.Row2
                                      + ", 0";
                    vmlShape1.GetClientDataArray(0).SetAnchorArray(0, position);
                }
                // create the comment in two different ways and verify that there is no difference

                XSSFComment shape1 = new XSSFComment(comments, comments.NewComment(CellAddress.A1), vmlShape1);
                shape1.Column = (ca.Col1);
                shape1.Row    = (ca.Row1);
                CT_Shape vmlShape2 = vml.newCommentShape();
                if (ca.IsSet())
                {
                    String position = ca.Col1 + ", 0, " + ca.Row1
                                      + ", 0, " + ca.Col2 + ", 0, " + ca.Row2
                                      + ", 0";
                    vmlShape2.GetClientDataArray(0).SetAnchorArray(0, position);
                }

                CellAddress ref1   = new CellAddress(ca.Row1, ca.Col1);
                XSSFComment shape2 = new XSSFComment(comments, comments.NewComment(ref1), vmlShape2);

                Assert.AreEqual(shape1.Author, shape2.Author);
                Assert.AreEqual(shape1.ClientAnchor, shape2.ClientAnchor);
                Assert.AreEqual(shape1.Column, shape2.Column);
                Assert.AreEqual(shape1.Row, shape2.Row);
                Assert.AreEqual(shape1.GetCTComment().ToString(), shape2.GetCTComment().ToString());
                Assert.AreEqual(shape1.GetCTComment().@ref, shape2.GetCTComment().@ref);

                /*CommentsTable table1 = shape1.CommentsTable;
                 * CommentsTable table2 = shape2.CommentsTable;
                 * Assert.AreEqual(table1.CTComments.toString(), table2.CTComments.toString());
                 * Assert.AreEqual(table1.NumberOfComments, table2.NumberOfComments);
                 * Assert.AreEqual(table1.Relations, table2.Relations);*/

                Assert.AreEqual(vmlShape1.ToString().Replace("_x0000_s\\d+", "_x0000_s0000"),
                                vmlShape2.ToString().Replace("_x0000_s\\d+", "_x0000_s0000"),
                                "The vmlShapes should have equal content afterwards");
            }
            finally
            {
                wb.Close();
            }
        }
Exemplo n.º 33
0
 internal XSSFTextBox(XSSFDrawing drawing, CT_Shape ctShape)
     : base(drawing, ctShape)
 {
 }
Exemplo n.º 34
0
        internal CT_Shape newCheckboxShape()
        {
            int checkboxShapeType = 201;
            // correct layout and shape type
            foreach (Object item in _items)
            {
                if (item.GetType() == typeof(CT_ShapeLayout))
                {
                    CT_ShapeLayout layout = (CT_ShapeLayout)item;
                }
                else if (item.GetType() == typeof(CT_Shapetype))
                {
                    CT_Shapetype shapetype = (CT_Shapetype)item;
                    shapetype.id = "_x0000_t" + checkboxShapeType;
                    shapetype.coordsize = "21600,21600";
                    shapetype.spt = checkboxShapeType;
                    shapetype.path2 = ("m,l,21600r21600,l21600,xe");
                    shapetype.stroke.joinstyle = ST_StrokeJoinStyle.miter;
                    shapetype.path = null;
                    CT_Path path = shapetype.AddNewPath();
                    path.shadowok = OpenXmlFormats.Vml.ST_TrueFalse.f;
                    path.extrusionok = OpenXmlFormats.Vml.ST_TrueFalse.f;
                    path.strokeok = OpenXmlFormats.Vml.ST_TrueFalse.f;
                    path.fillok = OpenXmlFormats.Vml.ST_TrueFalse.f;
                    path.connecttype = ST_ConnectType.rect;
                    
                    CT_Lock ctlock = shapetype.AddNewLock();
                    ctlock.ext = ST_Ext.edit;
                    ctlock.shapetype = OpenXmlFormats.Vml.Office.ST_TrueFalse.t;
                }
            }

            // actual checkbox
            CT_Shape shape = new CT_Shape();

            shape.id = "_x0000_s" + (++_shapeId);
            shape.type = "#_x0000_t" + checkboxShapeType;
            shape.style = "position:absolute;margin-left:202.5pt;margin-top:169.5pt;width:87.75pt;height:19.5pt;z-index:1;mso-wrap-style:tight";
            shape.fill = null;
            shape.filled = OpenXmlFormats.Vml.ST_TrueFalse.f;
            shape.fillcolor = ("window [65]");
            shape.stroked = OpenXmlFormats.Vml.ST_TrueFalse.f;
            shape.strokecolor = "windowText [64]";
            
            
            shape.insetmode = (ST_InsetMode.auto);
            shape.textbox = new CT_Textbox();
            shape.textbox.ItemXml = "<div style='text-align:left'>" +
                                        "<font face=\"Segoe UI\" size=\"160\" color=\"auto\">" +
                                          "Kontrollkästchen 1" +
                                        "</font>" +
                                    "</div>";

            shape.@lock = new CT_Lock();
            [email protected] = ST_Ext.edit;
            [email protected] = OpenXmlFormats.Vml.Office.ST_TrueFalse.t;


            CT_ClientData cldata = shape.AddNewClientData();
            cldata.ObjectType = ST_ObjectType.Checkbox;
            cldata.AddNewSizeWithCells();
            cldata.AddNewAnchor("1, 15, 0, 2, 3, 15, 3, 16");
            cldata.AddNewAutoFill(ST_TrueFalseBlank.@false);
            cldata.AddNewAutoLine(ST_TrueFalseBlank.@false);
            cldata.AddNewTextVAlign("Center");
            _items.Add(shape);

            return shape;
        }