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   GIS-MAN  阅读(1292)  评论(0编辑  收藏  举报

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示