Beispiel #1
0
        private static List <Record> ReadRecords(Stream stream, out MSODRAWING drawingRecord)
        {
            List <Record> records = new List <Record>();

            drawingRecord = null;
            Record record              = Record.Read(stream);
            Record last_record         = record;
            Record last_formula_record = null;

            last_record.Decode();
            if (record is BOF && ((BOF)record).StreamType == StreamType.Worksheet)
            {
                while (record.Type != RecordType.EOF)
                {
                    if (record.Type == RecordType.CONTINUE)
                    {
                        last_record.ContinuedRecords.Add(record);
                    }
                    else
                    {
                        switch (record.Type)
                        {
                        case RecordType.STRING:
                            // jetcat_au: use last_formula_record instead of last_record
                            if (last_formula_record is FORMULA)
                            {
                                record.Decode();
                                (last_formula_record as FORMULA).StringRecord = record as STRING;
                            }
                            break;

                        case RecordType.MSODRAWING:
                            if (drawingRecord == null)
                            {
                                drawingRecord = record as MSODRAWING;
                                records.Add(record);
                            }
                            else
                            {
                                drawingRecord.ContinuedRecords.Add(record);
                            }
                            break;

                        default:
                            records.Add(record);
                            break;
                        }
                        // jetcat_au: see 4.8 Array Formulas and Shared Formulas
                        if (record.Type == RecordType.FORMULA)
                        {
                            last_formula_record = record;
                        }
                        else if (record.Type != RecordType.SHRFMLA && record.Type != RecordType.ARRAY)
                        {
                            last_formula_record = null;
                        }
                        last_record = record;
                    }
                    record = Record.Read(stream);
                }
                records.Add(record);
            }
            return(records);
        }
Beispiel #2
0
        private static Record EncodePictures(Dictionary <Pair <int, int>, Picture> pictures, SharedResource sharedResource, Worksheet worksheet)
        {
            MSODRAWING        msoDrawing  = new MSODRAWING();
            MsofbtDgContainer dgContainer = new MsofbtDgContainer();

            msoDrawing.EscherRecords.Add(dgContainer);

            MsofbtDg dg = new MsofbtDg();

            dg.Instance    = 1;
            dg.NumShapes   = pictures.Count + 1;
            dg.LastShapeID = 1024 + pictures.Count;
            dgContainer.EscherRecords.Add(dg);

            MsofbtSpgrContainer spgrContainer = new MsofbtSpgrContainer();

            dgContainer.EscherRecords.Add(spgrContainer);

            MsofbtSpContainer spContainer0 = new MsofbtSpContainer();

            spContainer0.EscherRecords.Add(new MsofbtSpgr());
            MsofbtSp shape0 = new MsofbtSp();

            shape0.ShapeId = 1024;
            shape0.Flags   = ShapeFlag.Group | ShapeFlag.Patriarch;
            shape0.Version = 2;
            spContainer0.EscherRecords.Add(shape0);
            spgrContainer.EscherRecords.Add(spContainer0);

            foreach (Picture pic in pictures.Values)
            {
                if (!sharedResource.Images.Contains(pic.Image))
                {
                    sharedResource.Images.Add(pic.Image);
                }
                MsofbtSpContainer spContainer = new MsofbtSpContainer();
                MsofbtSp          shape       = new MsofbtSp();
                shape.Version   = 2;
                shape.ShapeType = ShapeType.PictureFrame;
                shape.ShapeId   = 1024 + spgrContainer.EscherRecords.Count;
                shape.Flags     = ShapeFlag.Haveanchor | ShapeFlag.Hasshapetype;
                spContainer.EscherRecords.Add(shape);

                MsofbtOPT opt = new MsofbtOPT();
                opt.Add(PropertyIDs.LockAgainstGrouping, 33226880);
                opt.Add(PropertyIDs.FitTextToShape, 262148);
                opt.Add(PropertyIDs.BlipId, (uint)sharedResource.Images.IndexOf(pic.Image) + 1);
                spContainer.EscherRecords.Add(opt);

                MsofbtClientAnchor anchor = new MsofbtClientAnchor();
                anchor.Row1      = pic.TopLeftCorner.RowIndex;
                anchor.Col1      = pic.TopLeftCorner.ColIndex;
                anchor.DX1       = pic.TopLeftCorner.DX;
                anchor.DY1       = pic.TopLeftCorner.DY;
                anchor.Row2      = pic.BottomRightCorner.RowIndex;
                anchor.Col2      = pic.BottomRightCorner.ColIndex;
                anchor.DX2       = pic.BottomRightCorner.DX;
                anchor.DY2       = pic.BottomRightCorner.DY;
                anchor.ExtraData = new byte[0];
                spContainer.EscherRecords.Add(anchor);

                spContainer.EscherRecords.Add(new MsofbtClientData());

                spgrContainer.EscherRecords.Add(spContainer);
            }
            return(msoDrawing);
        }