テキスト ラン (OpenXML SDK 2.0 を使用する Docx) 内の特定のテキストを検索する方法と、それを見つけたら、「検索テキスト」を囲むコメントを挿入する方法を教えてください。「検索テキスト」は、既存のランの部分文字列にすることができます。サンプルのすべての例は、最初の段落の周りにコメントを挿入するか、そのような単純なものを挿入します...私が探しているものではありません。
ありがとう
まだ答えを探しているかもしれない誰かのために:
そのためのコードは次のとおりです。
private void AddComment( Paragraph paragraph, string text )
{
string commentId = GetNextCommentId();
Comment comment = new Comment() { Id= commentId, Date = DateTime.Now };
Paragraph commentPara = new Paragraph( new Run( new Text( GetCommentsString( text ) ) ) { RunProperties = new RunProperties( new RunStyle() { Val = "CommentReference" } ) } );
commentPara.ParagraphProperties = new ParagraphProperties( new ParagraphStyleId() { Val = "CommentText" } );
comment.AppendChild( commentPara );
_comments.AppendChild( comment );//Comments object
_comments.Save();
paragraph.InsertBefore( new CommentRangeStart() { Id = commentId }, paragraph.GetFirstChild<Run>() );
var commentEnd = paragraph.InsertAfter( new CommentRangeEnd() { Id = commentId }, paragraph.Elements<Run>().Last() );
paragraph.InsertAfter( new Run( new CommentReference() { Id = commentId } ), commentEnd );
}