예제 #1
0
        private static void DrawSheet4(ISheet sheet4, HSSFWorkbook wb)
        {
            // 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)sheet4.CreateDrawingPatriarch();

            // Create a couple of textboxes
            HSSFTextbox textbox1 = (HSSFTextbox)patriarch.CreateTextbox(
                new HSSFClientAnchor(0, 0, 0, 0, (short)1, 1, (short)2, 2));

            textbox1.String = new HSSFRichTextString("This is a test");
            HSSFTextbox textbox2 = (HSSFTextbox)patriarch.CreateTextbox(
                new HSSFClientAnchor(0, 0, 900, 100, (short)3, 3, (short)3, 4));

            textbox2.String = new HSSFRichTextString("Woo");
            textbox2.SetFillColor(200, 0, 0);
            textbox2.LineStyle = LineStyle.DotGel;

            // Create third one with some fancy font styling.
            HSSFTextbox textbox3 = (HSSFTextbox)patriarch.CreateTextbox(
                new HSSFClientAnchor(0, 0, 900, 100, (short)4, 4, (short)5, 4 + 1));
            IFont font = wb.CreateFont();

            font.IsItalic  = true;
            font.Underline = (byte)FontUnderlineType.DOUBLE;
            HSSFRichTextString str = new HSSFRichTextString("Woo!!!");

            str.ApplyFont(2, 5, font);
            textbox3.String    = str;
            textbox3.FillColor = 0x08000030;
            textbox3.LineStyle = LineStyle.None; // no line around the textbox.
            textbox3.IsNoFill  = true;           // make it transparent
        }
예제 #2
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();
        }
예제 #3
0
        public void TestDrawString()
        {
            graphics.DrawString("This is a Test", 10, 10);
            HSSFTextbox t = (HSSFTextbox)escherGroupA.Children[0];

            Assert.AreEqual("This is a Test", t.String.String);
        }
예제 #4
0
        public void TestDrawString()
        {
            graphics.drawString("This is a Test", 10, 10);
            HSSFTextbox t = (HSSFTextbox)escherGroup.GetChildren()[0];

            Assert.AreEqual("This is a Test", t.String.String);

            // Check that with a valid font, it's still ok
            Font font = new Font("Forte", 12, FontStyle.Regular);

            graphics.SetFont(font);
            graphics.drawString("This is another Test", 10, 10);

            // And Test with ones that need the style appending
            font = new Font("dialog", 12, FontStyle.Regular);
            graphics.SetFont(font);
            graphics.drawString("This is another Test", 10, 10);

            font = new Font("dialog", 12, FontStyle.Bold);
            graphics.SetFont(font);
            graphics.drawString("This is another Test", 10, 10);

            // But with an invalid font, we get an exception
            font = new Font("IamAmadeUPfont", 22, FontStyle.Regular);
            graphics.SetFont(font);
            try
            {
                graphics.drawString("This is another Test", 10, 10);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }
        }
예제 #5
0
        public void TestAddTextToExistingFile()
        {
            HSSFWorkbook  wb        = new HSSFWorkbook();
            HSSFSheet     sh        = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch;
            HSSFTextbox   textbox   = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox;

            textbox.String = (new HSSFRichTextString("just for Test"));
            HSSFTextbox textbox2 = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox;

            textbox2.String = (new HSSFRichTextString("just for Test2"));

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

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

            Assert.AreEqual(patriarch.Children.Count, 2);
            HSSFTextbox text3 = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox;

            text3.String = (new HSSFRichTextString("text3"));
            Assert.AreEqual(patriarch.Children.Count, 3);

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

            Assert.AreEqual(patriarch.Children.Count, 3);
            Assert.AreEqual(((HSSFTextbox)patriarch.Children[0]).String.String, "just for Test");
            Assert.AreEqual(((HSSFTextbox)patriarch.Children[1]).String.String, "just for Test2");
            Assert.AreEqual(((HSSFTextbox)patriarch.Children[2]).String.String, "text3");
        }
예제 #6
0
        /// <summary>
        /// Creates the lowerlevel escher records for this shape.
        /// </summary>
        /// <param name="hssfShape">The HSSF shape.</param>
        /// <param name="shapeId">The shape id.</param>
        /// <returns></returns>
        private EscherContainerRecord CreateSpContainer(HSSFTextbox hssfShape, int shapeId)
        {
            HSSFTextbox shape = hssfShape;

            EscherContainerRecord  spContainer = new EscherContainerRecord();
            EscherSpRecord         sp          = new EscherSpRecord();
            EscherOptRecord        opt         = new EscherOptRecord();
            EscherRecord           anchor      = new EscherClientAnchorRecord();
            EscherClientDataRecord clientData  = new EscherClientDataRecord();

            escherTextbox = new EscherTextboxRecord();

            spContainer.RecordId = EscherContainerRecord.SP_CONTAINER;
            spContainer.Options  = (short)0x000F;
            sp.RecordId          = EscherSpRecord.RECORD_ID;
            sp.Options           = (short)((EscherAggregate.ST_TEXTBOX << 4) | 0x2);

            sp.ShapeId   = shapeId;
            sp.Flags     = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
            opt.RecordId = EscherOptRecord.RECORD_ID;
            //        opt.AddEscherProperty( new EscherBoolProperty( EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144 ) );
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTID, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTLEFT, shape.MarginLeft));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTRIGHT, shape.MarginRight));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTBOTTOM, shape.MarginBottom));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTTOP, shape.MarginTop));

            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__WRAPTEXT, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__ANCHORTEXT, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00080000));

            AddStandardOptions(shape, opt);
            HSSFAnchor userAnchor = shape.Anchor;

            //        if (userAnchor.IsHorizontallyFlipped())
            //            sp.Flags(sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ);
            //        if (userAnchor.IsVerticallyFlipped())
            //            sp.Flags(sp.Flags | EscherSpRecord.FLAG_FLIPVERT);
            anchor = CreateAnchor(userAnchor);
            clientData.RecordId    = EscherClientDataRecord.RECORD_ID;
            clientData.Options     = (short)0x0000;
            escherTextbox.RecordId = EscherTextboxRecord.RECORD_ID;
            escherTextbox.Options  = (short)0x0000;

            spContainer.AddChildRecord(sp);
            spContainer.AddChildRecord(opt);
            spContainer.AddChildRecord(anchor);
            spContainer.AddChildRecord(clientData);
            spContainer.AddChildRecord(escherTextbox);

            return(spContainer);
        }
예제 #7
0
        public void TestResultEqualsToAbstractShape()
        {
            HSSFWorkbook  wb           = new HSSFWorkbook();
            HSSFSheet     sh           = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch    = sh.CreateDrawingPatriarch() as HSSFPatriarch;
            HSSFTextbox   textbox      = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox;
            TextboxShape  textboxShape = HSSFTestModelHelper.CreateTextboxShape(1025, textbox);

            Assert.AreEqual(textbox.GetEscherContainer().ChildRecords.Count, 5);
            Assert.AreEqual(textboxShape.SpContainer.ChildRecords.Count, 5);

            //sp record
            byte[] expected = textboxShape.SpContainer.GetChild(0).Serialize();
            byte[] actual   = textbox.GetEscherContainer().GetChild(0).Serialize();

            Assert.AreEqual(expected.Length, actual.Length);
            Assert.IsTrue(Arrays.Equals(expected, actual));

            expected = textboxShape.SpContainer.GetChild(2).Serialize();
            actual   = textbox.GetEscherContainer().GetChild(2).Serialize();

            Assert.AreEqual(expected.Length, actual.Length);
            Assert.IsTrue(Arrays.Equals(expected, actual));

            expected = textboxShape.SpContainer.GetChild(3).Serialize();
            actual   = textbox.GetEscherContainer().GetChild(3).Serialize();

            Assert.AreEqual(expected.Length, actual.Length);
            Assert.IsTrue(Arrays.Equals(expected, actual));

            expected = textboxShape.SpContainer.GetChild(4).Serialize();
            actual   = textbox.GetEscherContainer().GetChild(4).Serialize();

            Assert.AreEqual(expected.Length, actual.Length);
            Assert.IsTrue(Arrays.Equals(expected, actual));

            ObjRecord obj      = textbox.GetObjRecord();
            ObjRecord objShape = textboxShape.ObjRecord;

            expected = obj.Serialize();
            actual   = objShape.Serialize();

            TextObjectRecord tor      = textbox.GetTextObjectRecord();
            TextObjectRecord torShape = textboxShape.TextObjectRecord;

            expected = tor.Serialize();
            actual   = torShape.Serialize();

            Assert.AreEqual(expected.Length, actual.Length);
            Assert.IsTrue(Arrays.Equals(expected, actual));
        }
예제 #8
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);
        }
예제 #9
0
        /// <summary>
        /// Textboxes also have an extra TXO record associated with them that most
        /// other shapes dont have.
        /// </summary>
        /// <param name="hssfShape">The HSSF shape.</param>
        /// <param name="shapeId">The shape id.</param>
        /// <returns></returns>
        private TextObjectRecord CreateTextObjectRecord(HSSFTextbox hssfShape, int shapeId)
        {
            HSSFTextbox shape = hssfShape;

            TextObjectRecord obj = new TextObjectRecord();

            obj.HorizontalTextAlignment = hssfShape.HorizontalAlignment;
            obj.VerticalTextAlignment   = hssfShape.VerticalAlignment;
            obj.IsTextLocked            = true;
            obj.TextOrientation         = TextOrientation.None;
            int frLength = (shape.String.NumFormattingRuns + 1) * 8;

            obj.Str = shape.String;

            return(obj);
        }
예제 #10
0
        public void TestAlignment()
        {
            HSSFWorkbook wb = new HSSFWorkbook();

            NPOI.SS.UserModel.ISheet sh1       = wb.CreateSheet();
            HSSFPatriarch            patriarch = sh1.CreateDrawingPatriarch() as HSSFPatriarch;

            HSSFTextbox        textbox = patriarch.CreateTextbox(new HSSFClientAnchor(0, 0, 0, 0, 1, 1, 6, 4)) as HSSFTextbox;
            HSSFRichTextString str     = new HSSFRichTextString("Hello, World");

            textbox.String = (str);
            textbox.HorizontalAlignment = HorizontalAlignment.Center;
            textbox.VerticalAlignment   = VerticalAlignment.Center;

            Assert.AreEqual(HorizontalAlignment.Center, textbox.HorizontalAlignment);
            Assert.AreEqual(VerticalAlignment.Center, textbox.VerticalAlignment);
        }
예제 #11
0
        public void TestAlignment()
        {
            HSSFWorkbook wb = new HSSFWorkbook();

            NPOI.SS.UserModel.ISheet sh1       = wb.CreateSheet();
            HSSFPatriarch            patriarch = sh1.CreateDrawingPatriarch() as HSSFPatriarch;

            HSSFTextbox        textbox = patriarch.CreateTextbox(new HSSFClientAnchor(0, 0, 0, 0, 1, 1, 6, 4)) as HSSFTextbox;
            HSSFRichTextString str     = new HSSFRichTextString("Hello, World");

            textbox.String = (str);
            textbox.HorizontalAlignment = (HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED);
            textbox.VerticalAlignment   = (HSSFTextbox.VERTICAL_ALIGNMENT_CENTER);

            Assert.AreEqual(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED, textbox.HorizontalAlignment);
            Assert.AreEqual(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER, textbox.VerticalAlignment);
        }
예제 #12
0
        public void TestExistingFileWithText()
        {
            HSSFWorkbook  wb      = HSSFTestDataSamples.OpenSampleWorkbook("drawings.xls");
            HSSFSheet     sheet   = wb.GetSheet("text") as HSSFSheet;
            HSSFPatriarch Drawing = sheet.DrawingPatriarch as HSSFPatriarch;

            Assert.AreEqual(1, Drawing.Children.Count);
            HSSFTextbox textbox = (HSSFTextbox)Drawing.Children[0];

            Assert.AreEqual(HorizontalTextAlignment.Left, textbox.HorizontalAlignment);
            Assert.AreEqual(VerticalTextAlignment.Top, textbox.VerticalAlignment);
            Assert.AreEqual(textbox.MarginTop, 0);
            Assert.AreEqual(textbox.MarginBottom, 3600000);
            Assert.AreEqual(textbox.MarginLeft, 3600000);
            Assert.AreEqual(textbox.MarginRight, 0);
            Assert.AreEqual(textbox.String.String, "teeeeesssstttt");
        }
예제 #13
0
        public void TestSetDeafultTextFormat()
        {
            HSSFWorkbook wb = new HSSFWorkbook();

            NPOI.SS.UserModel.ISheet sheet     = wb.CreateSheet();
            HSSFPatriarch            patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;

            HSSFTextbox        textbox1 = patriarch.CreateTextbox(new HSSFClientAnchor(0, 0, 0, 0, 1, 1, 3, 3)) as HSSFTextbox;
            HSSFRichTextString rt1      = new HSSFRichTextString("Hello, World!");

            Assert.AreEqual(0, rt1.NumFormattingRuns);
            textbox1.String = (rt1);

            HSSFRichTextString rt2 = (HSSFRichTextString)textbox1.String;

            Assert.AreEqual(1, rt2.NumFormattingRuns);
            Assert.AreEqual(HSSFRichTextString.NO_FONT, rt2.GetFontOfFormattingRun(0));
        }
예제 #14
0
파일: TestText.cs 프로젝트: zzy092/npoi
        public void TestResultEqualsToNonExistingAbstractShape()
        {
            HSSFWorkbook  wb        = new HSSFWorkbook();
            HSSFSheet     sh        = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch;
            HSSFTextbox   textbox   = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox;

            Assert.AreEqual(textbox.GetEscherContainer().ChildRecords.Count, 5);
            //sp record
            byte[] expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAFvEw/WBg4GBgZEFSHAxMAAA9gX7nhAAAAA=");
            byte[] actual   = textbox.GetEscherContainer().GetChild(0).Serialize();
            Assert.AreEqual(expected.Length, actual.Length);
            //assertArrayEquals(expected, actual)
            CollectionAssert.AreEqual(expected, actual);
            expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPggxIANAABK4+laGgAAAA==");
            actual   = textbox.GetEscherContainer().GetChild(2).Serialize();
            Assert.AreEqual(expected.Length, actual.Length);
            CollectionAssert.AreEqual(expected, actual);
            expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPzAAAQACl6c5QgAAAA=");
            actual   = textbox.GetEscherContainer().GetChild(3).Serialize();
            Assert.AreEqual(expected.Length, actual.Length);
            CollectionAssert.AreEqual(expected, actual);
            expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNg4P3AAAQA6pyIkQgAAAA=");
            actual   = textbox.GetEscherContainer().GetChild(4).Serialize();
            Assert.AreEqual(expected.Length, actual.Length);
            CollectionAssert.AreEqual(expected, actual);
            ObjRecord obj = textbox.GetObjRecord();

            expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAItlkGIQZRBiYGNgZBBMYEADAOdCLuweAAAA");
            actual   = obj.Serialize();
            Assert.AreEqual(expected.Length, actual.Length);
            CollectionAssert.AreEqual(expected, actual);

            TextObjectRecord tor = textbox.GetTextObjectRecord();

            expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAANvGKMQgxMSABgBGi8T+FgAAAA==");
            actual   = tor.Serialize();
            Assert.AreEqual(expected.Length, actual.Length);
            CollectionAssert.AreEqual(expected, actual);

            wb.Close();
        }
예제 #15
0
        /// <summary>
        /// Creates the lowerlevel OBJ records for this shape.
        /// </summary>
        /// <param name="hssfShape">The HSSF shape.</param>
        /// <param name="shapeId">The shape id.</param>
        /// <returns></returns>
        private ObjRecord CreateObjRecord(HSSFTextbox hssfShape, int shapeId)
        {
            HSSFShape shape = hssfShape;

            ObjRecord obj = new ObjRecord();
            CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();

            c.ObjectType  = (CommonObjectType)((HSSFSimpleShape)shape).ShapeType;
            c.ObjectId    = GetCmoObjectId(shapeId);
            c.IsLocked    = true;
            c.IsPrintable = true;
            c.IsAutoFill  = true;
            c.IsAutoline  = true;
            EndSubRecord e = new EndSubRecord();

            obj.AddSubRecord(c);
            obj.AddSubRecord(e);

            return(obj);
        }
예제 #16
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);
        }
예제 #17
0
        public void TestSetGetProperties()
        {
            HSSFWorkbook  wb        = new HSSFWorkbook();
            HSSFSheet     sh        = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch;
            HSSFTextbox   textbox   = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox;

            textbox.String = (new HSSFRichTextString("test"));
            Assert.AreEqual(textbox.String.String, "test");

            textbox.HorizontalAlignment = ((HorizontalTextAlignment)5);
            Assert.AreEqual((HorizontalTextAlignment)5, textbox.HorizontalAlignment);

            textbox.VerticalAlignment = ((VerticalTextAlignment)6);
            Assert.AreEqual((VerticalTextAlignment)6, textbox.VerticalAlignment);

            textbox.MarginBottom = (7);
            Assert.AreEqual(textbox.MarginBottom, 7);

            textbox.MarginLeft = (8);
            Assert.AreEqual(textbox.MarginLeft, 8);

            textbox.MarginRight = (9);
            Assert.AreEqual(textbox.MarginRight, 9);

            textbox.MarginTop = (10);
            Assert.AreEqual(textbox.MarginTop, 10);

            wb        = HSSFTestDataSamples.WriteOutAndReadBack(wb);
            sh        = wb.GetSheetAt(0) as HSSFSheet;
            patriarch = sh.DrawingPatriarch as HSSFPatriarch;
            textbox   = (HSSFTextbox)patriarch.Children[0];
            Assert.AreEqual(textbox.String.String, "test");
            Assert.AreEqual(textbox.HorizontalAlignment, (HorizontalTextAlignment)5);
            Assert.AreEqual(textbox.VerticalAlignment, (VerticalTextAlignment)6);
            Assert.AreEqual(textbox.MarginBottom, 7);
            Assert.AreEqual(textbox.MarginLeft, 8);
            Assert.AreEqual(textbox.MarginRight, 9);
            Assert.AreEqual(textbox.MarginTop, 10);

            textbox.String = (new HSSFRichTextString("test1"));
            textbox.HorizontalAlignment = HorizontalTextAlignment.Center;
            textbox.VerticalAlignment   = VerticalTextAlignment.Top;
            textbox.MarginBottom        = (71);
            textbox.MarginLeft          = (81);
            textbox.MarginRight         = (91);
            textbox.MarginTop           = (101);

            Assert.AreEqual(textbox.String.String, "test1");
            Assert.AreEqual(textbox.HorizontalAlignment, HorizontalTextAlignment.Center);
            Assert.AreEqual(textbox.VerticalAlignment, VerticalTextAlignment.Top);
            Assert.AreEqual(textbox.MarginBottom, 71);
            Assert.AreEqual(textbox.MarginLeft, 81);
            Assert.AreEqual(textbox.MarginRight, 91);
            Assert.AreEqual(textbox.MarginTop, 101);

            wb        = HSSFTestDataSamples.WriteOutAndReadBack(wb);
            sh        = wb.GetSheetAt(0) as HSSFSheet;
            patriarch = sh.DrawingPatriarch as HSSFPatriarch;
            textbox   = (HSSFTextbox)patriarch.Children[0];

            Assert.AreEqual(textbox.String.String, "test1");
            Assert.AreEqual(textbox.HorizontalAlignment, HorizontalTextAlignment.Center);
            Assert.AreEqual(textbox.VerticalAlignment, VerticalTextAlignment.Top);
            Assert.AreEqual(textbox.MarginBottom, 71);
            Assert.AreEqual(textbox.MarginLeft, 81);
            Assert.AreEqual(textbox.MarginRight, 91);
            Assert.AreEqual(textbox.MarginTop, 101);
        }
예제 #18
0
        /**
         * Converts the Records into UserModel
         *  objects on the bound HSSFPatriarch
         */
        public void ConvertRecordsToUserModel()
        {
            if (patriarch == null)
            {
                throw new InvalidOperationException("Must call SetPatriarch() first");
            }

            // The top level container ought to have
            //  the DgRecord and the container of one container
            //  per shape Group (patriach overall first)
            EscherContainerRecord topContainer =
                (EscherContainerRecord)GetEscherContainer();

            if (topContainer == null)
            {
                return;
            }
            topContainer = (EscherContainerRecord)
                           topContainer.ChildContainers[0];

            IList tcc = topContainer.ChildContainers;

            if (tcc.Count == 0)
            {
                throw new InvalidOperationException("No child escher containers at the point that should hold the patriach data, and one container per top level shape!");
            }

            // First up, Get the patriach position
            // This Is in the first EscherSpgrRecord, in
            //  the first container, with a EscherSRecord too
            EscherContainerRecord patriachContainer =
                (EscherContainerRecord)tcc[0];
            EscherSpgrRecord spgr = null;

            for (IEnumerator it = patriachContainer.ChildRecords.GetEnumerator(); it.MoveNext();)
            {
                EscherRecord r = (EscherRecord)it.Current;
                if (r is EscherSpgrRecord)
                {
                    spgr = (EscherSpgrRecord)r;
                    break;
                }
            }
            if (spgr != null)
            {
                patriarch.SetCoordinates(
                    spgr.RectX1, spgr.RectY1,
                    spgr.RectX2, spgr.RectY2
                    );
            }

            // Now Process the containers for each Group
            //  and objects
            for (int i = 1; i < tcc.Count; i++)
            {
                EscherContainerRecord shapeContainer =
                    (EscherContainerRecord)tcc[i];
                //Console.Error.WriteLine("\n\n*****\n\n");
                //Console.Error.WriteLine(shapeContainer);

                // Could be a Group, or a base object
                if (shapeContainer.ChildRecords.Count == 1 &&
                    shapeContainer.ChildContainers.Count == 1)
                {
                    // Group
                    HSSFShapeGroup group =
                        new HSSFShapeGroup(null, new HSSFClientAnchor());
                    patriarch.Children.Add(group);

                    EscherContainerRecord groupContainer =
                        (EscherContainerRecord)shapeContainer.GetChild(0);
                    ConvertRecordsToUserModel(groupContainer, group);
                }
                else if (shapeContainer.HasChildOfType(unchecked ((short)0xF00D)))
                {
                    // TextBox
                    HSSFTextbox box =
                        new HSSFTextbox(null, new HSSFClientAnchor());
                    patriarch.Children.Add(box);

                    ConvertRecordsToUserModel(shapeContainer, box);
                }
                else if (shapeContainer.HasChildOfType(unchecked ((short)0xF011)))
                {
                    // Not yet supporting EscherClientDataRecord stuff
                }
                else
                {
                    // Base level
                    ConvertRecordsToUserModel(shapeContainer, patriarch);
                }
            }

            // Now, clear any trace of what records make up
            //  the patriarch
            // Otherwise, everything will go horribly wrong
            //  when we try to Write out again....
            //      clearEscherRecords();
            drawingManager.GetDgg().FileIdClusters = new EscherDggRecord.FileIdCluster[0];

            // TODO: Support Converting our records
            //  back into shapes
            log.Log(POILogger.WARN, "Not Processing objects into Patriarch!");
        }
예제 #19
0
 /// <summary>
 /// Creates the low evel records for a textbox.
 /// </summary>
 /// <param name="hssfShape">The highlevel shape.</param>
 /// <param name="shapeId">The shape id to use for this shape.</param>
 public TextboxShape(HSSFTextbox hssfShape, int shapeId)
 {
     spContainer      = CreateSpContainer(hssfShape, shapeId);
     objRecord        = CreateObjRecord(hssfShape, shapeId);
     textObjectRecord = CreateTextObjectRecord(hssfShape, shapeId);
 }
예제 #20
0
        public void TestGetDataBackAgain()
        {
            HSSFSheet      s;
            HSSFShapeGroup s1;
            HSSFShapeGroup s2;

            patriarch.SetCoordinates(10, 20, 30, 40);

            MemoryStream baos = new MemoryStream();

            workbook.Write(baos);
            workbook = new HSSFWorkbook(new MemoryStream(baos.ToArray()));
            s        = (HSSFSheet)workbook.GetSheetAt(0);

            patriarch = (HSSFPatriarch)s.DrawingPatriarch;

            Assert.IsNotNull(patriarch);
            Assert.AreEqual(10, patriarch.X1);
            Assert.AreEqual(20, patriarch.Y1);
            Assert.AreEqual(30, patriarch.X2);
            Assert.AreEqual(40, patriarch.Y2);

            // Check the two groups too
            Assert.AreEqual(2, patriarch.CountOfAllChildren);
            Assert.IsTrue(patriarch.Children[0] is HSSFShapeGroup);
            Assert.IsTrue(patriarch.Children[1] is HSSFShapeGroup);

            s1 = (HSSFShapeGroup)patriarch.Children[0];
            s2 = (HSSFShapeGroup)patriarch.Children[1];

            Assert.AreEqual(0, s1.X1);
            Assert.AreEqual(0, s1.Y1);
            Assert.AreEqual(1023, s1.X2);
            Assert.AreEqual(255, s1.Y2);
            Assert.AreEqual(0, s2.X1);
            Assert.AreEqual(0, s2.Y1);
            Assert.AreEqual(1023, s2.X2);
            Assert.AreEqual(255, s2.Y2);

            Assert.AreEqual(0, s1.Anchor.Dx1);
            Assert.AreEqual(0, s1.Anchor.Dy1);
            Assert.AreEqual(1022, s1.Anchor.Dx2);
            Assert.AreEqual(255, s1.Anchor.Dy2);
            Assert.AreEqual(20, s2.Anchor.Dx1);
            Assert.AreEqual(30, s2.Anchor.Dy1);
            Assert.AreEqual(500, s2.Anchor.Dx2);
            Assert.AreEqual(200, s2.Anchor.Dy2);


            // Write and re-load once more, to Check that's ok
            baos = new MemoryStream();
            workbook.Write(baos);
            workbook  = new HSSFWorkbook(new MemoryStream(baos.ToArray()));
            s         = (HSSFSheet)workbook.GetSheetAt(0);
            patriarch = (HSSFPatriarch)s.DrawingPatriarch;

            Assert.IsNotNull(patriarch);
            Assert.AreEqual(10, patriarch.X1);
            Assert.AreEqual(20, patriarch.Y1);
            Assert.AreEqual(30, patriarch.X2);
            Assert.AreEqual(40, patriarch.Y2);

            // Check the two groups too
            Assert.AreEqual(2, patriarch.CountOfAllChildren);
            Assert.IsTrue(patriarch.Children[0] is HSSFShapeGroup);
            Assert.IsTrue(patriarch.Children[1] is HSSFShapeGroup);

            s1 = (HSSFShapeGroup)patriarch.Children[0];
            s2 = (HSSFShapeGroup)patriarch.Children[1];

            Assert.AreEqual(0, s1.X1);
            Assert.AreEqual(0, s1.Y1);
            Assert.AreEqual(1023, s1.X2);
            Assert.AreEqual(255, s1.Y2);
            Assert.AreEqual(0, s2.X1);
            Assert.AreEqual(0, s2.Y1);
            Assert.AreEqual(1023, s2.X2);
            Assert.AreEqual(255, s2.Y2);

            Assert.AreEqual(0, s1.Anchor.Dx1);
            Assert.AreEqual(0, s1.Anchor.Dy1);
            Assert.AreEqual(1022, s1.Anchor.Dx2);
            Assert.AreEqual(255, s1.Anchor.Dy2);
            Assert.AreEqual(20, s2.Anchor.Dx1);
            Assert.AreEqual(30, s2.Anchor.Dy1);
            Assert.AreEqual(500, s2.Anchor.Dx2);
            Assert.AreEqual(200, s2.Anchor.Dy2);

            // Change the positions of the first groups,
            //  but not of their anchors
            s1.SetCoordinates(2, 3, 1021, 242);

            baos = new MemoryStream();
            workbook.Write(baos);
            workbook  = new HSSFWorkbook(new MemoryStream(baos.ToArray()));
            s         = (HSSFSheet)workbook.GetSheetAt(0);
            patriarch = (HSSFPatriarch)s.DrawingPatriarch;

            Assert.IsNotNull(patriarch);
            Assert.AreEqual(10, patriarch.X1);
            Assert.AreEqual(20, patriarch.Y1);
            Assert.AreEqual(30, patriarch.X2);
            Assert.AreEqual(40, patriarch.Y2);

            // Check the two groups too
            Assert.AreEqual(2, patriarch.CountOfAllChildren);
            Assert.AreEqual(2, patriarch.Children.Count);
            Assert.IsTrue(patriarch.Children[0] is HSSFShapeGroup);
            Assert.IsTrue(patriarch.Children[1] is HSSFShapeGroup);

            s1 = (HSSFShapeGroup)patriarch.Children[0];
            s2 = (HSSFShapeGroup)patriarch.Children[1];

            Assert.AreEqual(2, s1.X1);
            Assert.AreEqual(3, s1.Y1);
            Assert.AreEqual(1021, s1.X2);
            Assert.AreEqual(242, s1.Y2);
            Assert.AreEqual(0, s2.X1);
            Assert.AreEqual(0, s2.Y1);
            Assert.AreEqual(1023, s2.X2);
            Assert.AreEqual(255, s2.Y2);

            Assert.AreEqual(0, s1.Anchor.Dx1);
            Assert.AreEqual(0, s1.Anchor.Dy1);
            Assert.AreEqual(1022, s1.Anchor.Dx2);
            Assert.AreEqual(255, s1.Anchor.Dy2);
            Assert.AreEqual(20, s2.Anchor.Dx1);
            Assert.AreEqual(30, s2.Anchor.Dy1);
            Assert.AreEqual(500, s2.Anchor.Dx2);
            Assert.AreEqual(200, s2.Anchor.Dy2);


            // Now Add some text to one group, and some more
            //  to the base, and Check we can get it back again
            HSSFTextbox tbox1 =
                patriarch.CreateTextbox(new HSSFClientAnchor(1, 2, 3, 4, (short)0, 0, (short)0, 0)) as HSSFTextbox;

            tbox1.String = (new HSSFRichTextString("I am text box 1"));
            HSSFTextbox tbox2 =
                s2.CreateTextbox(new HSSFChildAnchor(41, 42, 43, 44)) as HSSFTextbox;

            tbox2.String = (new HSSFRichTextString("This is text box 2"));

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


            baos = new MemoryStream();
            workbook.Write(baos);
            workbook = new HSSFWorkbook(new MemoryStream(baos.ToArray()));
            s        = (HSSFSheet)workbook.GetSheetAt(0);

            patriarch = (HSSFPatriarch)s.DrawingPatriarch;

            Assert.IsNotNull(patriarch);
            Assert.AreEqual(10, patriarch.X1);
            Assert.AreEqual(20, patriarch.Y1);
            Assert.AreEqual(30, patriarch.X2);
            Assert.AreEqual(40, patriarch.Y2);

            // Check the two groups and the text
            // Result of patriarch.countOfAllChildren() makes no sense:
            // Returns 4 for 2 empty groups + 1 TextBox.
            //Assert.AreEqual(3, patriarch.CountOfAllChildren);
            Assert.AreEqual(3, patriarch.Children.Count);

            // Should be two groups and a text
            Assert.IsTrue(patriarch.Children[0] is HSSFShapeGroup);
            Assert.IsTrue(patriarch.Children[1] is HSSFShapeGroup);
            Assert.IsTrue(patriarch.Children[2] is HSSFTextbox);


            s1    = (HSSFShapeGroup)patriarch.Children[0];
            tbox1 = (HSSFTextbox)patriarch.Children[2];

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

            Assert.AreEqual(2, s1.X1);
            Assert.AreEqual(3, s1.Y1);
            Assert.AreEqual(1021, s1.X2);
            Assert.AreEqual(242, s1.Y2);
            Assert.AreEqual(0, s2.X1);
            Assert.AreEqual(0, s2.Y1);
            Assert.AreEqual(1023, s2.X2);
            Assert.AreEqual(255, s2.Y2);

            Assert.AreEqual(0, s1.Anchor.Dx1);
            Assert.AreEqual(0, s1.Anchor.Dy1);
            Assert.AreEqual(1022, s1.Anchor.Dx2);
            Assert.AreEqual(255, s1.Anchor.Dy2);
            Assert.AreEqual(20, s2.Anchor.Dx1);
            Assert.AreEqual(30, s2.Anchor.Dy1);
            Assert.AreEqual(500, s2.Anchor.Dx2);
            Assert.AreEqual(200, s2.Anchor.Dy2);

            // Not working just yet
            //Assert.AreEqual("I am text box 1", tbox1.String.String);
        }
예제 #21
0
        /**
         * Converts the Records into UserModel
         *  objects on the bound HSSFPatriarch
         */
        public void ConvertRecordsToUserModel()
        {
            if (patriarch == null)
            {
                throw new InvalidOperationException("Must call SetPatriarch() first");
            }

            // The top level container ought to have
            //  the DgRecord and the container of one container
            //  per shape Group (patriach overall first)
            EscherContainerRecord topContainer =
                (EscherContainerRecord)GetEscherContainer();

            if (topContainer == null)
            {
                return;
            }
            topContainer = (EscherContainerRecord)
                           topContainer.ChildContainers[0];

            IList <EscherContainerRecord> tcc = topContainer.ChildContainers;

            if (tcc.Count == 0)
            {
                throw new InvalidOperationException("No child escher containers at the point that should hold the patriach data, and one container per top level shape!");
            }

            // First up, Get the patriach position
            // This Is in the first EscherSpgrRecord, in
            //  the first container, with a EscherSRecord too
            EscherContainerRecord patriachContainer =
                (EscherContainerRecord)tcc[0];
            EscherSpgrRecord spgr = null;

            for (IEnumerator it = patriachContainer.ChildRecords.GetEnumerator(); it.MoveNext();)
            {
                EscherRecord r = (EscherRecord)it.Current;
                if (r is EscherSpgrRecord)
                {
                    spgr = (EscherSpgrRecord)r;
                    break;
                }
            }
            if (spgr != null)
            {
                patriarch.SetCoordinates(
                    spgr.RectX1, spgr.RectY1,
                    spgr.RectX2, spgr.RectY2
                    );
            }

            // Now Process the containers for each Group
            //  and objects
            for (int i = 1; i < tcc.Count; i++)
            {
                EscherContainerRecord shapeContainer =
                    (EscherContainerRecord)tcc[i];
                //Console.Error.WriteLine("\n\n*****\n\n");
                //Console.Error.WriteLine(shapeContainer);

                // Could be a Group, or a base object
                if (shapeContainer.RecordId == EscherContainerRecord.SPGR_CONTAINER)
                {
                    if (shapeContainer.ChildRecords.Count > 0)
                    {
                        // Group
                        HSSFShapeGroup group =
                            new HSSFShapeGroup(null, new HSSFClientAnchor());
                        patriarch.Children.Add(group);

                        EscherContainerRecord groupContainer =
                            (EscherContainerRecord)shapeContainer.GetChild(0);
                        ConvertRecordsToUserModel(groupContainer, group);
                    }
                }
                else if (shapeContainer.RecordId == EscherContainerRecord.SP_CONTAINER)
                {
                    EscherSpRecord spRecord = shapeContainer.GetChildById(EscherSpRecord.RECORD_ID);
                    int            type     = spRecord.Options >> 4;

                    switch (type)
                    {
                    case ST_TEXTBOX:
                        // TextBox
                        HSSFTextbox box =
                            new HSSFTextbox(null, new HSSFClientAnchor());
                        patriarch.Children.Add(box);

                        ConvertRecordsToUserModel(shapeContainer, box);
                        break;

                    case ST_PICTUREFRAME:
                        // Duplicated from
                        // org.apache.poi.hslf.model.Picture.getPictureIndex()
                        EscherOptRecord      opt  = (EscherOptRecord)GetEscherChild(shapeContainer, EscherOptRecord.RECORD_ID);
                        EscherSimpleProperty prop = (EscherSimpleProperty)opt.Lookup(EscherProperties.BLIP__BLIPTODISPLAY);
                        if (prop != null)
                        {
                            int pictureIndex = prop.PropertyValue;
                            EscherClientAnchorRecord anchorRecord = (EscherClientAnchorRecord)GetEscherChild(shapeContainer, EscherClientAnchorRecord.RECORD_ID);
                            HSSFClientAnchor         anchor       = new HSSFClientAnchor();
                            anchor.Col1 = anchorRecord.Col1;
                            anchor.Col2 = anchorRecord.Col2;
                            anchor.Dx1  = anchorRecord.Dx1;
                            anchor.Dx2  = anchorRecord.Dx2;
                            anchor.Dy1  = anchorRecord.Dy1;
                            anchor.Dy2  = anchorRecord.Dy2;
                            anchor.Row1 = anchorRecord.Row1;
                            anchor.Row2 = anchorRecord.Row2;
                            HSSFPicture picture = new HSSFPicture(null, anchor);
                            picture.PictureIndex = pictureIndex;
                            patriarch.AddShape(picture);
                        }
                        break;
                    }
                }
                else
                {
                    // Base level
                    ConvertRecordsToUserModel(shapeContainer, patriarch);
                }
            }

            // Now, clear any trace of what records make up
            //  the patriarch
            // Otherwise, everything will go horribly wrong
            //  when we try to Write out again....
            //      clearEscherRecords();
            drawingManager.GetDgg().FileIdClusters = new EscherDggRecord.FileIdCluster[0];

            // TODO: Support Converting our records
            //  back into shapes
            log.Log(POILogger.WARN, "Not Processing objects into Patriarch!");
        }
예제 #22
0
 public static TextboxShape CreateTextboxShape(int shapeId, HSSFTextbox textbox)
 {
     return new TextboxShape(textbox, shapeId);
 }
예제 #23
0
        public void TestModify()
        {
            HSSFWorkbook wb = new HSSFWorkbook();

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

            HSSFShapeGroup group1 = patriarch.CreateGroup(new
                                                          HSSFClientAnchor(0, 0, 0, 0,
                                                                           (short)0, 0, (short)15, 25));

            group1.SetCoordinates(0, 0, 792, 612);

            HSSFTextbox textbox1 = group1.CreateTextbox(new
                                                        HSSFChildAnchor(100, 100, 300, 300));
            HSSFRichTextString rt1 = new HSSFRichTextString("Hello, World!");

            textbox1.String = rt1;

            // Write, read back and check that our text box is there
            wb        = HSSFTestDataSamples.WriteOutAndReadBack(wb);
            sheet     = wb.GetSheetAt(0) as HSSFSheet;
            patriarch = sheet.DrawingPatriarch as HSSFPatriarch;
            Assert.AreEqual(1, patriarch.Children.Count);

            group1 = (HSSFShapeGroup)patriarch.Children[(0)];
            Assert.AreEqual(1, group1.Children.Count);
            textbox1 = (HSSFTextbox)group1.Children[(0)];
            Assert.AreEqual("Hello, World!", textbox1.String.String);

            // modify anchor
            Assert.AreEqual(new HSSFChildAnchor(100, 100, 300, 300),
                            textbox1.Anchor);
            HSSFChildAnchor newAnchor = new HSSFChildAnchor(200, 200, 400, 400);

            textbox1.Anchor = newAnchor;
            // modify text
            textbox1.String = new HSSFRichTextString("Hello, World! (modified)");

            // add a new text box
            HSSFTextbox textbox2 = group1.CreateTextbox(new
                                                        HSSFChildAnchor(400, 400, 600, 600));
            HSSFRichTextString rt2 = new HSSFRichTextString("Hello, World-2");

            textbox2.String = rt2;
            Assert.AreEqual(2, group1.Children.Count);

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

            group1 = (HSSFShapeGroup)patriarch.Children[(0)];
            Assert.AreEqual(2, group1.Children.Count);
            textbox1 = (HSSFTextbox)group1.Children[(0)];
            Assert.AreEqual("Hello, World! (modified)",
                            textbox1.String.String);
            Assert.AreEqual(new HSSFChildAnchor(200, 200, 400, 400),
                            textbox1.Anchor);

            textbox2 = (HSSFTextbox)group1.Children[(1)];
            Assert.AreEqual("Hello, World-2", textbox2.String.String);
            Assert.AreEqual(new HSSFChildAnchor(400, 400, 600, 600),
                            textbox2.Anchor);

            wb        = HSSFTestDataSamples.WriteOutAndReadBack(wb);
            sheet     = wb.GetSheetAt(0) as HSSFSheet;
            patriarch = sheet.DrawingPatriarch as HSSFPatriarch;
            group1    = (HSSFShapeGroup)patriarch.Children[(0)];
            textbox1  = (HSSFTextbox)group1.Children[(0)];
            textbox2  = (HSSFTextbox)group1.Children[(1)];
            HSSFTextbox textbox3 = group1.CreateTextbox(new
                                                        HSSFChildAnchor(400, 200, 600, 400));
            HSSFRichTextString rt3 = new HSSFRichTextString("Hello, World-3");

            textbox3.String = rt3;
        }