转换“Selection.CopyAsPicture()”到图像文件? [英] Convert "Selection.CopyAsPicture()" to Image File?

查看:443
本文介绍了转换“Selection.CopyAsPicture()”到图像文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我找不到解决问题的方法。

I failed to find a solution for my problem.

我想将Word选择保存为图像文件。

I want to save the Word Selection as an Image file.

它成功地从word文件中复制数据,但我无法使用c#从剪贴板中获取图像。但是,当我关闭应用程序并通常将其粘贴到doc文件中....它工作正常!

It successfully copies the data from word file, but i cannot get an image from clipboard using c#. However, when i close the app and normally paste it in doc file .... it works fine!

我正在使用以下代码!

I am using the following CODE!!

Microsoft.Office.Interop.Word.Application app;
  Microsoft.Office.Interop.Word.Document oDoc;

  app = new Microsoft.Office.Interop.Word.Application();
  oDoc = app.Documents.Open("C:\\test\\test.docx");

  //Set the range for First Page
  oDoc.ActiveWindow.Selection.SetRange(oDoc.Bookmarks["\\Page"].Range.Start,
  oDoc.Bookmarks["\\Page"].Range.End - 1);
 
  app.Selection.CopyAsPicture();

  if (Clipboard.GetDataObject() != null) 
  {
  IDataObject data = Clipboard.GetDataObject();

  if (data.GetDataPresent(DataFormats.Bitmap, true)) // Return False
  {
   Image image = (System.Drawing.Image)data.GetData(DataFormats.Bitmap, true);
   image.Save( "C:\\image.jpg");

  }
  else if (data.GetDataPresent(DataFormats.MetafilePict)) // Return TRUE but failed to convert as image
  {
   Stream myStream = (Stream)data.GetData(DataFormats.MetafilePict);
   Image m = Metafile.FromStream(myStream);
   
  }
  
  }


推荐答案

您好NMA,

谢谢发布。

阅读完帖子后,我测试了代码,遇到了同样的问题。我也参考了这些网站:

After reading your post, I tested the code, and encountered the same problem. I also reference these websites:

http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/1bf630ad-70a3-4e04-9399-67c64043782f

http://social.msdn.microsoft.com/Forums / en / vsto / thread / fa93f6c9-ec8e-42d2-b4ba-ff6d94083720

http://stackoverflow.com/questions/169866/export-pictures-in-microsoft-word-to-tiff

似乎word有自己的剪贴板,我没有成功将数据设置为Windows Form剪贴板。我会进一步研究这个问题。所以,可能会有一些延迟,感谢您的耐心等待。

It seems that word has it's own clipboard and I haven't successfully set data to Windows Form clipboard. I will do further research about this problem. So, there might some delay, appreciate your patience.

最好的问候,


这篇关于转换“Selection.CopyAsPicture()”到图像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆