如何将光标的位置从c#移动到Word中的文件末尾 [英] How to Move position of cursor to end of the file in Word from c#

查看:375
本文介绍了如何将光标的位置从c#移动到Word中的文件末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,

我在C#程序中打开Microsoft应用程序的某个时刻陷入困境,然后它从C#写入一个小段落到单词,然后人们必须在段落中手动编辑一点并将光标留在该段中的任何位置,然后C#程序再次写段落,但这次C#不知道光标的位置,因为它会在段落的中间或文档中的任何位置。所以来自C#我需要知道位置光标并将其移动到该文档的最后一个字符。我知道这是可能的,但我不知道如何...

如果你们中的任何人都知道如何解决这个问题。请回复此处。





谢谢和最诚挚的问候,

Mohit。

Hello All,
I am stuck at one point where i am opening Microsoft application from C# program and then it writes small paragraph to word from C# and then person has to edit a bit manually in paragraph and leaves cursor anywhere in that paragraph and then C# program again writes paragraph but this time C# doesn't know about the position of cursor because it would be somewhere in middle of paragraph or anywhere in document.so from C# i need to know the position of cursor and move it to last character of that document. i know it's possible but i don't know how to..
If any of you know how to solve this. Please Reply here.


Thanks and Best Regards,
Mohit.

推荐答案

转到Word - 记录一个可以执行所需操作的宏 - 可能会编辑录制的内容以进行整理。



安装如果你还没有这样做,请参考Office / Word主互操作程序集的相关版本。



将录制的宏复制到VB代码中(或编辑它)在C#中做同样的事情 - 可能需要进行一些进一步的编辑,但希望不多 - 记录的VBA宏通常(根据我的经验)非常接近VB中所需的,如果你使用PIA,因为两者都转化为/包装相同的COM对象。
Go to Word - record a macro that does what you want - maybe edit what gets recorded to tidy it up.

Install and reference the relevant version of the Office / Word primary interop assemblies if you haven't done so already.

Copy the recorded macro to your VB code (or edit it to do the same in C#) - maybe some further editing might be needed, but hopefully not much - the VBA macros that get recorded are normally (in my experience) very close to what's needed in VB if you use the PIAs because both translate into / wrap the same COM objects.


object oMissing = System.Reflection.Missing.Value;
object oEoF = WdUnits.wdStory;
wordApp.ActiveWindow.Selection.EndKey(ref oEoF, ref oMissing);


尝试在codeproject中挂钩键盘,搜索windows hooks
try hooking the keyboard avaliable in codeproject, search for windows hooks


这篇关于如何将光标的位置从c#移动到Word中的文件末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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