Пример #1
0
 private static void DrawPolygon(HSSFPatriarch patriarch)
 {
     HSSFClientAnchor a = new HSSFClientAnchor();
     a.SetAnchor((short)2, 2, 0, 0, (short)3, 3, 1023, 255);
     HSSFShapeGroup g = patriarch.CreateGroup(a);
     g.SetCoordinates(0, 0, 200, 200);
     HSSFPolygon p1 = g.CreatePolygon(new HSSFChildAnchor(0, 0, 200, 200));
     p1.SetPolygonDrawArea(100, 100);
     p1.SetPoints(new int[] { 0, 90, 50 }, new int[] { 5, 5, 44 });
     p1.SetFillColor(0, 255, 0);
     HSSFPolygon p2 = g.CreatePolygon(new HSSFChildAnchor(20, 20, 200, 200));
     p2.SetPolygonDrawArea(200, 200);
     p2.SetPoints(new int[] { 120, 20, 150 }, new int[] { 105, 30, 195 });
     p2.SetFillColor(255, 0, 0);
 }
Пример #2
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;
        }