2015-12-21 48 views
1

我有一個Word文檔有2頁,並且我已經插入了表格,該表格從第一頁開始並持續到第二頁的中間(只有一個表格存在於文件)。在Delphi(XE7)和OLE自動化(變體和Office 2013)中,如何在表後移動光標? (手動在Word文檔文件,我曾多次按回車鍵)如何將光標移動到表格的末尾在word應用程序

爲此,這些代碼將無法正常工作:

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

和:

Selection.EndKey(wdStory, EmptyParam); 

和:

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

選擇表,然後向前移動一個字符? –

+0

@JanDoggen,如何選擇表格或其他對象? – Mohamad

+1

類似'Selection.Tables [1] .Select; Selection.Collapse(0); // wdCollapseEnd' – kobik

回答

2

有很多種方法可以去做。我使用的是獲取表格的範圍然後摺疊範圍。像這樣的東西(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" 
+0

我已經將它轉換爲Pascal代碼,當執行此操作時,在Set rng = tbl.Range 0123處提示一個異常「Tables is not methos」 – Mohamad

+0

Pascal是否使用關鍵字SET將某些內容分配給對象變量?我知道VB.NET和C#不... –

相關問題