在 Microsoft.Office.Interop.Word 中使用 Selection.Find 查找文档中的跟踪更改
我目前正在 VB.Net 应用程序中使用下面的代码来查找 Word 文档中的特定文本。 文本周围是由 .Text 语句中的字符代码表示的符号。 下面的代码工作正常。 现在的问题是,有时文档中所需的文本已被标记为删除,并在文档中显示为跟踪的更改。 我只想查找尚未标记为删除的所需文本。 有谁知道如何确定找到的文本是否删除?
xSelection.MoveStart(Word.WdUnits.wdStory)
xSelection.Find.ClearFormatting()
xSelection.Find.Replacement.ClearFormatting()
With xSelection.Find
.Text = ChrW(65000) & "( \[*)" & ChrW(65001)
.Replacement.Text = ""
.Forward = True
.Wrap = Word.WdFindWrap.wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchFuzzy = False
.MatchWildcards = True
End With
xSelection.Find.Execute(Replace:=Word.WdReplace.wdReplaceNone)
Do While xSelection.Find.Found
........Execute additional code here
Loop
I am currently using the code below within a VB.Net application to find specific text in a Word document. The text is surrounded by symbols represented by the character codes in the .Text statement. The code below is working fine. The issue now is that sometimes the desired text within a document has been marked for deletion and appears as tracked change within the document. I would like to find only the desired text that has NOT been marked for deletion. Does anyone know of a way to determine if the found text is a deletion?
xSelection.MoveStart(Word.WdUnits.wdStory)
xSelection.Find.ClearFormatting()
xSelection.Find.Replacement.ClearFormatting()
With xSelection.Find
.Text = ChrW(65000) & "( \[*)" & ChrW(65001)
.Replacement.Text = ""
.Forward = True
.Wrap = Word.WdFindWrap.wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchFuzzy = False
.MatchWildcards = True
End With
xSelection.Find.Execute(Replace:=Word.WdReplace.wdReplaceNone)
Do While xSelection.Find.Found
........Execute additional code here
Loop
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对我来说,在搜索之前将修订视图设置为最终视图是有效的。 然后只找到最终版本中可见的文本(您可以备份以前的值并在搜索完成后恢复视图):
完整代码:
For me it works to set the revision view to final prior to searching. Then only text visible in the final revision is found (You can backup the previous value and restore the view after your search is done):
Full code:
我最终循环遍历每个修订版本并更改已删除修订版本的字体颜色,以将它们与未删除的注释区分开来,如下所示:
然后我可以进行查找并根据其字体颜色以不同的方式处理找到的注释:
I ended up looping thru each revision and changing the font color of deleted revisions to differentiate them from non-deleted comments like so:
Then I can do the find and treat the found comments differently depending on their font color:
在搜索或处理 Word 文档之前尝试关闭显示修订:
它会保留文档中的更改跟踪(如果存在),但让您仅查看和处理最新内容,而不进行任何删除等。
Try to switch off showing revisions prior to searching or processing your Word document:
It preserves the change tracking in the document if present, but lets you to see and cope only with the newest content, without e.g. any deletions, etc..