gpt4 book ai didi

delphi - 如何在Word应用程序中将光标移动到表格末尾

转载 作者:行者123 更新时间:2023-12-03 19:50:25 29 4
gpt4 key购买 nike

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

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

为此,这些代码将不起作用:

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


和:

Selection.EndKey(wdStory, EmptyParam);


和:

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

最佳答案

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

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"

关于delphi - 如何在Word应用程序中将光标移动到表格末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34393260/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com