如何使用 C# 以编程方式将 Microsoft Word 注释转换为书签?
由于书签可以包含在 URL 中,因此我想将文档中的所有注释转换为书签。
我编写了 c# 应用程序,它在 Web 浏览器 Activex 控件中显示 Microsoft Word 文档。我获得了该文档的句柄并能够枚举评论。但是当我尝试在评论位置插入书签时,我最终得到了不指向任何内容的 NULL 书签,例如:
void ButtonConvertCommentsClick(object sender, EventArgs e)
{
Word.Comments wordComments = this.wordDoc.Comments;
MessageBox.Show("This document has " + wordComments.Count + " comments.");
for (int n = 1; n <= wordComments.Count; n++)
{
Word.Comment comment = this.wordDoc.Comments[n];
Word.Range range = comment.Range;
String commentText = comment.Range.Text;
this.wordDoc.Application.ActiveDocument.Bookmarks.Add("BOOKMARK"+n, range);
}
this.wordDoc.Save();
....
}
假设文档中有 3 条评论,则显示“BOOKMARK1”、“BOOKMARK2”和“BOOKMARK3”在书签列表中,但所有这些都禁用“转到...”按钮。
我做错了什么?
Since bookmarks can be included in a URL, I want to convert all the comments in a document to bookmarks.
I wrote a c# application which displays a Microsoft Word document in a web browser activex control. I get a handle to the document and am able to enumerate the comments. But when I attempt to insert bookmarks at the comment location, I end up with NULL bookmarks that don't point to anything, e.g.:
void ButtonConvertCommentsClick(object sender, EventArgs e)
{
Word.Comments wordComments = this.wordDoc.Comments;
MessageBox.Show("This document has " + wordComments.Count + " comments.");
for (int n = 1; n <= wordComments.Count; n++)
{
Word.Comment comment = this.wordDoc.Comments[n];
Word.Range range = comment.Range;
String commentText = comment.Range.Text;
this.wordDoc.Application.ActiveDocument.Bookmarks.Add("BOOKMARK"+n, range);
}
this.wordDoc.Save();
....
}
Assuming there were 3 comments in the doc, "BOOKMARK1", "BOOKMARK2" and "BOOKMARK3" shows up in the bookmark list, but the "Go To..." button is disabled for all of them.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
scope
获取评论的范围...Use
scope
to get the range of the comment...