Пример #1
0
        public void TestGetPatriarch()
        {
            HSSFWorkbook wb = new HSSFWorkbook();
            HSSFSheet    sh = wb.CreateSheet() as HSSFSheet;

            Assert.IsNull(sh.DrawingPatriarch);

            HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch;

            Assert.IsNotNull(patriarch);
            patriarch.CreateSimpleShape(new HSSFClientAnchor());
            patriarch.CreateSimpleShape(new HSSFClientAnchor());

            Assert.AreSame(patriarch, sh.DrawingPatriarch);

            EscherAggregate agg = patriarch.GetBoundAggregate();

            EscherDgRecord dg     = agg.GetEscherContainer().GetChildById(EscherDgRecord.RECORD_ID) as EscherDgRecord;
            int            lastId = dg.LastMSOSPID;

            Assert.AreSame(patriarch, sh.CreateDrawingPatriarch());

            wb        = HSSFTestDataSamples.WriteOutAndReadBack(wb);
            sh        = wb.GetSheetAt(0) as HSSFSheet;
            patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch;
            dg        = patriarch.GetBoundAggregate().GetEscherContainer().GetChildById(EscherDgRecord.RECORD_ID) as EscherDgRecord;

            Assert.AreEqual(lastId, dg.LastMSOSPID);
        }
Пример #2
0
 private static void DrawLinesToCenter(HSSFPatriarch patriarch)
 {
     // Draw some lines from and to the corners
     {
         HSSFClientAnchor a1 = new HSSFClientAnchor();
         a1.SetAnchor((short)2, 2, 0, 0, (short)2, 2, 512, 128);
         HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1);
         shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE);
     }
     {
         HSSFClientAnchor a1 = new HSSFClientAnchor();
         a1.SetAnchor((short)2, 2, 512, 128, (short)2, 2, 1023, 0);
         HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1);
         shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE);
     }
     {
         HSSFClientAnchor a1 = new HSSFClientAnchor();
         a1.SetAnchor((short)1, 1, 0, 0, (short)1, 1, 512, 100);
         HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1);
         shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE);
     }
     {
         HSSFClientAnchor a1 = new HSSFClientAnchor();
         a1.SetAnchor((short)1, 1, 512, 100, (short)1, 1, 1023, 0);
         HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1);
         shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE);
     }
 }
Пример #3
0
        public void TestBug45312()
        {
            HSSFWorkbook wb = new HSSFWorkbook();

            try
            {
                HSSFSheet     sheet     = wb.CreateSheet() as HSSFSheet;
                HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;

                {
                    HSSFClientAnchor a1 = new HSSFClientAnchor();
                    a1.SetAnchor((short)1, 1, 0, 0, (short)1, 1, 512, 100);
                    HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1);
                    shape1.ShapeType = (/*setter*/ HSSFSimpleShape.OBJECT_TYPE_LINE);
                }

                {
                    HSSFClientAnchor a1 = new HSSFClientAnchor();
                    //setAnchor method is wrong??
                    a1.SetAnchor((short)1, 1, 512, 0, (short)1, 1, 1023, 100);
                    HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1);
                    shape1.FlipVertical = (true);
                    shape1.ShapeType    = (/*setter*/ HSSFSimpleShape.OBJECT_TYPE_LINE);
                }

                {
                    HSSFClientAnchor a1 = new HSSFClientAnchor();
                    a1.SetAnchor((short)2, 2, 0, 0, (short)2, 2, 512, 100);
                    HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1);
                    shape1.ShapeType = (/*setter*/ HSSFSimpleShape.OBJECT_TYPE_LINE);
                }
                {
                    HSSFClientAnchor a1 = new HSSFClientAnchor();
                    a1.SetAnchor((short)2, 2, 0, 100, (short)2, 2, 512, 200);
                    HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1);
                    shape1.FlipHorizontal = (/*setter*/ true);
                    shape1.ShapeType      = (/*setter*/ HSSFSimpleShape.OBJECT_TYPE_LINE);
                }

                /*OutputStream stream = new FileOutputStream("/tmp/45312.xls");
                 * try {
                 *  wb.Write(stream);
                 * } finally {
                 *  stream.Close();
                 * }*/

                CheckWorkbookBack(wb);
            }
            finally
            {
                //wb.Close();
            }
        }
Пример #4
0
        public void TestRotation()
        {
            HSSFWorkbook  wb        = new HSSFWorkbook();
            HSSFSheet     sheet     = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;

            HSSFSimpleShape rectangle = patriarch.CreateSimpleShape(new HSSFClientAnchor(0, 0, 100, 100, (short)0, 0, (short)5, 5));

            rectangle.ShapeType = HSSFSimpleShape.OBJECT_TYPE_RECTANGLE;

            Assert.AreEqual(rectangle.RotationDegree, 0);
            rectangle.RotationDegree = (short)45;
            Assert.AreEqual(rectangle.RotationDegree, 45);
            rectangle.IsFlipHorizontal = true;

            wb        = HSSFTestDataSamples.WriteOutAndReadBack(wb);
            sheet     = wb.GetSheetAt(0) as HSSFSheet;
            patriarch = sheet.DrawingPatriarch as HSSFPatriarch;
            rectangle = (HSSFSimpleShape)patriarch.Children[0];
            Assert.AreEqual(rectangle.RotationDegree, 45);
            rectangle.RotationDegree = (short)30;
            Assert.AreEqual(rectangle.RotationDegree, 30);

            patriarch.SetCoordinates(0, 0, 10, 10);
            rectangle.String = new HSSFRichTextString("1234");
        }
Пример #5
0
        public void TestShapeContainerImplementsIterable()
        {
            HSSFWorkbook  wb        = new HSSFWorkbook();
            HSSFSheet     sheet     = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;

            patriarch.CreateSimpleShape(new HSSFClientAnchor());
            patriarch.CreateSimpleShape(new HSSFClientAnchor());

            int i = 2;

            foreach (HSSFShape shape in patriarch)
            {
                i--;
            }
            Assert.AreEqual(i, 0);
        }
Пример #6
0
        /// <summary>
        /// Hàm vẽ một line trên file excel
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="col1">Cột chứa điểm đầu của line</param>
        /// <param name="row1">Dòng chứa điểm đầu của line</param>
        /// <param name="x1">Tọa độ X điểm đầu của line (Tọa độ x trong 1 cell có giá trị từ 0 - 1023)</param>
        /// <param name="y1">Tọa độ Y điểm đầu của line (Tọa độ Y trong 1 cell có giá trị từ 0 - 255)</param>
        /// <param name="col2">Cột chứa điểm cuối của line</param>
        /// <param name="row2">Dòng chứa điểm cuối của line</param>
        /// <param name="x2">Tọa độ X điểm cuối của line</param>
        /// <param name="y2">Tọa độ Y điểm cuối của line</param>
        /// <modified>
        /// Author      Date        comment
        /// TuanVM      15/07/2012  Tạo mới
        /// </modified>
        public static void DrawLine(this ISheet sheet, short col1, int row1, int x1, int y1, short col2, int row2, int x2, int y2)
        {
            HSSFPatriarch    patriarch = (HSSFPatriarch)sheet.CreateDrawingPatriarch();
            HSSFClientAnchor a1        = new HSSFClientAnchor();

            a1.SetAnchor(col1, row1, x1, y1, col2, row2, x2, y2);
            HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1);

            shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE);
        }
Пример #7
0
        private static void DrawGrid(HSSFPatriarch patriarch)
        {
            // This Draws a grid of lines.  Since the coordinates space fixed at
            // 1024 by 256 we use a ratio to get a reasonably square grids.

            double xRatio = 3.22;
            double yRatio = 0.6711;

            int x1 = 000;
            int y1 = 000;
            int x2 = 000;
            int y2 = 200;

            for (int i = 0; i < 20; i++)
            {
                HSSFClientAnchor a2 = new HSSFClientAnchor();
                a2.SetAnchor((short)2, 2, (int)(x1 * xRatio), (int)(y1 * yRatio),
                             (short)2, 2, (int)(x2 * xRatio), (int)(y2 * yRatio));
                HSSFSimpleShape shape2 = patriarch.CreateSimpleShape(a2);
                shape2.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE);

                x1 += 10;
                x2 += 10;
            }

            x1 = 000;
            y1 = 000;
            x2 = 200;
            y2 = 000;
            for (int i = 0; i < 20; i++)
            {
                HSSFClientAnchor a2 = new HSSFClientAnchor();
                a2.SetAnchor((short)2, 2, (int)(x1 * xRatio), (int)(y1 * yRatio),
                             (short)2, 2, (int)(x2 * xRatio), (int)(y2 * yRatio));
                HSSFSimpleShape shape2 = patriarch.CreateSimpleShape(a2);
                shape2.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE);

                y1 += 10;
                y2 += 10;
            }
        }
Пример #8
0
 private static void DrawOval(HSSFPatriarch patriarch)
 {
     // Create an oval and style to taste.
     HSSFClientAnchor a = new HSSFClientAnchor();
     a.SetAnchor((short)2, 2, 20, 20, (short)2, 2, 190, 80);
     HSSFSimpleShape s = patriarch.CreateSimpleShape(a);
     s.ShapeType = HSSFSimpleShape.OBJECT_TYPE_OVAL;
     s.SetLineStyleColor(10, 10, 10);
     s.SetFillColor(90, 10, 200);
     s.LineWidth = HSSFShape.LINEWIDTH_ONE_PT * 3;
     s.LineStyle = LineStyle.DotSys;
 }
Пример #9
0
        public void TestTextForSimpleShape()
        {
            HSSFWorkbook  wb1       = new HSSFWorkbook();
            HSSFSheet     sheet     = wb1.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;

            HSSFSimpleShape shape = patriarch.CreateSimpleShape(new HSSFClientAnchor());

            shape.ShapeType = HSSFSimpleShape.OBJECT_TYPE_RECTANGLE;

            EscherAggregate agg = HSSFTestHelper.GetEscherAggregate(patriarch);

            Assert.AreEqual(agg.GetShapeToObjMapping().Count, 2);

            HSSFWorkbook wb2 = HSSFTestDataSamples.WriteOutAndReadBack(wb1);

            wb1.Close();
            sheet     = wb2.GetSheetAt(0) as HSSFSheet;
            patriarch = sheet.DrawingPatriarch as HSSFPatriarch;

            shape = (HSSFSimpleShape)patriarch.Children[0];

            agg = HSSFTestHelper.GetEscherAggregate(patriarch);
            Assert.AreEqual(agg.GetShapeToObjMapping().Count, 2);

            shape.String = new HSSFRichTextString("string1");
            Assert.AreEqual(shape.String.String, "string1");

            Assert.IsNotNull(HSSFTestHelper.GetEscherContainer(shape).GetChildById(EscherTextboxRecord.RECORD_ID));
            Assert.AreEqual(agg.GetShapeToObjMapping().Count, 2);

            HSSFWorkbook wb3 = HSSFTestDataSamples.WriteOutAndReadBack(wb2);

            wb2.Close();

            HSSFWorkbook wb4 = HSSFTestDataSamples.WriteOutAndReadBack(wb3);

            wb3.Close();

            sheet     = wb4.GetSheetAt(0) as HSSFSheet;
            patriarch = sheet.DrawingPatriarch as HSSFPatriarch;

            shape = (HSSFSimpleShape)patriarch.Children[0];

            Assert.IsNotNull(HSSFTestHelper.GetTextObjRecord(shape));
            Assert.AreEqual(shape.String.String, "string1");
            Assert.IsNotNull(HSSFTestHelper.GetEscherContainer(shape).GetChildById(EscherTextboxRecord.RECORD_ID));
            Assert.AreEqual(agg.GetShapeToObjMapping().Count, 2);

            wb4.Close();
        }
Пример #10
0
        public void TestShapeIds()
        {
            HSSFWorkbook  wb1        = new HSSFWorkbook();
            HSSFSheet     sheet1     = wb1.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch1 = sheet1.CreateDrawingPatriarch() as HSSFPatriarch;

            for (int i = 0; i < 2; i++)
            {
                patriarch1.CreateSimpleShape(new HSSFClientAnchor());
            }

            HSSFWorkbook wb2 = HSSFTestDataSamples.WriteOutAndReadBack(wb1);

            wb1.Close();

            sheet1     = wb2.GetSheetAt(0) as HSSFSheet;
            patriarch1 = sheet1.DrawingPatriarch as HSSFPatriarch;

            EscherAggregate agg1 = HSSFTestHelper.GetEscherAggregate(patriarch1);
            // last shape ID cached in EscherDgRecord
            EscherDgRecord dg1 =
                agg1.GetEscherContainer().GetChildById(EscherDgRecord.RECORD_ID) as EscherDgRecord;

            Assert.AreEqual(1026, dg1.LastMSOSPID);

            // iterate over shapes and check shapeId
            EscherContainerRecord spgrContainer =
                agg1.GetEscherContainer().ChildContainers[0] as EscherContainerRecord;

            // root spContainer + 2 spContainers for shapes
            Assert.AreEqual(3, spgrContainer.ChildRecords.Count);

            EscherSpRecord sp0 =
                ((EscherContainerRecord)spgrContainer.GetChild(0)).GetChildById(EscherSpRecord.RECORD_ID) as EscherSpRecord;

            Assert.AreEqual(1024, sp0.ShapeId);

            EscherSpRecord sp1 =
                ((EscherContainerRecord)spgrContainer.GetChild(1)).GetChildById(EscherSpRecord.RECORD_ID) as EscherSpRecord;

            Assert.AreEqual(1025, sp1.ShapeId);

            EscherSpRecord sp2 =
                ((EscherContainerRecord)spgrContainer.GetChild(2)).GetChildById(EscherSpRecord.RECORD_ID) as EscherSpRecord;

            Assert.AreEqual(1026, sp2.ShapeId);
            wb2.Close();
        }
Пример #11
0
        public void TestShapeFlip()
        {
            HSSFWorkbook  wb1       = new HSSFWorkbook();
            HSSFSheet     sheet     = wb1.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;

            HSSFSimpleShape rectangle = patriarch.CreateSimpleShape(new HSSFClientAnchor());

            rectangle.ShapeType = HSSFSimpleShape.OBJECT_TYPE_RECTANGLE;

            Assert.AreEqual(rectangle.IsFlipVertical, false);
            Assert.AreEqual(rectangle.IsFlipHorizontal, false);

            rectangle.IsFlipVertical = true;
            Assert.AreEqual(rectangle.IsFlipVertical, true);
            rectangle.IsFlipHorizontal = true;
            Assert.AreEqual(rectangle.IsFlipHorizontal, true);

            HSSFWorkbook wb2 = HSSFTestDataSamples.WriteOutAndReadBack(wb1);

            wb1.Close();
            sheet     = wb2.GetSheetAt(0) as HSSFSheet;
            patriarch = sheet.DrawingPatriarch as HSSFPatriarch;

            rectangle = (HSSFSimpleShape)patriarch.Children[0];

            Assert.AreEqual(rectangle.IsFlipHorizontal, true);
            rectangle.IsFlipHorizontal = false;
            Assert.AreEqual(rectangle.IsFlipHorizontal, false);

            Assert.AreEqual(rectangle.IsFlipVertical, true);
            rectangle.IsFlipVertical = false;
            Assert.AreEqual(rectangle.IsFlipVertical, false);

            HSSFWorkbook wb3 = HSSFTestDataSamples.WriteOutAndReadBack(wb2);

            wb2.Close();
            sheet     = wb3.GetSheetAt(0) as HSSFSheet;
            patriarch = sheet.DrawingPatriarch as HSSFPatriarch;

            rectangle = (HSSFSimpleShape)patriarch.Children[0];

            Assert.AreEqual(rectangle.IsFlipVertical, false);
            Assert.AreEqual(rectangle.IsFlipHorizontal, false);

            wb3.Close();
        }
Пример #12
0
        public void TestInitState()
        {
            HSSFWorkbook  wb        = new HSSFWorkbook();
            HSSFSheet     sh        = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch;

            EscherAggregate agg = HSSFTestHelper.GetEscherAggregate(patriarch);

            Assert.AreEqual(agg.TailRecords.Count, 0);

            HSSFComment comment = patriarch.CreateCellComment(new HSSFClientAnchor()) as HSSFComment;

            Assert.AreEqual(agg.TailRecords.Count, 1);

            HSSFSimpleShape shape = patriarch.CreateSimpleShape(new HSSFClientAnchor());

            Assert.AreEqual(comment.GetOptRecord().EscherProperties.Count, 10);
        }
Пример #13
0
        public void TestShapeEscherMustHaveAnchorRecord()
        {
            HSSFWorkbook wb    = new HSSFWorkbook();
            HSSFSheet    sheet = wb.CreateSheet() as HSSFSheet;

            HSSFPatriarch    drawing = sheet.CreateDrawingPatriarch() as HSSFPatriarch;
            HSSFClientAnchor anchor  = new HSSFClientAnchor(10, 10, 200, 200, (short)2, 2, (short)15, 15);

            anchor.AnchorType = (2);

            HSSFSimpleShape rectangle = drawing.CreateSimpleShape(anchor);

            rectangle.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);

            rectangle.Anchor = (anchor);

            Assert.IsNotNull(HSSFTestHelper.GetEscherAnchor(anchor));
            Assert.IsNotNull(HSSFTestHelper.GetEscherContainer(rectangle));
            Assert.IsTrue(HSSFTestHelper.GetEscherAnchor(anchor).Equals(HSSFTestHelper.GetEscherContainer(rectangle).GetChildById(EscherClientAnchorRecord.RECORD_ID)));
        }
Пример #14
0
 private static void DrawManyLines(HSSFPatriarch patriarch)
 {
     // Draw bunch of lines
     int x1 = 100;
     int y1 = 100;
     int x2 = 800;
     int y2 = 200;
     int color = 0;
     for (int i = 0; i < 10; i++)
     {
         HSSFClientAnchor a2 = new HSSFClientAnchor();
         a2.SetAnchor((short)2, 2, x1, y1, (short)2, 2, x2, y2);
         HSSFSimpleShape shape2 = patriarch.CreateSimpleShape(a2);
         shape2.ShapeType = HSSFSimpleShape.OBJECT_TYPE_LINE;
         shape2.LineStyleColor = color;
         y1 -= 10;
         y2 -= 10;
         color += 30;
     }
 }
Пример #15
0
        /// <summary>
        /// Hàm vẽ một line căn vào giữa của 2 cột trên sheet
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="col1">Cột chứa điểm bắt đầu của line</param>
        /// <param name="row">Dòng chứa điểm bắt đầu của line</param>
        /// <param name="x">Tọa độ x của điểm bắt đầu (Tọa độ x trong 1 cell có giá trị từ 0 - 1023)</param>
        /// <param name="y">Tọa độ y của điểm bắt đầu (Tọa độ Y trong 1 cell có giá trị từ 0 - 255)</param>
        /// <param name="col2"></param>
        /// <modified>
        /// Author      Date        comment
        /// TuanVM      15/07/2012  Tạo mới
        /// </modified>
        public static void DrawLinesToCenter(this ISheet sheet, short col1, int row, int x, int y, short col2)
        {
            HSSFPatriarch patriarch = (HSSFPatriarch)sheet.CreateDrawingPatriarch();

            HSSFClientAnchor a1 = new HSSFClientAnchor();

            if (col2 == col1)
            {
                a1.SetAnchor(col1, row, x, y, col2, row, 1024 - x, y);
            }
            else
            {
                int col1Width = sheet.GetColumnWidth(col1);
                int col2Width = sheet.GetColumnWidth(col2);

                a1.SetAnchor(col1, row, x, y, col2, row, 1024 - x * col1Width / col2Width, y);
            }
            HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1);

            shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE);
        }
Пример #16
0
        private static void DrawSheet1(ISheet sheet1)
        {
            // Create a row and size one of the cells reasonably large.
            IRow row = sheet1.CreateRow(2);
            row.Height = ((short)2800);
            row.CreateCell(1);
            sheet1.SetColumnWidth(2, 9000);

            // Create the Drawing patriarch.  This is the top level container for
            // all shapes.
            HSSFPatriarch patriarch = (HSSFPatriarch)sheet1.CreateDrawingPatriarch();

            // Draw some lines and an oval.
            DrawLinesToCenter(patriarch);
            DrawManyLines(patriarch);
            DrawOval(patriarch);
            DrawPolygon(patriarch);

            // Draw a rectangle.
            HSSFSimpleShape rect = patriarch.CreateSimpleShape(new HSSFClientAnchor(100, 100, 900, 200, (short)0, 0, (short)0, 0));
            rect.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
        }
Пример #17
0
        public void TestRemoveShapes()
        {
            HSSFWorkbook  wb        = new HSSFWorkbook();
            HSSFSheet     sheet     = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;

            HSSFSimpleShape rectangle = patriarch.CreateSimpleShape(new HSSFClientAnchor());

            rectangle.ShapeType = HSSFSimpleShape.OBJECT_TYPE_RECTANGLE;

            int idx = wb.AddPicture(new byte[] { 1, 2, 3 }, PictureType.JPEG);

            patriarch.CreatePicture(new HSSFClientAnchor(), idx);

            patriarch.CreateCellComment(new HSSFClientAnchor());

            HSSFPolygon polygon = patriarch.CreatePolygon(new HSSFClientAnchor());

            polygon.SetPoints(new int[] { 1, 2 }, new int[] { 2, 3 });

            patriarch.CreateTextbox(new HSSFClientAnchor());

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

            group.CreateTextbox(new HSSFChildAnchor());
            group.CreatePicture(new HSSFChildAnchor(), idx);

            Assert.AreEqual(patriarch.Children.Count, 6);
            Assert.AreEqual(group.Children.Count, 2);

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 12);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1);

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

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 12);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1);

            Assert.AreEqual(patriarch.Children.Count, 6);

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

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 10);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1);

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

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 10);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1);

            group = (HSSFShapeGroup)patriarch.Children[(5)];
            patriarch.RemoveShape(group);

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 8);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1);

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

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 8);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1);
            Assert.AreEqual(patriarch.Children.Count, 5);

            HSSFShape shape = patriarch.Children[0];

            patriarch.RemoveShape(shape);

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 6);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1);
            Assert.AreEqual(patriarch.Children.Count, 4);

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

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 6);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1);
            Assert.AreEqual(patriarch.Children.Count, 4);

            HSSFPicture picture = (HSSFPicture)patriarch.Children[0];

            patriarch.RemoveShape(picture);

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 5);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1);
            Assert.AreEqual(patriarch.Children.Count, 3);

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

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 5);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1);
            Assert.AreEqual(patriarch.Children.Count, 3);

            HSSFComment comment = (HSSFComment)patriarch.Children[0];

            patriarch.RemoveShape(comment);

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 3);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0);
            Assert.AreEqual(patriarch.Children.Count, 2);

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

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 3);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0);
            Assert.AreEqual(patriarch.Children.Count, 2);

            polygon = (HSSFPolygon)patriarch.Children[0];
            patriarch.RemoveShape(polygon);

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 2);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0);
            Assert.AreEqual(patriarch.Children.Count, 1);

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

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 2);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0);
            Assert.AreEqual(patriarch.Children.Count, 1);

            HSSFTextbox textbox = (HSSFTextbox)patriarch.Children[0];

            patriarch.RemoveShape(textbox);

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 0);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0);
            Assert.AreEqual(patriarch.Children.Count, 0);

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

            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 0);
            Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0);
            Assert.AreEqual(patriarch.Children.Count, 0);
        }
Пример #18
0
        /**
         * create a rectangle, save the workbook, read back and verify that all shape properties are there
         */
        public void TestReadWriteRectangle()
        {
            HSSFWorkbook wb    = new HSSFWorkbook();
            HSSFSheet    sheet = wb.CreateSheet() as HSSFSheet;

            HSSFPatriarch    drawing = sheet.CreateDrawingPatriarch() as HSSFPatriarch;
            HSSFClientAnchor anchor  = new HSSFClientAnchor(10, 10, 50, 50, (short)2, 2, (short)4, 4);

            anchor.AnchorType = (AnchorType)(2);
            Assert.AreEqual(anchor.AnchorType, 2);

            HSSFSimpleShape rectangle = drawing.CreateSimpleShape(anchor);

            rectangle.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
            rectangle.LineWidth = (10000);
            rectangle.FillColor = (777);
            Assert.AreEqual(rectangle.FillColor, 777);
            Assert.AreEqual(10000, rectangle.LineWidth);
            rectangle.LineStyle = (LineStyle)(10);
            Assert.AreEqual(10, rectangle.LineStyle);
            Assert.AreEqual(rectangle.WrapText, HSSFSimpleShape.WRAP_SQUARE);
            rectangle.LineStyleColor = (1111);
            rectangle.IsNoFill       = (true);
            rectangle.WrapText       = (HSSFSimpleShape.WRAP_NONE);
            rectangle.String         = (new HSSFRichTextString("teeeest"));
            Assert.AreEqual(rectangle.LineStyleColor, 1111);
            Assert.AreEqual(((EscherSimpleProperty)((EscherOptRecord)HSSFTestHelper.GetEscherContainer(rectangle).GetChildById(EscherOptRecord.RECORD_ID))
                             .Lookup(EscherProperties.TEXT__TEXTID)).PropertyValue, "teeeest".GetHashCode());
            Assert.AreEqual(rectangle.IsNoFill, true);
            Assert.AreEqual(rectangle.WrapText, HSSFSimpleShape.WRAP_NONE);
            Assert.AreEqual(rectangle.String.String, "teeeest");

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

            HSSFSimpleShape rectangle2 =
                (HSSFSimpleShape)drawing.Children[0];

            Assert.AreEqual(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE,
                            rectangle2.ShapeType);
            Assert.AreEqual(10000, rectangle2.LineWidth);
            Assert.AreEqual(10, (int)rectangle2.LineStyle);
            Assert.AreEqual(anchor, rectangle2.Anchor);
            Assert.AreEqual(rectangle2.LineStyleColor, 1111);
            Assert.AreEqual(rectangle2.FillColor, 777);
            Assert.AreEqual(rectangle2.IsNoFill, true);
            Assert.AreEqual(rectangle2.String.String, "teeeest");
            Assert.AreEqual(rectangle.WrapText, HSSFSimpleShape.WRAP_NONE);

            rectangle2.FillColor      = (3333);
            rectangle2.LineStyle      = (LineStyle)(9);
            rectangle2.LineStyleColor = (4444);
            rectangle2.IsNoFill       = (false);
            rectangle2.LineWidth      = (77);
            rectangle2.Anchor.Dx1     = 2;
            rectangle2.Anchor.Dx2     = 3;
            rectangle2.Anchor.Dy1     = (4);
            rectangle2.Anchor.Dy2     = (5);
            rectangle.WrapText        = (HSSFSimpleShape.WRAP_BY_POINTS);
            rectangle2.String         = (new HSSFRichTextString("test22"));

            wb      = HSSFTestDataSamples.WriteOutAndReadBack(wb);
            sheet   = wb.GetSheetAt(0) as HSSFSheet;
            drawing = sheet.DrawingPatriarch as HSSFPatriarch;
            Assert.AreEqual(1, drawing.Children.Count);
            rectangle2 = (HSSFSimpleShape)drawing.Children[0];
            Assert.AreEqual(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, rectangle2.ShapeType);
            Assert.AreEqual(rectangle.WrapText, HSSFSimpleShape.WRAP_BY_POINTS);
            Assert.AreEqual(77, rectangle2.LineWidth);
            Assert.AreEqual(9, rectangle2.LineStyle);
            Assert.AreEqual(rectangle2.LineStyleColor, 4444);
            Assert.AreEqual(rectangle2.FillColor, 3333);
            Assert.AreEqual(rectangle2.Anchor.Dx1, 2);
            Assert.AreEqual(rectangle2.Anchor.Dx2, 3);
            Assert.AreEqual(rectangle2.Anchor.Dy1, 4);
            Assert.AreEqual(rectangle2.Anchor.Dy2, 5);
            Assert.AreEqual(rectangle2.IsNoFill, false);
            Assert.AreEqual(rectangle2.String.String, "test22");

            HSSFSimpleShape rect3 = drawing.CreateSimpleShape(new HSSFClientAnchor());

            rect3.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
            wb = HSSFTestDataSamples.WriteOutAndReadBack(wb);

            drawing = (wb.GetSheetAt(0) as HSSFSheet).DrawingPatriarch as HSSFPatriarch;
            Assert.AreEqual(drawing.Children.Count, 2);
        }
Пример #19
0
        public void TestReallyEmbedSomething()
        {
            HSSFWorkbook  wb        = new HSSFWorkbook();
            ISheet        sheet     = wb.CreateSheet();
            HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;

            byte[]          pictureData = HSSFTestDataSamples.GetTestDataFileContent("logoKarmokar4.png");
            byte[]          picturePPT  = POIDataSamples.GetSlideShowInstance().ReadFile("clock.jpg");
            int             imgIdx      = wb.AddPicture(pictureData, PictureType.PNG);
            POIFSFileSystem pptPoifs    = GetSamplePPT();
            int             pptIdx      = wb.AddOlePackage(pptPoifs, "Sample-PPT", "sample.ppt", "sample.ppt");
            POIFSFileSystem xlsPoifs    = GetSampleXLS();
            int             imgPPT      = wb.AddPicture(picturePPT, PictureType.JPEG);
            int             xlsIdx      = wb.AddOlePackage(xlsPoifs, "Sample-XLS", "sample.xls", "sample.xls");
            int             txtIdx      = wb.AddOlePackage(GetSampleTXT(), "Sample-TXT", "sample.txt", "sample.txt");

            int rowoffset = 5;
            int coloffset = 5;

            ICreationHelper  ch     = wb.GetCreationHelper();
            HSSFClientAnchor anchor = (HSSFClientAnchor)ch.CreateClientAnchor();

            anchor.SetAnchor((short)(2 + coloffset), 1 + rowoffset, 0, 0, (short)(3 + coloffset), 5 + rowoffset, 0, 0);
            anchor.AnchorType = (/*setter*/ AnchorType.DontMoveAndResize);

            patriarch.CreateObjectData(anchor, pptIdx, imgPPT);

            anchor = (HSSFClientAnchor)ch.CreateClientAnchor();
            anchor.SetAnchor((short)(5 + coloffset), 1 + rowoffset, 0, 0, (short)(6 + coloffset), 5 + rowoffset, 0, 0);
            anchor.AnchorType = (/*setter*/ AnchorType.DontMoveAndResize);

            patriarch.CreateObjectData(anchor, xlsIdx, imgIdx);

            anchor = (HSSFClientAnchor)ch.CreateClientAnchor();
            anchor.SetAnchor((short)(3 + coloffset), 10 + rowoffset, 0, 0, (short)(5 + coloffset), 11 + rowoffset, 0, 0);
            anchor.AnchorType = (/*setter*/ AnchorType.DontMoveAndResize);

            patriarch.CreateObjectData(anchor, txtIdx, imgIdx);

            anchor = (HSSFClientAnchor)ch.CreateClientAnchor();
            anchor.SetAnchor((short)(1 + coloffset), -2 + rowoffset, 0, 0, (short)(7 + coloffset), 14 + rowoffset, 0, 0);
            anchor.AnchorType = (/*setter*/ AnchorType.DontMoveAndResize);

            HSSFSimpleShape circle = patriarch.CreateSimpleShape(anchor);

            circle.ShapeType = (/*setter*/ HSSFSimpleShape.OBJECT_TYPE_OVAL);
            circle.IsNoFill  = (/*setter*/ true);

            if (false)
            {
                FileStream fos = new FileStream("embed.xls", FileMode.Create);
                wb.Write(fos);
                fos.Close();
            }

            wb = HSSFTestDataSamples.WriteOutAndReadBack(wb as HSSFWorkbook);

            MemoryStream   bos   = new MemoryStream();
            HSSFObjectData od    = wb.GetAllEmbeddedObjects()[0];
            Ole10Native    ole10 = Ole10Native.CreateFromEmbeddedOleObject((DirectoryNode)od.GetDirectory());

            bos = new MemoryStream();
            pptPoifs.WriteFileSystem(bos);
            Assert.IsTrue(Arrays.Equals(ole10.DataBuffer, bos.ToArray()));

            od    = wb.GetAllEmbeddedObjects()[1];
            ole10 = Ole10Native.CreateFromEmbeddedOleObject((DirectoryNode)od.GetDirectory());
            bos   = new MemoryStream();
            xlsPoifs.WriteFileSystem(bos);
            Assert.IsTrue(Arrays.Equals(ole10.DataBuffer, bos.ToArray()));

            od    = wb.GetAllEmbeddedObjects()[2];
            ole10 = Ole10Native.CreateFromEmbeddedOleObject((DirectoryNode)od.GetDirectory());
            Assert.IsTrue(Arrays.Equals(ole10.DataBuffer, GetSampleTXT()));
        }