Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public void TestClearShapesForPatriarch()
        {
            HSSFWorkbook  wb        = new HSSFWorkbook();
            HSSFSheet     sheet     = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;

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

            EscherAggregate agg = HSSFTestHelper.GetEscherAggregate(patriarch);

            Assert.AreEqual(agg.GetShapeToObjMapping().Count, 6);
            Assert.AreEqual(agg.TailRecords.Count, 1);
            Assert.AreEqual(patriarch.Children.Count, 3);

            patriarch.Clear();

            Assert.AreEqual(agg.GetShapeToObjMapping().Count, 0);
            Assert.AreEqual(agg.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(agg.GetShapeToObjMapping().Count, 0);
            Assert.AreEqual(agg.TailRecords.Count, 0);
            Assert.AreEqual(patriarch.Children.Count, 0);
        }
Exemplo n.º 3
0
        public void TestClearShapes()
        {
            HSSFWorkbook   wb        = new HSSFWorkbook();
            HSSFSheet      sheet     = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch  patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;
            HSSFShapeGroup group     = patriarch.CreateGroup(new HSSFClientAnchor());

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

            EscherAggregate agg = HSSFTestHelper.GetEscherAggregate(patriarch);

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

            group.Clear();

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

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

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

            Assert.AreEqual(agg.GetShapeToObjMapping().Count, 1);
            Assert.AreEqual(agg.TailRecords.Count, 0);
            Assert.AreEqual(group.Children.Count, 0);
        }
Exemplo n.º 4
0
        internal override void AfterInsert(HSSFPatriarch patriarch)
        {
            EscherAggregate       agg             = patriarch.GetBoundAggregate();
            EscherContainerRecord containerRecord = (EscherContainerRecord)GetEscherContainer().GetChildById(EscherContainerRecord.SP_CONTAINER);

            agg.AssociateShapeToObjRecord(containerRecord.GetChildById(EscherClientDataRecord.RECORD_ID), GetObjRecord());
        }
Exemplo n.º 5
0
        public void TestCloneSheetWithEmptyDrawingAggregate()
        {
            HSSFWorkbook b = new HSSFWorkbook();
            HSSFSheet s = b.CreateSheet("Test") as HSSFSheet;
            HSSFPatriarch patriarch = s.CreateDrawingPatriarch() as HSSFPatriarch;

            EscherAggregate agg1 = patriarch.GetBoundAggregate();

            HSSFSheet s2 = s.CloneSheet(b) as HSSFSheet;

            patriarch = s2.DrawingPatriarch as HSSFPatriarch;

            EscherAggregate agg2 = patriarch.GetBoundAggregate();

            EscherSpRecord sp1 = (EscherSpRecord)agg1.GetEscherContainer().GetChild(1).GetChild(0).GetChild(1);
            EscherSpRecord sp2 = (EscherSpRecord)agg2.GetEscherContainer().GetChild(1).GetChild(0).GetChild(1);

            Assert.AreEqual(sp1.ShapeId, 1024);
            Assert.AreEqual(sp2.ShapeId, 2048);

            EscherDgRecord dg = (EscherDgRecord)agg2.GetEscherContainer().GetChild(0);

            Assert.AreEqual(dg.LastMSOSPID, 2048);
            Assert.AreEqual(dg.Instance, 0x2);

            //everything except id and DgRecord.lastMSOSPID and DgRecord.Instance must be the same

            sp2.ShapeId = (1024);
            dg.LastMSOSPID = (1024);
            dg.Instance =((short)0x1);

            Assert.AreEqual(agg1.Serialize().Length, agg2.Serialize().Length);
            Assert.AreEqual(agg1.ToXml(""), agg2.ToXml(""));
            Assert.IsTrue(Arrays.Equals(agg1.Serialize(), agg2.Serialize()));
        }
Exemplo n.º 6
0
        internal override void AfterInsert(HSSFPatriarch patriarch)
        {
            EscherAggregate agg = patriarch.GetBoundAggregate();

            agg.AssociateShapeToObjRecord(GetEscherContainer().GetChildById(EscherClientDataRecord.RECORD_ID), GetObjRecord());
            if (GetTextObjectRecord() != null)
            {
                agg.AssociateShapeToObjRecord(GetEscherContainer().GetChildById(EscherTextboxRecord.RECORD_ID), GetTextObjectRecord());
            }
        }
Exemplo n.º 7
0
        internal override void AfterInsert(HSSFPatriarch patriarch)
        {
            EscherAggregate agg = patriarch.GetBoundAggregate();

            agg.AssociateShapeToObjRecord(GetEscherContainer().GetChildById(EscherClientDataRecord.RECORD_ID), GetObjRecord());
            EscherBSERecord bse =
                (patriarch.Sheet.Workbook as HSSFWorkbook).Workbook.GetBSERecord(PictureIndex);

            bse.Ref = (bse.Ref + 1);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates the patriarch.
        /// </summary>
        /// <param name="sheet">the sheet this patriarch is stored in.</param>
        /// <param name="boundAggregate">The bound aggregate.</param>
        public HSSFPatriarch(HSSFSheet sheet, EscherAggregate boundAggregate)
        {
            _boundAggregate    = boundAggregate;
            _sheet             = sheet;
            _mainSpgrContainer = _boundAggregate.GetEscherContainer().ChildContainers[0];
            EscherContainerRecord spContainer = (EscherContainerRecord)_boundAggregate.GetEscherContainer()
                                                .ChildContainers[0].GetChild(0);

            _spgrRecord = (EscherSpgrRecord)spContainer.GetChildById(EscherSpgrRecord.RECORD_ID);
            BuildShapeTree();
        }
Exemplo n.º 9
0
        public void TestDgRecordNumShapes()
        {
            HSSFWorkbook  wb        = new HSSFWorkbook();
            HSSFSheet     sheet     = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;

            EscherAggregate aggregate = HSSFTestHelper.GetEscherAggregate(patriarch);
            EscherDgRecord  dgRecord  = (EscherDgRecord)aggregate.GetEscherRecord(0).GetChild(0) as EscherDgRecord;

            Assert.AreEqual(dgRecord.NumShapes, 1);
        }
Exemplo n.º 10
0
        public void TestCreateAggregate()
        {
            String msoDrawingRecord1 =
                "0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 " +
                "03 00 00 00 02 04 00 00 0F 00 03 F0 08 01 00 00 " +
                "0F 00 04 F0 28 00 00 00 01 00 09 F0 10 00 00 00 " +
                "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " +
                "02 00 0A F0 08 00 00 00 00 04 00 00 05 00 00 00 " +
                "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 " +
                "01 04 00 00 00 0A 00 00 73 00 0B F0 2A 00 00 00 " +
                "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 " +
                "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 " +
                "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 " +
                "00 00 00 00 01 00 54 00 05 00 45 00 01 00 88 03 " +
                "05 00 94 00 00 00 11 F0 00 00 00 00";

            String msoDrawingRecord2 =
                "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 " +
                "02 04 00 00 80 0A 00 00 73 00 0B F0 2A 00 00 00 " +
                "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 " +
                "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 " +
                "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 " +
                "00 00 00 00 01 00 8D 03 05 00 E4 00 03 00 4D 03 " +
                "0B 00 0C 00 00 00 11 F0 00 00 00 00";

            DrawingRecord d1 = new DrawingRecord();

            d1.Data = (HexRead.ReadFromString(msoDrawingRecord1));

            ObjRecord r1 = new ObjRecord();

            DrawingRecord d2 = new DrawingRecord();

            d2.Data = (HexRead.ReadFromString(msoDrawingRecord2));

            ObjRecord r2 = new ObjRecord();

            ArrayList records = new ArrayList();

            records.Add(d1);
            records.Add(r1);
            records.Add(d2);
            records.Add(r2);

            DrawingManager2 drawingManager = new DrawingManager2(new EscherDggRecord());
            EscherAggregate aggregate      = EscherAggregate.CreateAggregate(records, 0, drawingManager);

            Assert.AreEqual(1, aggregate.EscherRecords.Count);
            Assert.AreEqual(unchecked ((short)0xF002), aggregate.GetEscherRecord(0).RecordId);
            Assert.AreEqual(2, aggregate.GetEscherRecord(0).ChildRecords.Count);

            //        System.out.println( "aggregate = " + aggregate );
        }
Exemplo n.º 11
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();
        }
Exemplo n.º 12
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();
        }
Exemplo n.º 13
0
        public void TestSerialize()
        {
            EscherContainerRecord  container1   = new EscherContainerRecord();
            EscherContainerRecord  spContainer1 = new EscherContainerRecord();
            EscherContainerRecord  spContainer2 = new EscherContainerRecord();
            EscherContainerRecord  spContainer3 = new EscherContainerRecord();
            EscherSpRecord         sp1          = new EscherSpRecord();
            EscherSpRecord         sp2          = new EscherSpRecord();
            EscherSpRecord         sp3          = new EscherSpRecord();
            EscherClientDataRecord d2           = new EscherClientDataRecord();
            EscherClientDataRecord d3           = new EscherClientDataRecord();

            container1.Options    = ((short)0x000F);
            spContainer1.Options  = ((short)0x000F);
            spContainer1.RecordId = (EscherContainerRecord.SP_CONTAINER);
            spContainer2.Options  = ((short)0x000F);
            spContainer2.RecordId = (EscherContainerRecord.SP_CONTAINER);
            spContainer3.Options  = ((short)0x000F);
            spContainer3.RecordId = (EscherContainerRecord.SP_CONTAINER);
            d2.RecordId           = (EscherClientDataRecord.RECORD_ID);
            d2.RemainingData      = (new byte[0]);
            d3.RecordId           = (EscherClientDataRecord.RECORD_ID);
            d3.RemainingData      = (new byte[0]);
            container1.AddChildRecord(spContainer1);
            container1.AddChildRecord(spContainer2);
            container1.AddChildRecord(spContainer3);
            spContainer1.AddChildRecord(sp1);
            spContainer2.AddChildRecord(sp2);
            spContainer3.AddChildRecord(sp3);
            spContainer2.AddChildRecord(d2);
            spContainer3.AddChildRecord(d3);

            EscherAggregate aggregate = new EscherAggregate(null);

            aggregate.AddEscherRecord(container1);
            aggregate.AssoicateShapeToObjRecord(d2, new ObjRecord());
            aggregate.AssoicateShapeToObjRecord(d3, new ObjRecord());

            byte[] data         = new byte[112];
            int    bytesWritten = aggregate.Serialize(0, data);

            Assert.AreEqual(112, bytesWritten);
            Assert.AreEqual("[EC, 00, 40, 00, 0F, 00, 00, 00, 58, 00, 00, 00, 0F, 00, 04, F0, 10, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00, EC, 00, 20, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00, ]",
                            HexDump.ToHex(data));
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        public void TestDgContainerMustBeRootOfHSSFSheetEscherRecords()
        {
            HSSFWorkbook      wb      = HSSFTestDataSamples.OpenSampleWorkbook("47251.xls");
            HSSFSheet         sh      = wb.GetSheetAt(0) as HSSFSheet;
            InternalSheet     ish     = HSSFTestHelper.GetSheetForTest(sh);
            List <RecordBase> records = ish.Records;
            // records to be aggregated
            List <RecordBase> dgRecords = records.GetRange(19, 23 - 19);

            byte[]          dgBytes = toByteArray(dgRecords);
            IDrawing        d       = sh.DrawingPatriarch;
            EscherAggregate agg     = (EscherAggregate)ish.FindFirstRecordBySid(EscherAggregate.sid);

            Assert.AreEqual(true, agg.EscherRecords[0] is EscherContainerRecord);
            Assert.AreEqual(EscherContainerRecord.DG_CONTAINER, agg.EscherRecords[0].RecordId);
            Assert.AreEqual((short)0x0, agg.EscherRecords[0].Options);
            agg = (EscherAggregate)ish.FindFirstRecordBySid(EscherAggregate.sid);
            byte[] dgBytesAfterSave = agg.Serialize();
            Assert.AreEqual(dgBytes.Length, dgBytesAfterSave.Length, "different size of drawing data before and after save");
            Assert.IsTrue(Arrays.Equals(dgBytes, dgBytesAfterSave), "drawing data before and after save is different");
        }
Exemplo n.º 16
0
 public static HSSFPatriarch CreateTestPatriarch(HSSFSheet sheet, EscherAggregate agg)
 {
     return(new HSSFPatriarch(sheet, agg));
 }
Exemplo n.º 17
0
 /// <summary>
 /// Creates the patriarch.
 /// </summary>
 /// <param name="sheet">the sheet this patriarch is stored in.</param>
 /// <param name="boundAggregate">The bound aggregate.</param>
 public HSSFPatriarch(HSSFSheet sheet, EscherAggregate boundAggregate)
 {
     this._boundAggregate = boundAggregate;
     this._sheet          = sheet;
 }
Exemplo n.º 18
0
        //static void LoadDocumentPart(HWPFDocument hwpf,TreeNode parent,string partName,FieldsDocumentPart part)
        //{

        //    TreeNode mainNode = new TreeNode(partName);
        //    mainNode.ImageKey = "Folder";
        //    mainNode.SelectedImageKey = "Folder";
        //    parent.Nodes.Add(mainNode);
        //    Fields fields = hwpf.GetFields();
        //    foreach (Field field in fields.GetFields(part))
        //    {
        //        TreeNode tn = new TreeNode("Field");
        //        mainNode.Nodes.Add(tn);
        //    }
        //}


        static void HandleWorkbook(TreeNode treeNode, HSSFWorkbook hssfworkbook)
        {
            if (hssfworkbook.NumberOfSheets > 0)
            {
                treeNode.ImageKey         = "Folder";
                treeNode.SelectedImageKey = "Folder";
                for (int i = 0; i < hssfworkbook.NumberOfSheets; i++)
                {
                    string   sheettext = string.Format("Sheet {0}", i + 1);
                    TreeNode sheetnode =
                        treeNode.Nodes.Add(sheettext, sheettext, "Folder", "Folder");

                    HSSFSheet       hssfsheet = ((HSSFSheet)hssfworkbook.GetSheetAt(i));
                    EscherAggregate ea        = hssfsheet.DrawingEscherAggregate;
                    IEnumerator     iterator1 = hssfsheet.Sheet.Records.GetEnumerator();
                    while (iterator1.MoveNext())
                    {
                        if (iterator1.Current is Record)
                        {
                            Record record = (Record)iterator1.Current;
                            sheetnode.Nodes.Add(new RecordTreeNode(record));
                        }
                        else if (iterator1.Current is RecordAggregate)
                        {
                            RecordAggregate record = (RecordAggregate)iterator1.Current;
                            sheetnode.Nodes.Add(new RecordAggregateTreeNode(record));
                        }
                    }
                    //RecordTreeNode rtn = new DirectoryTreeNode();
                    if (ea != null)
                    {
                        foreach (EscherRecord er in ea.EscherRecords)
                        {
                            sheetnode.Nodes.Add(new EscherRecordTreeNode(er));
                        }
                    }
                }
            }
            else
            {
                treeNode.ImageKey = "Binary";
            }
            IEnumerator iterator2 = hssfworkbook.Workbook.Records.GetEnumerator();

            while (iterator2.MoveNext())
            {
                if (iterator2.Current is Record)         //&& !(iterator2.Current is UnknownRecord))
                {
                    Record record = (Record)iterator2.Current;
                    if (record is DrawingGroupRecord)
                    {
                        hssfworkbook.GetAllPictures();
                    }
                    treeNode.Nodes.Add(new RecordTreeNode(record));
                }
                else if (iterator2.Current is RecordBase)
                {
                    RecordBase record = (RecordBase)iterator2.Current;
                    treeNode.Nodes.Add(record.GetType().Name);
                }
            }
        }
Exemplo n.º 19
0
        /**
         * build shape tree from escher container
         * @param container root escher container from which escher records must be taken
         * @param agg - EscherAggregate
         * @param out - shape container to which shapes must be added
         * @param root - node to create HSSFObjectData shapes
         */

        public static void CreateShapeTree(EscherContainerRecord container, EscherAggregate agg,
                                           HSSFShapeContainer out1, DirectoryNode root)
        {
            if (container.RecordId == EscherContainerRecord.SPGR_CONTAINER)
            {
                ObjRecord obj = null;
                EscherClientDataRecord clientData = (EscherClientDataRecord)((EscherContainerRecord)container.GetChild(0)).GetChildById(EscherClientDataRecord.RECORD_ID);
                if (null != clientData)
                {
                    obj = (ObjRecord)agg.GetShapeToObjMapping()[clientData];
                }
                HSSFShapeGroup group = new HSSFShapeGroup(container, obj);
                IList <EscherContainerRecord> children = container.ChildContainers;
                // skip the first child record, it is group descriptor
                for (int i = 0; i < children.Count; i++)
                {
                    EscherContainerRecord spContainer = children[(i)];
                    if (i != 0)
                    {
                        CreateShapeTree(spContainer, agg, group, root);
                    }
                }
                out1.AddShape(group);
            }
            else if (container.RecordId == EscherContainerRecord.SP_CONTAINER)
            {
                Dictionary <EscherRecord, Record.Record> shapeToObj = agg.GetShapeToObjMapping();
                ObjRecord        objRecord = null;
                TextObjectRecord txtRecord = null;

                foreach (EscherRecord record in container.ChildRecords)
                {
                    switch (record.RecordId)
                    {
                    case EscherClientDataRecord.RECORD_ID:
                        objRecord = (ObjRecord)shapeToObj[(record)];
                        break;

                    case EscherTextboxRecord.RECORD_ID:
                        txtRecord = (TextObjectRecord)shapeToObj[(record)];
                        break;
                    }
                }
                if (IsEmbeddedObject(objRecord))
                {
                    HSSFObjectData objectData = new HSSFObjectData(container, objRecord, root);
                    out1.AddShape(objectData);
                    return;
                }
                CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord)objRecord.SubRecords[0];
                HSSFShape shape;
                switch (cmo.ObjectType)
                {
                case CommonObjectType.Picture:
                    shape = new HSSFPicture(container, objRecord);
                    break;

                case CommonObjectType.Rectangle:
                    shape = new HSSFSimpleShape(container, objRecord, txtRecord);
                    break;

                case CommonObjectType.Line:
                    shape = new HSSFSimpleShape(container, objRecord);
                    break;

                case CommonObjectType.ComboBox:
                    shape = new HSSFCombobox(container, objRecord);
                    break;

                case CommonObjectType.MicrosoftOfficeDrawing:
                    EscherOptRecord optRecord = (EscherOptRecord)container.GetChildById(EscherOptRecord.RECORD_ID);
                    EscherProperty  property  = optRecord.Lookup(EscherProperties.GEOMETRY__VERTICES);
                    if (null != property)
                    {
                        shape = new HSSFPolygon(container, objRecord, txtRecord);
                    }
                    else
                    {
                        shape = new HSSFSimpleShape(container, objRecord, txtRecord);
                    }
                    break;

                case CommonObjectType.Text:
                    shape = new HSSFTextbox(container, objRecord, txtRecord);
                    break;

                case CommonObjectType.Comment:
                    shape = new HSSFComment(container, objRecord, txtRecord, agg.GetNoteRecordByObj(objRecord));
                    break;

                default:
                    shape = new HSSFSimpleShape(container, objRecord, txtRecord);
                    break;
                }
                out1.AddShape(shape);
            }
        }