问题
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).
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);
and :
Selection.EndKey(wdStory, EmptyParam);
and :
lvParag := ActiveDocument.Paragraphs.First;
Result := Range.Sentences.First.End - 1;
回答1:
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"
来源:https://stackoverflow.com/questions/34393260/how-can-i-move-cursor-to-end-of-table-in-word-application