gpt4 book ai didi

c# - ASP.NET OpenXML : How to create password protected word file

转载 作者:太空宇宙 更新时间:2023-11-03 17:03:29 24 4
gpt4 key购买 nike

        byte[] abc= Encoding.ASCII.GetBytes("sdf");

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

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

最佳答案

试试这个:

1) 在 vi​​sual studio 中转到 Project Menu -> Add Reference

2) 选择“COM”选项卡

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

4) 按确定。

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

例如使用 Microsoft.Office.Interop;

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

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

请不要忘记保存文档。

谢谢

觉得有用请点个赞吧

关于c# - ASP.NET OpenXML : How to create password protected word file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14118145/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com