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");
        }
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM