[英]How can I programmatically convert Microsoft Word comments to bookmarks using C#?
由于书签可以包含在URL中,因此我想将文档中的所有注释都转换为书签。
我编写了一个ac#应用程序,该应用程序在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”,但是对所有注释都禁用了“转到...”按钮。
我究竟做错了什么?
使用scope
获取注释的范围...
for (int n = 1; n <= wordComments.Count; n++)
{
Word.Comment comment = this.wordDoc.Comments[n];
Word.Range range = this.wordDoc.Range(comment.Scope.Start, comment.Scope.End);
String commentText = comment.Range.Text;
this.wordDoc.Application.ActiveDocument.Bookmarks.Add("BOOKMARK"+n, range);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.