【问题标题】:ASP .NET OpenXML : How to create password protected word fileASP .NET OpenXML:如何创建受密码保护的 word 文件
【发布时间】:2013-01-02 07:07:08
【问题描述】:
        byte[] abc= Encoding.ASCII.GetBytes("sdf");

        DocumentProtection prot = new DocumentProtection();
        prot.Edit = DocumentProtectionValues.ReadOnly;
        prot.Hash = Convert.ToBase64String(abc);
        settings1.Append(prot);

我已经尝试了上面提到的代码,其中只读工作正常,但我遇到了使用哈希 (#) 设置密码的问题。建议我可能的方式

【问题讨论】:

  • 我什至试过 prot.Hash =Base64BinaryValue.FromString("dsf");

标签: c# asp.net c#-4.0 openxml


【解决方案1】:

试试这个:

1) 在 Visual Studio 中转到项目菜单 -> 添加引用

2) 选择“COM”标签

3) 选择“Microsoft Word(版本号)对象库”

4) 按确定。

5) 现在,在 .cs 页面中添加对该库的引用。

例如using Microsoft.Office.Interop;

6) 创建一个word文件对象并设置其密码,如下所示:

Microsoft.Office.Interop.Word._Document oDoc;
oDoc.Password = "abcd";

请不要忘记保存文档。

谢谢

如果有用请点赞并投票。

【讨论】:

  • 不要忘记保存文档,关闭文件并终止 Word 进程。
  • @VladSpreys Spreys :) 是的。谢谢。
  • 请理解,每次运行应用程序时都会打开 WORD.EXE。
  • 不要因为这个小小的不便而从 openxml 转移到 vsto 互操作!
猜你喜欢
  • 2011-02-02
  • 1970-01-01
  • 2010-09-22
  • 2016-06-07
  • 2018-12-18
  • 1970-01-01
  • 2010-10-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多