zoukankan      html  css  js  c++  java
  • c#实现word,winWordControl 文档不允许复制、粘贴、隐藏工具栏、快捷保存

    1.隐藏工具栏

    //隐藏工具栏
    for (int i = 1; i <= winWordControl1.document.CommandBars.Count; i++) { winWordControl1.document.CommandBars[i].Enabled = false;//置灰
    winWordControl1.document.CommandBars[i].Visible = false;//不可见
    }

    本语句完成的功能是对整体工具条的隐藏,如:常用,格式等工具条,而工具条内具体的功能点隐藏如下:

     for(int i=1;i<=winWordControl1.document.ActiveWindow.Application.CommandBars["Standard"].Controls.Count;i++)
    {
    if ("打印(&P)打印预览(&V)".IndexOf(winWordControl1.document.ActiveWindow.Application.CommandBars["Standard"].Controls[i].Caption)!=-1) { winWordControl1.document.ActiveWindow.Application.CommandBars["Standard"].Controls[i].Enabled = true; } else { winWordControl1.document.ActiveWindow.Application.CommandBars["Standard"].Controls[i].Enabled = false; winWordControl1.document.ActiveWindow.Application.CommandBars["Standard"].Controls[i].Visible = false; } }

    本代码实现“常用”工具条,打印和打印预览显示、可操作。

    2.不允许复制、粘贴

      object missing = Type.Missing;
      if (winWordControl1.document.Application.ActiveDocument.ProtectionType == Word.WdProtectionType.wdNoProtection)
      {
          winWordControl1.document.Application.ActiveDocument.Protect(Word.WdProtectionType.wdAllowOnlyFormFields, ref missing, ref missing);
      }

    3.屏蔽快捷键方式

    //不允许快捷键保存
    int keyControl = winWordControl1.document.Application.BuildKeyCode(Word.WdKey.wdKeyControl, ref  missing, ref  missing, ref missing);
    int cKey = winWordControl1.document.Application.BuildKeyCode(Word.WdKey.wdKeyS, ref  missing, ref  missing, ref missing);
    winWordControl1.document.Application.get_FindKey(keyControl | cKey, ref missing).Disable();

    屏蔽其他的快捷键参考上面代码就可。

  • 相关阅读:
    20165214 第八周学习任务
    20165214 实验二 Java面向对象程序设计
    20165214 结队编程项目-四则运算
    20165214 第七周学习任务
    20165214 第六周学习任务
    20165214 实验一 Java开发环境的熟悉
    20165313 《Java程序设计》第八周学习总结
    结对编程-四则运算
    2017-2018-2 20165313实验二《Java面向对象程序设计》
    20165313 《Java程序设计》第七周学习总结
  • 原文地址:https://www.cnblogs.com/lecone/p/csharp-word-winWordControl.html
Copyright © 2011-2022 走看看