使用应用程序级加载项,我在打开文档时执行一些操作,这些操作需要将修订(跟踪的更改)呈现为内联而不是隐藏,以便它们包含在Range
文档中。查阅文档后,我认为我所要做的就是更改活动窗口的视图属性MarkupMode
:声称做我想做的事。
但是这个属性似乎与文档中的修订显示方式完全脱节!为了测试这一点,我尝试在文档中手动切换模式,然后在事件处理程序MarkupMode
中查看并立即检查它。onSelectionChange
我继续跟踪了 的一堆属性ActiveWindow.View
,这是很好的衡量标准。令我惊讶和懊恼的是,当我查看具有内联更改的本地人时:
...并将值与隐藏更改的值进行比较:
没有改变!是什么赋予了?我是否没有查看正确的属性以确保内联呈现更改?Microsoft 是否完全无法编写有意义的文档?我会指出,我也尝试在代码中更改属性,以查看修订的呈现是否会更改,但没有成功。我将不胜感激任何反馈。
编辑:复制问题的简单代码:
private void ThisAddIn_Startup(object sender, EventArgs e)
{
Application.WindowSelectionChange += application_WindowSelectionChange;
}
private void application_WindowSelectionChange(Selection sel)
{
var testDoc = sel.Document;
var test = new
{
testDoc.ActiveWindow.View,
testDoc.ActiveWindow.View.ShowRevisionsAndComments,
testDoc.ActiveWindow.View.ShowInsertionsAndDeletions,
testDoc.ActiveWindow.View.MarkupMode,
testDoc.ActiveWindow.View.RevisionsMode
};
}
编辑 2:除了这个人为的示例之外,我需要控制修订的标记样式,因为我正在搜索可能包含作为对象DocumentOpen
存在的文本的文本。Revision
更具体地说,我正在尝试使用上述文本执行以下操作(在修订中删除了文本“帮助您证明的强大方法”):
private void ThisAddIn_Startup(object sender, EventArgs e)
{
Application.DocumentOpen += application_DocumentOpen;
}
private void application_DocumentOpen(Document doc)
{
// expected text, as taken from screengrab example above. Includes
// text removed in a revision
string expectedText = "Video provides a powerful way to help you prove your point.";
// make sure that we're in print view
if (doc.ActiveWindow.View.Type != WdViewType.wdPrintView)
{
doc.ActiveWindow.View.Type = WdViewType.wdPrintView;
}
// attempt to ensure that document revisions are marked up inline. Does not accomplish anything
doc.ActiveWindow.View.MarkupMode = WdRevisionsMode.wdInLineRevisions;
// attempt to locate text. Will fail if revisions are not marked up inline (deletion is not part of document content range otherwise)
var locatedRange = doc.Content.OccurrenceOfText(expectedText);
}
// extension method to locate text inside a range. Searching entire Content in this example
private static Range OccurrenceOfText(this Range rng, string text)
{
rng.Find.Forward = true;
rng.Find.Format = false;
rng.Find.Execute(text);
if (!rng.Find.Found)
{
throw new Exception("Unable to locate text! Are Revisions marked up inline?");
}
// return brand new range containing located content
return rng.Document.Range(rng.Start, rng.End);
}
编辑 3:正如 Cindy 所说,我的问题是我使用了错误的属性:我需要使用该View.RevisionsFilter.Markup
属性进行更改。此外,我没有诊断出的一个问题是,根据 View 属性,完全有可能Range
像我一样执行的搜索返回的Text
属性与搜索的文本不同。如果Revision
对象存在于Range
.