如何在Word应用程序中将光标移动到表格末尾 [英] How can I move cursor to end of table In word application

查看:734
本文介绍了如何在Word应用程序中将光标移动到表格末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含2页的Word文档,并且已经插入了一个表,该表从第一页开始一直持续到第二页的中间(文档中只有一个表).

I have a Word document with 2 pages and I've insert table that table start from page one and continues until the middle of the second page(Only one table exist in document).

在Delphi(XE7)和OLE自动化(版本和Office 2013)中,如何在表格后移动光标? (在Word文档文件中,我已经反复按Enter键)

In Delphi(XE7) and with OLE automation(variant and Office 2013), How can I move cursor after the table? (Manually in word document file, I have repeatedly press Enter key)

为此,这些代码将无效:

For this purpose, These codes will not work :

Selection.GoTo(wdGoToItem.wdGoToPage, wdGoToDirection.wdGoToLast);

和:

Selection.EndKey(wdStory, EmptyParam);

和:

lvParag := ActiveDocument.Paragraphs.First;
Result := Range.Sentences.First.End - 1;

推荐答案

有多种解决方法.我使用的是获取表的范围,然后折叠范围.像这样的东西(VBA,但翻译"它应该没有任何困难):

There are various ways to go about it. The one I use is to get the table's Range then collapse the Range. Something like this (VBA, but you shouldn't have any difficulty "translating" it):

Dim tbl as Word.Table, rng as Word.Range
Set tbl = ActiveDocument.Tables(1)
Set rng = tbl.Range
rng.Collapse wdCollapseEnd 'Word.WdCollapseDirection.wdCollapseEnd
'If you need to show the user the Selection
rng.Select()
'Otherwise, continue to work with the Range object, adding text, for example:
rng.Text = "text following the table"
'and formatting it
rng.Style = "style name"

这篇关于如何在Word应用程序中将光标移动到表格末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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