如何将图像和文本从应用程序C#复制到Microsoft Office [英] How to copy Images and text from Application C# to Microsoft office

查看:117
本文介绍了如何将图像和文本从应用程序C#复制到Microsoft Office的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中使用剪贴板时遇到问题,并且随着时间的推移我在互联网上进行搜索,但是
我找不到所有能解决我问题的东西!请帮帮我.

我需要将图像和文本都复制到剪贴板,所以我使用:

I have problem when work with clipboard in C# and i search over time in internet but
I cant find everything for my problems! Please help me.

I need copy both of image and text to Clipboard so I use:

//gdiBitmap is BitmapSource:
DataObject dataObj = new DataObject(); 
dataObj.SetData(DataFormats.Bitmap, gdiBitmap); 
dataObj.SetData(DataFormats.Text, " Text Copy Image To Clipboard");
Clipboard.SetDataObject(dataObj, true);


但是我无法将剪贴板中的内容粘贴到Microsoft Word或Excel.
它仅粘贴文本将图像复制到剪贴板中",而我的图像不显示任何内容.

但是如果我只复制一张图片或文字就可以了!

感谢您的帮助!


but I cant pastes the content in clipboard to Microsoft Word or Excel.
It is Only pastes the text "Text Copy Image To Clipboard" and my image is nothing.

but if i only copy one Image or text it''s ok!

Thanks for Help!

推荐答案



尝试从word中复制某些内容,然后在C#项目中运行以下代码:

Hi,

Try to copy something from word, and then run this code in a C# project:

object rtfData = Clipboard.GetData(DataFormats.Rtf);
Clipboard.SetData(DataFormats.Rtf, rtfData);



您将看到Word以RTF格式将数据放入剪贴板.

为了使您做同样的事情,必须将其放入剪贴板RTF数据格式.

在您的示例中,如果粘贴Word,它将复制剪贴板中的文本,如果粘贴在Paint中,它将复制图像.

每个外部程序都以自己的方式解析剪贴板中的数据.

希望这会有所帮助.



You will see that Word puts data in Clipboard in RTF format.

In order for you to make the same thing, you must put into clipboard RTF data format.

In your example if you paste in word, it will copy the text from Clipboard, and if you paste in Paint it will copy the Image.

Every external program parse the data from Clipboard in his own way.

Hope this helps.


这篇关于如何将图像和文本从应用程序C#复制到Microsoft Office的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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