首页 > Windows开发 > 详细

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

时间:2019-12-24 14:43:46      阅读:209      评论:0      收藏:0      [点我收藏+]
 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");
        }
    }

 

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

原文:https://www.cnblogs.com/gisbeginner/p/12091167.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!