C# word API中带有轨迹更改的范围对象

C# word API中带有轨迹更改的范围对象,c#,ms-word,office-interop,C#,Ms Word,Office Interop,我正在努力处理Word API中的Range对象,尤其是与轨迹更改相结合 我构建了一个解决方案,其中一个用户可以选择word文档中的文本。我使用数据库存储这些选定单词/句子的开始和结束位置。当用户打开文档时,这些单词将突出显示。但是,如果我们开始更改轨迹,这些范围将不再映射到文档中的正确位置。我真的找不到一个方法来做这个映射,非常感谢你的帮助。有没有办法做到这一点 我已经尝试了很多东西: _wordDocument.ShowRevisions = false; _wordDocument.Tra

我正在努力处理Word API中的Range对象,尤其是与轨迹更改相结合

我构建了一个解决方案,其中一个用户可以选择word文档中的文本。我使用数据库存储这些选定单词/句子的开始和结束位置。当用户打开文档时,这些单词将突出显示。但是,如果我们开始更改轨迹,这些范围将不再映射到文档中的正确位置。我真的找不到一个方法来做这个映射,非常感谢你的帮助。有没有办法做到这一点

我已经尝试了很多东西:

_wordDocument.ShowRevisions = false;
_wordDocument.TrackRevisions = false;
_wordDocument.TrackFormatting = false;
_wordDocument.TrackMoves = false;

_wordDocument.ActiveWindow.View.RevisionsView = WdRevisionsView.wdRevisionsViewOriginal;
_wordDocument.ActiveWindow.View.ShowRevisionsAndComments = false;
_wordDocument.ActiveWindow.View.ShowInsertionsAndDeletions = false;

_wordDocument.Saved = false;
_wordDocument.Save();

//Do what we need to do
range = _wordDocument.Range(ref startRange, ref endRange);

string theTextInRange = range.Text;
MessageBox.Show("Text in range: " + theTextInRange);

_wordDocument.Bookmarks.Add(string.Format(CultureInfo.InvariantCulture, "_{0}", commentViewModel.CommentId), range);

//Revert back (do after)
_wordDocument.ShowRevisions = _lastShowRevisions;
_wordDocument.TrackRevisions = true;
_wordDocument.TrackFormatting = _lastTrackFormatting;
_wordDocument.TrackMoves = true;

_wordDocument.ActiveWindow.View.RevisionsView = WdRevisionsView.wdRevisionsViewFinal;
_wordDocument.ActiveWindow.View.ShowRevisionsAndComments = true;
_wordDocument.ActiveWindow.View.ShowInsertionsAndDeletions = true;

_wordDocument.Saved = false;
_wordDocument.Save();
如您所见,我在下次打开文档时使用书签硬存储注释的位置,但是,如果用户同时更改了文档,那么这个范围就不再映射了。我的实现支持多个副本,这意味着用户B可以突出显示复制版本中的内容,并且这些高亮显示也显示在文档B中,我们尝试创建书签,就像我在上面的代码中显示的那样