当前位置: 移动技术网 > IT编程>开发语言>c# > C# 实现对PPT文档加密、解密及重置密码的操作方法

C# 实现对PPT文档加密、解密及重置密码的操作方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

工作中我们会使用到各种各样的文档,其中,ppt起着不可或缺的作用。一份ppt文档里可能包含重要商业计划、企业运营资料或者公司管理资料等。因此,在竞争环境里,企业重要资料的保密工作就显得尤为重要,而对于重要资料我们可以选择添加密码的形式来进行文档保护。本文将介绍如何通过c#来给ppt添加密码,当然你也可以根据需要来修改密码或者解除密码。下面将对三种操作方法进行具体讲述。

所用工具:

spire.presentation for. net

                 visual studio 2013

工具使用说明:spire.presentation for .net支持生成、写入、修改、转换、打印ppt等操作,这里我使用的是免费版的,使用前需要下载并安装,完成后需要添加引用dll文件到程序集中,同时也需添加using指令。

1.添加密码

using spire.presentation;
namespace security_ppt
{
 class program
 {
  static void main(string[] args)
  {
   //新建一个presentation类实例,并加载需要加密的文档
   presentation presentation = new presentation();
   presentation.loadfromfile(@"c:\users\administrator\desktop\test.pptx");  
   //加密文件,设置打开密码并保存文档
   presentation.encrypt("test");
   presentation.savetofile("encrypt.pptx", fileformat.pptx2007);
  }
 }
}

调试运行项目生成文件,如下图

打开文件,此时需要嵌入密码,正确输入密码后即可打开文档。

2.重置密码

using spire.presentation;
namespace resetpassword_ppt
{
 class program
 {
  static void main(string[] args)
  {
   //创建一个presentation类实例并加载已加密的文档
   presentation presentation = new presentation();
   presentation.loadfromfile(@"c:\users\administrator\desktop\encrypt.pptx", fileformat.pptx2010, "test");
   //解除原有密码,添加新密码
   presentation.removeencryption();
   presentation.protect("newtest");
   //保存文档
   presentation.savetofile("newresult.pptx", fileformat.pptx2010);
  }
 }
}

同样的,调试运行程序生成文件

打开后输入新密码,这里可以选择可修改或者以只读方式查看文件

3.解除密码

上面描述的修改密码的方法中,若只是想解除密码而不新设置密码的话,只需删除掉添加新密码,即 presentation.protect("newtest")这一行代码,调试运行后,生成的文档就没有密码保护了。

总结

以上所述是小编给大家介绍的c# 实现对ppt文档加密、解密及重置密码的操作方法,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网