C# 设置PPT密码保护(加密、解密、编辑权限)

2025-07-22 16:06:52

保护一些重要文档,我们可以通过设置文件的打开密码或者设置文件编辑的权限来有效保护文档内容。此外,对于不再需要密码保护或者需要定期更换密码的文档,我们也可以根据需要来设置。此经验就将分享操作ppt文档密码保护的方法。

工具/原料

Free Spire.Presentation for .NET 3.3 (社区版)

Visual Studio

dll引用

1、在E-iceblue官网或者Nuget网站上下载Free Spire.Presentation for .NET的安装包后,注意在编辑代码时,添加引用Spire.Presentation.dll到程序。dll文件可在安装路径下的Bin文件夹中获取。

C# 设置PPT密码保护(加密、解密、编辑权限)

2. 设置PPT文档编辑权限

1、using Spire.Presentation;namespace EditProtection{ class Progra罪焐芡拂m { static void Main(string[] args) { //新建Presentation对象 Presentation presentation = new Presentation(); //加载文档 presentation.LoadFromFile("sample.pptx"); //设置启用编辑PPT的密码 presentation.Protect("keytoedit"); //保存并打开文档 presentation.SaveToFile("readonly.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("readonly.pptx"); } }}

2、编辑权限设置结果:

C# 设置PPT密码保护(加密、解密、编辑权限)

5.标记文档最终编辑状态

1、using Spire.Presentation;namespace Down{ class Program { static void Main(string[] args) { // 新建Presentation 对象并加载文档 Presentation ppt = new Presentation(); ppt.LoadFromFile("sample.pptx", FileFormat.Pptx2010); //标记为最终状态 ppt.DocumentProperty["_MarkAsFinal"] = true; //保存并打开文档 ppt.SaveToFile("output.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("output.pptx"); } }}

2、调试程序,生成文档:

C# 设置PPT密码保护(加密、解密、编辑权限)
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢