Exemplo n.º 1
0
        public void TestClearShapes()
        {
            HSSFWorkbook   wb        = new HSSFWorkbook();
            HSSFSheet      sheet     = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch  patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;
            HSSFShapeGroup group     = patriarch.CreateGroup(new HSSFClientAnchor());

            group.CreateShape(new HSSFChildAnchor());
            group.CreateShape(new HSSFChildAnchor());

            EscherAggregate agg = HSSFTestHelper.GetEscherAggregate(patriarch);

            Assert.AreEqual(agg.GetShapeToObjMapping().Count, 5);
            Assert.AreEqual(agg.TailRecords.Count, 0);
            Assert.AreEqual(group.Children.Count, 2);

            group.Clear();

            Assert.AreEqual(agg.GetShapeToObjMapping().Count, 1);
            Assert.AreEqual(agg.TailRecords.Count, 0);
            Assert.AreEqual(group.Children.Count, 0);

            wb        = HSSFTestDataSamples.WriteOutAndReadBack(wb);
            sheet     = wb.GetSheetAt(0) as HSSFSheet;
            patriarch = sheet.DrawingPatriarch as HSSFPatriarch;

            group = (HSSFShapeGroup)patriarch.Children[(0)];

            Assert.AreEqual(agg.GetShapeToObjMapping().Count, 1);
            Assert.AreEqual(agg.TailRecords.Count, 0);
            Assert.AreEqual(group.Children.Count, 0);
        }
Exemplo n.º 2
0
        private static void DrawSheet3(ISheet sheet3)
        {
            // Create a row and size one of the cells reasonably large
            IRow row = sheet3.CreateRow(2);

            row.HeightInPoints = 140;
            row.CreateCell(1);
            sheet3.SetColumnWidth(2, 9000);

            // Create the Drawing patriarch.  This is the top level container for
            // all shapes. This will clear out any existing shapes for that sheet.
            HSSFPatriarch patriarch = (HSSFPatriarch)sheet3.CreateDrawingPatriarch();

            // Create a shape group.
            HSSFShapeGroup group = patriarch.CreateGroup(
                new HSSFClientAnchor(0, 0, 900, 200, (short)2, 2, (short)2, 2));

            // Create a couple of lines in the group.
            HSSFSimpleShape shape1 = group.CreateShape(new HSSFChildAnchor(3, 3, 500, 500));

            shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE);
            ((HSSFChildAnchor)shape1.Anchor).SetAnchor((short)3, 3, 500, 500);
            HSSFSimpleShape shape2 = group.CreateShape(new HSSFChildAnchor((short)1, 200, 400, 600));

            shape2.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE);
        }
Exemplo n.º 3
0
        public void TestAddShapesToGroup()
        {
            HSSFWorkbook wb = new HSSFWorkbook();

            // create a sheet with a text box
            HSSFSheet     sheet     = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;

            HSSFShapeGroup group = patriarch.CreateGroup(new HSSFClientAnchor());
            int            index = wb.AddPicture(new byte[] { 1, 2, 3 }, PictureType.JPEG);

            group.CreatePicture(new HSSFChildAnchor(), index);
            HSSFPolygon polygon = group.CreatePolygon(new HSSFChildAnchor());

            polygon.SetPoints(new int[] { 1, 100, 1 }, new int[] { 1, 50, 100 });
            group.CreateTextbox(new HSSFChildAnchor());
            group.CreateShape(new HSSFChildAnchor());

            wb        = HSSFTestDataSamples.WriteOutAndReadBack(wb);
            sheet     = wb.GetSheetAt(0) as HSSFSheet;
            patriarch = sheet.DrawingPatriarch as HSSFPatriarch;
            Assert.AreEqual(1, patriarch.Children.Count);

            Assert.IsTrue(patriarch.Children[0] is HSSFShapeGroup);
            group = (HSSFShapeGroup)patriarch.Children[0];

            Assert.AreEqual(group.Children.Count, 4);

            Assert.IsTrue(group.Children[0] is HSSFPicture);
            Assert.IsTrue(group.Children[1] is HSSFPolygon);
            Assert.IsTrue(group.Children[2] is HSSFTextbox);
            Assert.IsTrue(group.Children[3] is HSSFSimpleShape);

            HSSFShapeGroup group2 = patriarch.CreateGroup(new HSSFClientAnchor());

            index = wb.AddPicture(new byte[] { 2, 2, 2 }, PictureType.JPEG);
            group2.CreatePicture(new HSSFChildAnchor(), index);
            polygon = group2.CreatePolygon(new HSSFChildAnchor());
            polygon.SetPoints(new int[] { 1, 100, 1 }, new int[] { 1, 50, 100 });
            group2.CreateTextbox(new HSSFChildAnchor());
            group2.CreateShape(new HSSFChildAnchor());
            group2.CreateShape(new HSSFChildAnchor());

            wb        = HSSFTestDataSamples.WriteOutAndReadBack(wb);
            sheet     = wb.GetSheetAt(0) as HSSFSheet;
            patriarch = sheet.DrawingPatriarch as HSSFPatriarch;
            Assert.AreEqual(2, patriarch.Children.Count);

            group = (HSSFShapeGroup)patriarch.Children[1];

            Assert.AreEqual(group.Children.Count, 5);

            Assert.IsTrue(group.Children[0] is HSSFPicture);
            Assert.IsTrue(group.Children[1] is HSSFPolygon);
            Assert.IsTrue(group.Children[2] is HSSFTextbox);
            Assert.IsTrue(group.Children[3] is HSSFSimpleShape);
            Assert.IsTrue(group.Children[4] is HSSFSimpleShape);

            int shapeid = group.ShapeId;
        }