【问题标题】:How can I move cursor to end of table In word application如何在word应用程序中将光标移动到表格末尾
【发布时间】:2015-12-21 22:50:04
【问题描述】:

我有一个 2 页的 Word 文档,我插入了表格,该表格从第一页开始,一直持续到第二页的中间(文档中只有一个表格)。

在 Delphi(XE7) 和 OLE 自动化(变体和 Office 2013)中,如何将光标移动到表格后? (手动在word文档文件中,我反复按回车键)

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

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

和:

Selection.EndKey(wdStory, EmptyParam);

和:

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

【问题讨论】:

  • 选择表格,然后向前移动一个字符?
  • @JanDoggen,如何选择表格或其他对象?
  • 类似Selection.Tables[1].Select; Selection.Collapse(0); // wdCollapseEnd

标签: delphi ms-word ole


【解决方案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"

【讨论】:

  • 我已将其转换为 Pascal 代码,执行此操作时,在 Set rng = tbl.Range 处引发异常“Tables is not methos”
  • Pascal 是否使用关键字 SET 为对象变量赋值?我知道 VB.NET 和 C# 不...
猜你喜欢
  • 1970-01-01
  • 2020-01-27
  • 1970-01-01
  • 2011-12-17
  • 2021-11-21
  • 1970-01-01
  • 2019-09-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多