将光标定位在 Word 文档的开头/结尾 [英] Position cursor at start/end of Word document

查看:24
本文介绍了将光标定位在 Word 文档的开头/结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 Word Interop 从 .Net 处理我们的 Word 2007 文档.主要是用字段做的事情:

We are manipulating our Word 2007 documents from .Net using Word Interop. Mostly doing stuff with fields as in:

For Each f In d.Fields
    f.Select()
    //do stuff with fields here            
Next

这会留下所选文档中的最后一个字段.

This leaves the last field in the document selected.

因此,为了简洁起见,我们希望将光标定位在文档的结尾(甚至开头也可以).

So, for the sake of neatness we would like to position the cursor at the end of the document (or even the start would be OK).

在谷歌上搜索答案并没有太多结果......我能得到的最接近的似乎是建议我们需要让自己参与范围或书签.Document 对象有一个 GoTo 方法,但它提供的 WdGoToItem 选项都没有用.

Googling for the answer doesn't throw up much ... the nearest I can get seems to be suggesting we need to involve ourselves with ranges or bookmarks. There's a GoTo method for the Document object but none of the WdGoToItem options it offers are useful.

难道没有一种简单的方法可以将光标发送到文档的末尾(或开头)吗?

Isn't there a simple way to just send the cursor to the end (or start) of document?

编辑

我的部分问题是我不喜欢选择最后一个字段.现在意识到我可以做到

Part of my problem was I didn't like leaving the last field selected. Have now realised that I can do

f.Unlink

删除 mergefield 并将字段文本保留为纯文本.哪个更整洁,我们是否也重新定位光标

to remove the mergefield and just leave the field text there as plain text. Which is neater, whether or not we also reposition the cursor

推荐答案

@Alexander Kojevnikov:感谢您的帮助,因为您让我走上了正轨.但是我发现我必须将 .GoTo 应用于 Word Selection 对象,而不是文档.如:

@Alexander Kojevnikov: Thanks for your help because you put me on the right track. However I found I had to apply the .GoTo to the Word Selection object, not the Document. As in:

    Dim what As Object = Word.WdGoToItem.wdGoToLine
    Dim which As Object = Word.WdGoToDirection.wdGoToLast

    //below line had no effect
    //d.GoTo(what, which, Nothing, Nothing)

    w.Selection.GoTo(what, which, Nothing, Nothing)

这篇关于将光标定位在 Word 文档的开头/结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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