Пример #1
0
        private static Record EncodePictures(Dictionary <Pair <int, int>, Picture> pictures, SharedResource sharedResource, Worksheet worksheet)
        {
            MSODRAWING        mSODRAWING        = new MSODRAWING();
            MsofbtDgContainer msofbtDgContainer = new MsofbtDgContainer();

            mSODRAWING.EscherRecords.Add(msofbtDgContainer);
            MsofbtDg msofbtDg = new MsofbtDg();

            msofbtDg.Instance = 1;
            checked
            {
                msofbtDg.NumShapes   = pictures.Count + 1;
                msofbtDg.LastShapeID = 1024 + pictures.Count;
                msofbtDgContainer.EscherRecords.Add(msofbtDg);
                MsofbtSpgrContainer msofbtSpgrContainer = new MsofbtSpgrContainer();
                msofbtDgContainer.EscherRecords.Add(msofbtSpgrContainer);
                MsofbtSpContainer msofbtSpContainer = new MsofbtSpContainer();
                msofbtSpContainer.EscherRecords.Add(new MsofbtSpgr());
                MsofbtSp msofbtSp = new MsofbtSp();
                msofbtSp.ShapeId = 1024;
                msofbtSp.Flags   = 5;
                msofbtSp.Version = 2;
                msofbtSpContainer.EscherRecords.Add(msofbtSp);
                msofbtSpgrContainer.EscherRecords.Add(msofbtSpContainer);
                foreach (Picture current in pictures.Values)
                {
                    if (!sharedResource.Images.Contains(current.Image))
                    {
                        sharedResource.Images.Add(current.Image);
                    }
                    MsofbtSpContainer msofbtSpContainer2 = new MsofbtSpContainer();
                    MsofbtSp          msofbtSp2          = new MsofbtSp();
                    msofbtSp2.Version   = 2;
                    msofbtSp2.ShapeType = ShapeType.PictureFrame;
                    msofbtSp2.ShapeId   = 1024 + msofbtSpgrContainer.EscherRecords.Count;
                    msofbtSp2.Flags     = 2560;
                    msofbtSpContainer2.EscherRecords.Add(msofbtSp2);
                    MsofbtOPT msofbtOPT = new MsofbtOPT();
                    msofbtOPT.Add(PropertyIDs.LockAgainstGrouping, 33226880u);
                    msofbtOPT.Add(PropertyIDs.FitTextToShape, 262148u);
                    msofbtOPT.Add(PropertyIDs.BlipId, (uint)sharedResource.Images.IndexOf(current.Image) + 1u);
                    msofbtSpContainer2.EscherRecords.Add(msofbtOPT);
                    MsofbtClientAnchor msofbtClientAnchor = new MsofbtClientAnchor();
                    msofbtClientAnchor.Row1      = current.TopLeftCorner.RowIndex;
                    msofbtClientAnchor.Col1      = current.TopLeftCorner.ColIndex;
                    msofbtClientAnchor.DX1       = current.TopLeftCorner.DX;
                    msofbtClientAnchor.DY1       = current.TopLeftCorner.DY;
                    msofbtClientAnchor.Row2      = current.BottomRightCorner.RowIndex;
                    msofbtClientAnchor.Col2      = current.BottomRightCorner.ColIndex;
                    msofbtClientAnchor.DX2       = current.BottomRightCorner.DX;
                    msofbtClientAnchor.DY2       = current.BottomRightCorner.DY;
                    msofbtClientAnchor.ExtraData = new byte[0];
                    msofbtSpContainer2.EscherRecords.Add(msofbtClientAnchor);
                    msofbtSpContainer2.EscherRecords.Add(new MsofbtClientData());
                    msofbtSpgrContainer.EscherRecords.Add(msofbtSpContainer2);
                }
                return(mSODRAWING);
            }
        }
Пример #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);
        }
Пример #3
0
        private static Record EncodeImages(IList <Image> images)
        {
            MSODRAWINGGROUP    mSODRAWINGGROUP    = new MSODRAWINGGROUP();
            MsofbtDggContainer msofbtDggContainer = new MsofbtDggContainer();

            mSODRAWINGGROUP.EscherRecords.Add(msofbtDggContainer);
            MsofbtDgg msofbtDgg = new MsofbtDgg();

            msofbtDgg.NumSavedDrawings = images.Count;
            checked
            {
                msofbtDgg.NumSavedShapes = images.Count + 1;
                msofbtDgg.MaxShapeID     = 1024 + msofbtDgg.NumSavedShapes;
                msofbtDgg.GroupIdClusters.Add(1, msofbtDgg.NumSavedShapes);
                msofbtDggContainer.EscherRecords.Add(msofbtDgg);
                MsofbtBstoreContainer msofbtBstoreContainer = new MsofbtBstoreContainer();
                msofbtBstoreContainer.Instance = (ushort)images.Count;
                foreach (Image current in images)
                {
                    MsofbtBSE msofbtBSE = new MsofbtBSE();
                    msofbtBSE.UID                  = Guid.NewGuid();
                    msofbtBSE.Ref                  = 1;
                    msofbtBSE.Version              = 2;
                    msofbtBSE.BlipRecord           = WorkbookEncoder.CreateBlipRecord(current);
                    msofbtBSE.BlipRecord.Type      = current.Format;
                    msofbtBSE.BlipRecord.ImageData = current.Data;
                    msofbtBSE.BlipRecord.UID       = msofbtBSE.UID;
                    msofbtBSE.BlipRecord.Marker    = 255;
                    msofbtBSE.SetBlipType(current.Format);
                    msofbtBstoreContainer.EscherRecords.Add(msofbtBSE);
                }
                msofbtDggContainer.EscherRecords.Add(msofbtBstoreContainer);
                MsofbtOPT msofbtOPT = new MsofbtOPT();
                msofbtOPT.Add(PropertyIDs.FitTextToShape, 524296u);
                msofbtOPT.Add(PropertyIDs.FillColor, 134217793u);
                msofbtOPT.Add(PropertyIDs.LineColor, 134217792u);
                msofbtDggContainer.EscherRecords.Add(msofbtOPT);
                MsofbtSplitMenuColors msofbtSplitMenuColors = new MsofbtSplitMenuColors();
                msofbtSplitMenuColors.Instance = 4;
                msofbtSplitMenuColors.Color1   = 134217741;
                msofbtSplitMenuColors.Color2   = 134217740;
                msofbtSplitMenuColors.Color3   = 134217751;
                msofbtSplitMenuColors.Color4   = 268435703;
                msofbtDggContainer.EscherRecords.Add(msofbtSplitMenuColors);
                return(mSODRAWINGGROUP);
            }
        }
Пример #4
0
        public void ExtractPictures()
        {
            if (Drawing != null)
            {
                MsofbtDgContainer dgContainer = Drawing.FindChild <MsofbtDgContainer>();
                if (dgContainer != null)
                {
                    MsofbtSpgrContainer spgrContainer = dgContainer.FindChild <MsofbtSpgrContainer>();

                    List <MsofbtSpContainer> spContainers = spgrContainer.FindChildren <MsofbtSpContainer>();

                    foreach (MsofbtSpContainer spContainer in spContainers)
                    {
                        MsofbtOPT          opt    = spContainer.FindChild <MsofbtOPT>();
                        MsofbtClientAnchor anchor = spContainer.FindChild <MsofbtClientAnchor>();

                        if (opt != null && anchor != null)
                        {
                            foreach (ShapeProperty prop in opt.Properties)
                            {
                                if (prop.PropertyID == PropertyIDs.BlipId)
                                {
                                    int     imageIndex = (int)prop.PropertyValue - 1;
                                    Picture pic        = new Picture();
                                    pic.TopLeftCorner.RowIndex     = anchor.Row1;
                                    pic.TopLeftCorner.ColIndex     = anchor.Col1;
                                    pic.TopLeftCorner.DX           = anchor.DX1;
                                    pic.TopLeftCorner.DY           = anchor.DY1;
                                    pic.BottomRightCorner.RowIndex = anchor.Row2;
                                    pic.BottomRightCorner.ColIndex = anchor.Col2;
                                    pic.BottomRightCorner.DX       = anchor.DX2;
                                    pic.BottomRightCorner.DY       = anchor.DY2;
                                    pic.Image             = Book.ExtractImage(imageIndex);
                                    pictures[pic.CellPos] = pic;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #5
0
 public void ExtractPictures()
 {
     if (this.Drawing != null)
     {
         MsofbtDgContainer msofbtDgContainer = this.Drawing.FindChild <MsofbtDgContainer>();
         if (msofbtDgContainer != null)
         {
             MsofbtSpgrContainer      msofbtSpgrContainer = msofbtDgContainer.FindChild <MsofbtSpgrContainer>();
             List <MsofbtSpContainer> list = msofbtSpgrContainer.FindChildren <MsofbtSpContainer>();
             foreach (MsofbtSpContainer current in list)
             {
                 MsofbtOPT          msofbtOPT          = current.FindChild <MsofbtOPT>();
                 MsofbtClientAnchor msofbtClientAnchor = current.FindChild <MsofbtClientAnchor>();
                 if (msofbtOPT != null && msofbtClientAnchor != null)
                 {
                     foreach (ShapeProperty current2 in msofbtOPT.Properties)
                     {
                         if (current2.PropertyID == PropertyIDs.BlipId)
                         {
                             int     index   = checked ((int)current2.PropertyValue - 1);
                             Picture picture = new Picture();
                             picture.TopLeftCorner.RowIndex     = msofbtClientAnchor.Row1;
                             picture.TopLeftCorner.ColIndex     = msofbtClientAnchor.Col1;
                             picture.TopLeftCorner.DX           = msofbtClientAnchor.DX1;
                             picture.TopLeftCorner.DY           = msofbtClientAnchor.DY1;
                             picture.BottomRightCorner.RowIndex = msofbtClientAnchor.Row2;
                             picture.BottomRightCorner.ColIndex = msofbtClientAnchor.Col2;
                             picture.BottomRightCorner.DX       = msofbtClientAnchor.DX2;
                             picture.BottomRightCorner.DY       = msofbtClientAnchor.DY2;
                             picture.Image = this.Book.ExtractImage(index);
                             this.pictures[picture.CellPos] = picture;
                             break;
                         }
                     }
                 }
             }
         }
     }
 }
Пример #6
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);
        }