vsto c# 获取word里面的图片并保存

 internal void GetEmbeddedImages()
        {
            int i = 0;
            Document doc = Globals.ThisAddIn.Application.ActiveDocument;                  
            foreach (Microsoft.Office.Interop.Word.InlineShape ils in doc.InlineShapes)
            {             
                if (ils != null)
                {
                    i = i + 1;                    
                    if (ils.Type == Microsoft.Office.Interop.Word.WdInlineShapeType.wdInlineShapePicture)
                    {                       
                        ils.Select();
                        Globals.ThisAddIn.Application.Selection.CopyAsPicture();                       
                        IDataObject ido = Clipboard.GetDataObject();
                        if (ido != null)
                        {                          
                            if (ido.GetDataPresent(DataFormats.Bitmap))
                            {                               
                                Bitmap bmp = (Bitmap)ido.GetData(DataFormats.Bitmap);
                                string filename = @"C:\Users\Pictures\savedoc\" + i.ToString() + ".jpg";
                                bmp.Save(filename, ImageFormat.Jpeg);                               
                            }
                        }
                    }
                }               
            }
            MessageBox.Show("finished");
        }
    }

 

posted on 2019-12-24 14:00  GIS-MAN  阅读(1240)  评论(0编辑  收藏  举报

导航