使用 VSTO 在 Word 中动态创建的表格后插入文本
如何使用 VSTO 和 Word 2003 在创建的表格后插入文本? 我有这样的代码,
bookmarkDescriptions = (object)"bookmarkDescriptions";
Word.Range rangeDescriptions = aDoc.Bookmarks.get_Item(ref bookmarkDescriptions).Range;
foreach (var item in items)
{
//Add a paragraph with some text
Table descTable = aDoc.Tables.Add(oSelection.Range, 1, 2, ref missing, ref missing);
//Insert some text into the cells
//Add a another paragraph with some text
}
当我添加另一段文本时,它会添加到表格中,但我希望它位于表格之后。 由于我需要循环所有项目并为每个项目创建一些文本 - 段落 - 更多文本,因此我不知道如何利用书签来获取表格之后和之外的范围。
How using VSTO and Word 2003 can I insert text after a table I've created? I have code like
bookmarkDescriptions = (object)"bookmarkDescriptions";
Word.Range rangeDescriptions = aDoc.Bookmarks.get_Item(ref bookmarkDescriptions).Range;
foreach (var item in items)
{
//Add a paragraph with some text
Table descTable = aDoc.Tables.Add(oSelection.Range, 1, 2, ref missing, ref missing);
//Insert some text into the cells
//Add a another paragraph with some text
}
when I add another paragraph of text it's added within the table but I want it after the table. Since I need to loop over all items and create some text - paragraph - some more text for each of them I don't see how I could make use of a bookmark to get a range after and outside the table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚解决了这个问题。 我正在使用以下代码。
理解 Word 对象模型的最佳方法似乎是在 Word 中记录宏,然后查看源代码,了解正在执行哪些 API 调用,然后在您选择的环境中复制该调用。
I just solved the problem. I am using the following code.
The best way to make sense of the Word object model seems to be to record a macro in Word and to then look at the source code so see what API calls are being made and to then replicate that in your enviroment of choice, hth.