Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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();
        }
        /**
         * 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);
            }
        }