[英]Open Both Edit and Open Passwords Protected PowerPoint Presentation
我正在嘗試找到一種方法來以編程方式打開既受開放保護又受編輯保護的演示文稿。
我確實知道如何單獨實現一個或后者,但不必處理彈出窗口 window 要求編輯密碼。
打開受保護的文件:
Presentation presentation = ppApp.Presentations.Open($"{presentationFile}::{password}::", MsoTriState.msoFalse, MsoTriState.msoFalse, WithWindow: MsoTriState.msoFalse);
要打開受編輯保護的文件:
var presentation = ppApp.ProtectedViewWindows.Open($"{presentationFile}", editPassword, MsoTriState.msoFalse);
實際問題:如何打開受打開和編輯(已知)密碼保護的演示文稿,刪除它們並保存演示文稿?”
歡迎任何建議,謝謝!
這兩種方法完全不同。
受保護視圖 window 中顯示的文件無法編輯,並且被限制運行活動內容,例如 Visual Basic for Applications 宏和數據連接。 有關受保護視圖 windows 的更多信息,請參閱什么是受保護視圖? .
ProtectedViewWindows.Open方法允許指定讀取密碼。 它打開並從ProtectedViewWindows
集合返回ProtectedViewWindow
object。 ProtectedViewWindow.Edit方法更改ProtectedViewWindow
object 的密碼。
由於受保護的視圖 window 旨在保護用戶免受潛在惡意代碼的侵害,因此您可以使用ProtectedViewWindow
object 返回的Presentation
object 執行的操作將受到限制。 不允許的操作將返回錯誤。
如果我們談論受密碼保護的文件,假設您知道密碼,您可以使用以下內容打開文件:
Presentations.Open("c:\temp\protected_presentation.pptx::password::")
並在演示文稿上設置密碼,例如:
ActivePresentation.Password = "Hide_me"
因此,例如,原始草圖:
Sub TestTest()
Dim oPPTApp As Object
Dim oPPTPres As Object
Set oPPTApp = CreateObject("PowerPoint.Application")
If Not oPPTApp Is Nothing Then
Set oPPTPres = oPPTApp.presentations.Open("C:\temp\test.pptx::opensesame::")
MsgBox oPPTPres.slides(1).Shapes(1).TextFrame.TextRange.Text
oPPTPres.Close
oPPTApp.Quit
End If
End Sub
使用Aspose.Slides for .NET ,您可以輕松移除用於演示文稿的保護。 以下代碼示例向您展示了如何執行此操作:
// Load a presentation.
var loadOptions = new LoadOptions { Password = "my_password" };
using var presentation = new Presentation("protected.pptx", loadOptions);
// Remove all protection.
presentation.ProtectionManager.RemoveEncryption();
presentation.ProtectionManager.RemoveWriteProtection();
presentation.ProtectionManager.ReadOnlyRecommended = false;
// Save the unprotected presentation to a file.
presentation.Save("unprotected.pptx", SaveFormat.Pptx);
這是一個付費圖書館,但您可以獲得臨時許可證或使用試用模式來評估所有功能。 或者,您可以使用Aspose.Slides Cloud SDK for .NET來管理演示文稿。 下面的代碼示例向您展示了如何使用 Aspose.Slides Cloud 執行相同的操作:
var slidesApi = new SlidesApi("my_client_id", "my_client_secret");
var inputFileName = "protected.pptx";
var outputFileName = "unprotected.pptx";
// Upload the protected presentation to a default storage.
using var inputStream = File.OpenRead(inputFileName);
slidesApi.UploadFile(inputFileName, inputStream);
// Remove all protection.
slidesApi.DeleteProtection(inputFileName, "my_password");
// Download the unprotected presentation and save to a file.
using var outputStream = slidesApi.DownloadFile(inputFileName);
using var resultStream = File.OpenWrite(outputFileName);
outputStream.CopyTo(resultStream);
這也是基於 REST 的付費產品,但您每月可以撥打 150 個免費的 API 電話,用於管理演示和任何目的。 我是一名支持開發人員,很樂意在Aspose.Slides 論壇上回答有關這些庫的任何問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.