工作中我們會使用到各種各樣的文檔,其中,ppt起著不可或缺的作用。一份ppt文檔里可能包含重要商業計劃、企業運營資料或者公司管理資料等。因此,在競爭環境里,企業重要資料的保密工作就顯得尤為重要,而對于重要資料我們可以選擇添加密碼的形式來進行文檔保護。本文將介紹如何通過c#來給ppt添加密碼,當然你也可以根據需要來修改密碼或者解除密碼。下面將對三種操作方法進行具體講述。
所用工具:
spire.presentation for. net
visual studio 2013
工具使用說明:spire.presentation for .net支持生成、寫入、修改、轉換、打印ppt等操作,這里我使用的是免費版的,使用前需要下載并安裝,完成后需要添加引用dll文件到程序集中,同時也需添加using指令。
1.添加密碼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
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.重置密碼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
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文檔加密、解密及重置密碼的操作方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:http://www.cnblogs.com/Yesi/archive/2017/11/23/7885063.html