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();

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

  • 相关阅读:
    【架构师必看】淘宝从百万到千万级并发的14次服务端架构演进之路
    Nginx(四)------nginx 负载均衡
    Nginx(三)------nginx 反向代理
    Nginx(二)------nginx.conf 配置文件
    Nginx(一)------简介与安装
    nginx配置ssl实现https访问
    架构设计的五大原则-SOLID
    ABP开发框架前后端开发系列
    Windows程序通用自动更新模块(C#,.NET4.5以上)
    网络通讯中粘包的处理
  • 原文地址:https://www.cnblogs.com/lecone/p/csharp-word-winWordControl.html
Copyright © 2011-2022 走看看