C# 如何编程从docx检索标记的条目

C# 如何编程从docx检索标记的条目,c#,vb.net,ms-word,ms-office,C#,Vb.net,Ms Word,Ms Office,如何从docx文档中检索标记的条目(通过按Alt+Shift+X进行标记。Word显示“标记索引条目”对话框)?我需要在中标识它并替换为特定内容。 我手动在ms word中创建标记条目,但我需要以某种方式检索它 我所尝试的: var wordApp = new Application(); wordApp.Visible = true; var docxDocument = wordApp.Documents.Open(filePath);

如何从docx文档中检索标记的条目(通过按Alt+Shift+X进行标记。Word显示“标记索引条目”对话框)?我需要在中标识它并替换为特定内容。 我手动在ms word中创建标记条目,但我需要以某种方式检索它

我所尝试的:

var wordApp = new Application();
wordApp.Visible = true;
var docxDocument = wordApp.Documents.Open(filePath);                           
var indexes= docxDocument.Indexes; // empty collection

我发现更好的解决方案是使用书签。 更改书签内容的示例:

var wordApp = new Application();
wordApp.Visible = true;
var docxDocument = wordApp.Documents.Open(filePath);

var bookmark = wordApp.ActiveDocument.Bookmarks["MyBookmark"];                     
Range range = bookmark.Range;
range.Text = "My new text\n";
object rng = range;
var newBookmark = wordApp.ActiveDocument.Bookmarks.Add("NewBookmark", ref rng);

如果您对纯文本感兴趣,那么(手动)将其放入剪贴板怎么样?然后在你的应用程序中处理剪贴板(比较,替换,…),而不仅仅是通过剪贴板将其插入MS Word。谢谢,但我的意思是通过在MS Word中按Alt+Shift+X进行标记