Пример #1
0
        private static Record EncodeImages(IList <Image> images)
        {
            MSODRAWINGGROUP    drawingGroup = new MSODRAWINGGROUP();
            MsofbtDggContainer dggContainer = new MsofbtDggContainer();

            drawingGroup.EscherRecords.Add(dggContainer);

            MsofbtDgg dgg = new MsofbtDgg();

            dgg.NumSavedDrawings = images.Count;
            dgg.NumSavedShapes   = images.Count + 1;
            dgg.MaxShapeID       = 1024 + dgg.NumSavedShapes;
            dgg.GroupIdClusters.Add(1, dgg.NumSavedShapes);
            dggContainer.EscherRecords.Add(dgg);

            MsofbtBstoreContainer bstoreContainer = new MsofbtBstoreContainer();

            bstoreContainer.Instance = (ushort)images.Count;
            foreach (Image image in images)
            {
                MsofbtBSE blipStoreEntry = new MsofbtBSE();
                blipStoreEntry.UID                  = Guid.NewGuid();
                blipStoreEntry.Ref                  = 1;
                blipStoreEntry.Version              = 2;
                blipStoreEntry.BlipRecord           = CreateBlipRecord(image);
                blipStoreEntry.BlipRecord.Type      = image.Format;
                blipStoreEntry.BlipRecord.ImageData = image.Data;
                blipStoreEntry.BlipRecord.UID       = blipStoreEntry.UID;
                blipStoreEntry.BlipRecord.Marker    = 255;
                blipStoreEntry.SetBlipType(image.Format);
                bstoreContainer.EscherRecords.Add(blipStoreEntry);
            }
            dggContainer.EscherRecords.Add(bstoreContainer);

            MsofbtOPT defautProperties = new MsofbtOPT();

            defautProperties.Add(PropertyIDs.FitTextToShape, 524296);
            defautProperties.Add(PropertyIDs.FillColor, 134217793);
            defautProperties.Add(PropertyIDs.LineColor, 134217792);
            dggContainer.EscherRecords.Add(defautProperties);

            MsofbtSplitMenuColors splitMenuColors = new MsofbtSplitMenuColors();

            splitMenuColors.Instance = 4;
            splitMenuColors.Color1   = 134217741;
            splitMenuColors.Color2   = 134217740;
            splitMenuColors.Color3   = 134217751;
            splitMenuColors.Color4   = 268435703;
            dggContainer.EscherRecords.Add(splitMenuColors);

            return(drawingGroup);
        }
Пример #2
0
        private static List <Record> ReadRecords(Stream stream, out MSODRAWINGGROUP drawingGroup)
        {
            List <Record> records = new List <Record>();

            drawingGroup = null;
            Record record = Record.Read(stream);

            record.Decode();
            Record last_record = record;

            if (record is BOF && ((BOF)record).StreamType == StreamType.WorkbookGlobals)
            {
                while (record.Type != RecordType.EOF)
                {
                    if (record.Type == RecordType.CONTINUE)
                    {
                        last_record.ContinuedRecords.Add(record);
                    }
                    else
                    {
                        switch (record.Type)
                        {
                        case RecordType.MSODRAWINGGROUP:
                            if (drawingGroup == null)
                            {
                                drawingGroup = record as MSODRAWINGGROUP;
                                records.Add(record);
                            }
                            else
                            {
                                drawingGroup.ContinuedRecords.Add(record);
                            }
                            break;

                        default:
                            records.Add(record);
                            break;
                        }
                        last_record = record;
                    }
                    record = Record.Read(stream);
                }
                records.Add(record);
            }
            else
            {
                throw new Exception("Invalid Workbook.");
            }
            return(records);
        }