在Word Interop App中插入xml文本后更改选择

时间:2014-03-31 14:37:52

标签: office-interop

我有一个单词addin,它创建了一个可以放在word文档中的字段列表。通过拖放或双击选择字段时,它会将该字段放在文档上,并在文档中创建一个xml部分。这很好。我想要做的是将单词中的选择位置移动到刚刚插入的xml部分之后。因此,如果该字段表示"日期创建",我想在"创建日期"之后将选择点移动到以下行。关于如何做到这一点的任何想法?谢谢。

1 个答案:

答案 0 :(得分:0)

我假设您使用范围插入字段? 如果是这样你可以折叠到范围的末尾然后添加你想要的。 例如:

// Move to the end
myRange.Collapse(Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseEnd);
// Now add something behind the table to prevent word from joining tables into one
myRange.InsertParagraphAfter();
//to move to the end again
myRange.Collapse(Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseEnd);
相关问题