简体   繁体   English

Delphi Word自动化:如何在表后插入文本?

[英]Delphi Word automation: how to insert text after a table?

I have a Microsoft Word document with a table in it. 我有一个带有表格的Microsoft Word文档。 My problem is that I need some text after the table but when I use Selection.TypeText(Text) after the table, the text is shown inside the table and not after/outside the table. 我的问题是我需要在表之后使用一些文本,但是当我在表之后使用Selection.TypeText(Text) ,文本显示在表内,而不是在表之后/之外。 How can I insert text after the table? 如何在表格后面插入文字?

Code shown below: 代码如下所示:

Table := MSWord.ActiveDocument.Tables.Add(MSWord.Selection.Range, 2, 1);
Table.Cell(1, 1).Range.Text := 'GreenDay';
Table.Cell(2, 1).Range.Text := 'Kiss';
MSWord.Selection.TypeText('cdassda');

My second problem is that I am not able to append data to a new page: 我的第二个问题是我无法将数据附加到新页面:

MSWord.Selection.Goto(wdGoToPage, wdGoToLast);

Try this: 尝试这个:

Table.Cell(1, 1).Range.Text := 'GreenDay';
Table.Cell(2, 1).Range.Text := 'Kiss';
MSWord.Selection.EndKey( Unit:=wdStory);
MSWord.Selection.TypeParagraph;
MSWord.Selection.TypeText('cdassda');

Regarding your second point, this works for me: 关于你的第二点,这对我有用:

//MSWord.Selection.Goto(wdGoToPage, wdGoToLast);

MSWord.Selection.EndKey( Unit:=wdStory );
MSWord.Selection.InsertBreak( Type:=wdPageBreak);

MSWord.Selection.TypeText('next page');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM