Esempio n. 1
0
        public void TestReadAnchors()
        {
            XSSFWorkbook wb      = new XSSFWorkbook();
            XSSFSheet    sheet   = wb.CreateSheet() as XSSFSheet;
            XSSFDrawing  Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;

            XSSFClientAnchor anchor1 = new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4);
            XSSFShape        shape1  = Drawing.CreateTextbox(anchor1) as XSSFShape;

            Assert.IsNotNull(shape1);

            XSSFClientAnchor anchor2 = new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 5);
            XSSFShape        shape2  = Drawing.CreateTextbox(anchor2) as XSSFShape;

            Assert.IsNotNull(shape2);

            int pictureIndex         = wb.AddPicture(new byte[] { }, XSSFWorkbook.PICTURE_TYPE_PNG);
            XSSFClientAnchor anchor3 = new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 6);
            XSSFShape        shape3  = Drawing.CreatePicture(anchor3, pictureIndex) as XSSFShape;

            Assert.IsNotNull(shape3);

            wb      = XSSFTestDataSamples.WriteOutAndReadBack(wb) as XSSFWorkbook;
            sheet   = wb.GetSheetAt(0) as XSSFSheet;
            Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;
            List <XSSFShape> shapes = Drawing.GetShapes();

            Assert.AreEqual(3, shapes.Count);
            Assert.AreEqual(shapes[0].GetAnchor(), anchor1);
            Assert.AreEqual(shapes[1].GetAnchor(), anchor2);
            Assert.AreEqual(shapes[2].GetAnchor(), anchor3);

            Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wb));
        }
Esempio n. 2
0
        /**
         *
         * @return list of shapes in this drawing
         */
        public List <XSSFShape> GetShapes()
        {
            List <XSSFShape> lst = new List <XSSFShape>();

            foreach (IEG_Anchor anchor in drawing.CellAnchors)
            {
                XSSFShape shape = null;
                if (anchor.picture != null)
                {
                    shape = new XSSFPicture(this, anchor.picture);
                }
                else if (anchor.connector != null)
                {
                    shape = new XSSFConnector(this, anchor.connector);
                }
                else if (anchor.groupShape != null)
                {
                    shape = new XSSFShapeGroup(this, anchor.groupShape);
                }
                else if (anchor.graphicFrame != null)
                {
                    shape = new XSSFGraphicFrame(this, anchor.graphicFrame);
                }
                else if (anchor.sp != null)
                {
                    shape = new XSSFSimpleShape(this, anchor.sp);
                }
                if (shape != null)
                {
                    shape.anchor = GetAnchorFromIEGAnchor(anchor);
                    lst.Add(shape);
                }
            }
            //foreach (XmlNode obj in xmldoc.SelectNodes("./*/*/*"))
            //{
            //    XSSFShape shape = null;
            //    if (obj.LocalName == "sp")
            //    {
            //        shape = new XSSFSimpleShape(this, obj);
            //    }
            //    else if (obj.LocalName == "pic")
            //    {
            //        shape = new XSSFPicture(this, obj);
            //    }
            //    else if (obj.LocalName == "cxnSp")
            //    {
            //        shape = new XSSFConnector(this, obj);
            //    }
            //    //    else if (obj is CT_GraphicalObjectFrame) shape = new XSSFGraphicFrame(this, (CT_GraphicalObjectFrame)obj);
            //    //    else if (obj is CT_GroupShape) shape = new XSSFShapeGroup(this, (CT_GroupShape)obj);
            //    if (shape != null)
            //    {
            //        shape.anchor = GetAnchorFromParent(obj);
            //        lst.Add(shape);
            //    }
            //}
            return(lst);
        }
Esempio n. 3
0
        public void TestClone()
        {
            XSSFWorkbook wb     = XSSFTestDataSamples.OpenSampleWorkbook("WithDrawing.xlsx");
            XSSFSheet    sheet1 = wb.GetSheetAt(0) as XSSFSheet;

            XSSFSheet sheet2 = wb.CloneSheet(0) as XSSFSheet;

            //the source sheet has one relationship and it is XSSFDrawing
            List <POIXMLDocumentPart> rels1 = sheet1.GetRelations();

            Assert.AreEqual(1, rels1.Count);
            Assert.IsTrue(rels1[(0)] is XSSFDrawing);

            List <POIXMLDocumentPart> rels2 = sheet2.GetRelations();

            Assert.AreEqual(1, rels2.Count);
            Assert.IsTrue(rels2[(0)] is XSSFDrawing);

            XSSFDrawing drawing1 = (XSSFDrawing)rels1[0];
            XSSFDrawing drawing2 = (XSSFDrawing)rels2[0];

            Assert.AreNotSame(drawing1, drawing2);  // Drawing2 is a clone of Drawing1

            List <XSSFShape> shapes1 = drawing1.GetShapes();
            List <XSSFShape> shapes2 = drawing2.GetShapes();

            Assert.AreEqual(shapes1.Count, shapes2.Count);

            for (int i = 0; i < shapes1.Count; i++)
            {
                XSSFShape sh1 = (XSSFShape)shapes1[(i)];
                XSSFShape sh2 = (XSSFShape)shapes2[i];

                Assert.IsTrue(sh1.GetType() == sh2.GetType());
                Assert.AreEqual(sh1.GetShapeProperties().ToString(), sh2.GetShapeProperties().ToString());
            }

            Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wb));
        }