【问题标题】:Prevent actions to be added to the word undo redo OR Remove actions from the undo redo CommandBarComboBox阻止将操作添加到单词 undo redo 或从 undo redo CommandBarComboBox 中删除操作
【发布时间】:2012-05-22 14:15:38
【问题描述】:

我们正在以编程方式在 Word 文档中插入内容控件,并且我们不想将操作添加到 Word 的撤消堆栈中。我们找到的唯一方法是访问 undo commandbar-combobox 并删除与插入内容控制操作相关的项目,我们使用以下代码:

var commandBars = _wordDocument.CommandBars.Cast<CommandBar>();
var standardCommandBar = commandBars.First(bar => bar.Name.Equals("Standard"));
CommandBarComboBox undoControl = 
                     standardCommandBar.Controls
                     .Cast<CommandBarControl>()
                     .First(control => control.Id == 128) as CommandBarComboBox;

undoControl.RemoveItem(1);

最后一行 undoControl.RemoveItem(1) 抛出 ComException HRESULT E_FAIL

有没有办法从撤消重做组合框中删除操作?

【问题讨论】:

标签: c# interop office-interop word-2010


【解决方案1】:

由于你的问题,我遇到了和你一样的问题,但现在已经解决了。

  var commandBars = WordDoc.CommandBars.Cast<CommandBar>();
  var standardCommandBar = commandBars.First(bar => bar.Name.Equals("Standard"));
  CommandBarComboBox undoControl = standardCommandBar.Controls
                   .Cast<CommandBarControl>()
                   .First(control => control.Id == 128) as CommandBarComboBox;

您的代码将返回撤消列表中的最后一个对象。现在您可以根据自己的要求添加检查。

        if (undoControl.accName.ToLower().Contains("range.case"))
            WordApp.ActiveDocument.Undo(3);
        else if (undoControl.accName.ToLower().Contains("font.reset"))
            WordApp.ActiveDocument.Undo(2);

        else WordApp.ActiveDocument.Undo(1);

Microsoft Word

【讨论】:

    猜你喜欢
    • 2013-02-25
    • 2017-01-13
    • 1970-01-01
    • 2012-07-21
    • 1970-01-01
    • 2020-07-17
    • 2012-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多