Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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;
        }