Example #1
0
        public void TestCorrectOrderInOptRecord()
        {
            HSSFWorkbook  wb        = new HSSFWorkbook();
            HSSFSheet     sheet     = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;

            HSSFTextbox     textbox = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox;
            EscherOptRecord opt     = HSSFTestHelper.GetOptRecord(textbox);

            String opt1Str = opt.ToXml();

            textbox.FillColor = textbox.FillColor;
            EscherContainerRecord Container = HSSFTestHelper.GetEscherContainer(textbox);
            EscherOptRecord       optRecord = Container.GetChildById(EscherOptRecord.RECORD_ID) as EscherOptRecord;

            Assert.AreEqual(opt1Str, optRecord.ToXml());
            textbox.LineStyle = textbox.LineStyle;
            Assert.AreEqual(opt1Str, optRecord.ToXml());
            textbox.LineWidth = textbox.LineWidth;
            Assert.AreEqual(opt1Str, optRecord.ToXml());
            textbox.LineStyleColor = textbox.LineStyleColor;
            Assert.AreEqual(opt1Str, optRecord.ToXml());

            wb.Close();
        }
Example #2
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();
        }
Example #3
0
        public void TestOpt()
        {
            HSSFWorkbook wb = new HSSFWorkbook();

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

            HSSFTextbox     textbox = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox;
            EscherOptRecord opt1    = HSSFTestHelper.GetOptRecord(textbox);
            EscherOptRecord opt2    = HSSFTestHelper.GetEscherContainer(textbox).GetChildById(EscherOptRecord.RECORD_ID) as EscherOptRecord;

            Assert.AreSame(opt1, opt2);
        }
Example #4
0
        public void TestCorrectOrderInSpContainer()
        {
            HSSFWorkbook  wb      = HSSFTestDataSamples.OpenSampleWorkbook("drawings.xls");
            HSSFSheet     sheet   = wb.GetSheet("pictures") as HSSFSheet;
            HSSFPatriarch drawing = sheet.DrawingPatriarch as HSSFPatriarch;

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

            Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(0).RecordId, EscherSpRecord.RECORD_ID);
            Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(1).RecordId, EscherOptRecord.RECORD_ID);
            Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(2).RecordId, EscherClientAnchorRecord.RECORD_ID);
            Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(3).RecordId, EscherClientDataRecord.RECORD_ID);

            rectangle.Anchor = (new HSSFClientAnchor());

            Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(0).RecordId, EscherSpRecord.RECORD_ID);
            Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(1).RecordId, EscherOptRecord.RECORD_ID);
            Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(2).RecordId, EscherClientAnchorRecord.RECORD_ID);
            Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(3).RecordId, EscherClientDataRecord.RECORD_ID);
        }
Example #5
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)));
        }
Example #6
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);
        }