如何使用C#在Word中剪切和粘贴? [英] How to do Cut and paste in Word using C#?

查看:312
本文介绍了如何使用C#在Word中剪切和粘贴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 是否可以从Word文档中剪切(不复制!)图片并将其再次粘贴?我在Google中找到的示例代码仅有助于复制和粘贴.
有人可以帮我吗?

谢谢:)

Hi Is there any option to cut (Not Copy!) a picture from the word document and paste it again? Sample code I found in the google only helped for Copy and paste.
Could somebdy help me on this?

Thanks:)

推荐答案

您可以使用Win32 SendInput方法,并将SendInput定向到Word.
通过SendInput,您可以告诉您按"CTRL",然后按"X",然后释放"X"和"CTRL",模拟Cut的CTRL + X.

http://www.pinvoke.net/default.aspx/user32/sendinput.html [ ^ ]
You can use Win32 SendInput method, and direct your SendInput to Word.
Via SendInput you can tell that you what to press "CTRL", then "X" and release "X" and "CTRL", simulating a CTRL+X for Cut.

http://www.pinvoke.net/default.aspx/user32/sendinput.html[^]


为正在使用的Office/Word版本安装主互操作程序集.
在您的项目中添加对Word PIA的引用.
现在,您可以直接从C#代码控制Word.
代码的结构几乎与您在Word本身中编写VBA宏相同-在VB.NET中,即使语法非常接近,但对于C#,您必须做一些编辑.
因此,要快速入门,请转到Word,记录一个宏以执行所需的操作并查看它.
现在,在您的C#代码中复制它的功能.
Install Primary Interop Assemblies for whichever version of Office / Word you are using.
Add a reference to the Word PIA in your project.
You can now control Word directly from your C# code.
The structure of your code will be pretty much the same as if you''d written a VBA macro within Word itself - in VB.NET, even the syntax will be pretty close, but for C# you''ll have to do a bit of editing.
So to get a quick start, go to Word, record a macro to do what you want and look at it.
Now replicate what it does in your C# code.


这篇关于如何使用C#在Word中剪切和粘贴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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