Пример #1
0
        public void TestCloneSheetWithDrawings()
        {
            HSSFWorkbook wb1 = HSSFTestDataSamples.OpenSampleWorkbook("45720.xls");

            HSSFSheet sheet1 = (HSSFSheet)wb1.GetSheetAt(0);

            wb1.Workbook.FindDrawingGroup();
            DrawingManager2 dm1 = wb1.Workbook.DrawingManager;

            wb1.CloneSheet(0);

            HSSFWorkbook wb2 = HSSFTestDataSamples.WriteOutAndReadBack(wb1);

            wb2.Workbook.FindDrawingGroup();
            DrawingManager2 dm2 = wb2.Workbook.DrawingManager;

            //Check EscherDggRecord - a workbook-level registry of drawing objects
            Assert.AreEqual(dm1.GetDgg().MaxDrawingGroupId + 1, dm2.GetDgg().MaxDrawingGroupId);

            HSSFSheet sheet2 = (HSSFSheet)wb2.GetSheetAt(1);

            //Check that id of the drawing Group was updated
            EscherDgRecord dg1     = (EscherDgRecord)(sheet1.DrawingPatriarch as HSSFPatriarch).GetBoundAggregate().FindFirstWithId(EscherDgRecord.RECORD_ID);
            EscherDgRecord dg2     = (EscherDgRecord)(sheet2.DrawingPatriarch as HSSFPatriarch).GetBoundAggregate().FindFirstWithId(EscherDgRecord.RECORD_ID);
            int            dg_id_1 = dg1.Options >> 4;
            int            dg_id_2 = dg2.Options >> 4;

            Assert.AreEqual(dg_id_1 + 1, dg_id_2);

            //TODO: Check shapeId in the Cloned sheet
        }
Пример #2
0
        internal int NewShapeId()
        {
            DrawingManager2 dm = ((HSSFWorkbook)_sheet.Workbook).Workbook.DrawingManager;
            EscherDgRecord  dg =
                (EscherDgRecord)_boundAggregate.GetEscherContainer().GetChildById(EscherDgRecord.RECORD_ID);
            short drawingGroupId = dg.DrawingGroupId;

            return(dm.AllocateShapeId(drawingGroupId, dg));
        }
Пример #3
0
        internal void AfterCreate()
        {
            DrawingManager2 drawingManager = ((HSSFWorkbook)_sheet.Workbook).Workbook.DrawingManager;
            short           dgId           = drawingManager.FindNewDrawingGroupId();

            _boundAggregate.SetDgId(dgId);
            _boundAggregate.SetMainSpRecordId(NewShapeId());
            drawingManager.IncrementDrawingsSaved();
        }
Пример #4
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 );
        }
Пример #5
0
        private void ConfirmAggregatedRecords(List <RecordBase> recordStream)
        {
            InternalSheet sheet = InternalSheet.CreateSheet();

            sheet.Records.Clear();
            ((List <RecordBase>)sheet.Records).AddRange(recordStream);

            IList sheetRecords = sheet.Records;

            DrawingManager2 drawingManager = new DrawingManager2(new EscherDggRecord());

            sheet.AggregateDrawingRecords(drawingManager, false);

            Assert.AreEqual(4, sheetRecords.Count);
            Assert.AreEqual(BOFRecord.sid, ((Record)sheetRecords[0]).Sid);
            Assert.AreEqual(EscherAggregate.sid, ((Record)sheetRecords[1]).Sid);
            Assert.AreEqual(WindowTwoRecord.sid, ((Record)sheetRecords[2]).Sid);
            Assert.AreEqual(EOFRecord.sid, ((Record)sheetRecords[3]).Sid);
        }
Пример #6
0
        /**
         * Collapses the drawing records into an aggregate.
         */
        public static EscherAggregate CreateAggregate(IList records, int locFirstDrawingRecord, DrawingManager2 drawingManager)
        {
            // Keep track of any shape records Created so we can match them back to the object id's.
            // Textbox objects are also treated as shape objects.
            IList shapeRecords = new ArrayList();
            EscherRecordFactory recordFactory = new CustomEscherRecordFactory(ref shapeRecords);

            // Calculate the size of the buffer
            EscherAggregate agg      = new EscherAggregate(drawingManager);
            int             loc      = locFirstDrawingRecord;
            int             dataSize = 0;

            while (loc + 1 < records.Count &&
                   GetSid(records, loc) == DrawingRecord.sid &&
                   IsObjectRecord(records, loc + 1))
            {
                dataSize += ((DrawingRecord)records[loc]).Data.Length;
                loc      += 2;
            }

            // Create one big buffer
            byte[] buffer = new byte[dataSize];
            int    offset = 0;

            loc = locFirstDrawingRecord;
            while (loc + 1 < records.Count &&
                   GetSid(records, loc) == DrawingRecord.sid &&
                   IsObjectRecord(records, loc + 1))
            {
                DrawingRecord drawingRecord = (DrawingRecord)records[loc];
                Array.Copy(drawingRecord.Data, 0, buffer, offset, drawingRecord.Data.Length);
                offset += drawingRecord.Data.Length;
                loc    += 2;
            }

            // Decode the shapes
            //        agg.escherRecords = new ArrayList();
            int pos = 0;

            while (pos < dataSize)
            {
                EscherRecord r         = recordFactory.CreateRecord(buffer, pos);
                int          bytesRead = r.FillFields(buffer, pos, recordFactory);
                agg.AddEscherRecord(r);
                pos += bytesRead;
            }

            // Associate the object records with the shapes
            loc = locFirstDrawingRecord;
            int shapeIndex = 0;

            agg.shapeToObj = new Hashtable();
            while (loc + 1 < records.Count &&
                   GetSid(records, loc) == DrawingRecord.sid &&
                   IsObjectRecord(records, loc + 1))
            {
                Record objRecord = (Record)records[loc + 1];
                agg.shapeToObj[shapeRecords[shapeIndex++]] = objRecord;
                loc += 2;
            }

            return(agg);
        }
Пример #7
0
 public EscherAggregate(DrawingManager2 drawingManager)
 {
     this.drawingManager = drawingManager;
 }
Пример #8
0
 public void SetUp()
 {
     dgg = new EscherDggRecord();
     dgg.FileIdClusters = (new EscherDggRecord.FileIdCluster[0]);
     drawingManager2    = new DrawingManager2(dgg);
 }