简体   繁体   中英

Open password protected document in application level add in

Is there a way of opening password protected Word and Excel files without manually entering password when developing an application or document level VSTO Add-in. In other words, how do I set the password programmatically.

I have tried to do it in the document open event but it is invoked after opening document.

Is there an event which is invoked before the document gets opened?

Basically what I want to achieve is avoid opening the document outside the my Add in

Yes there is - look at documentation here . Basically - you need to pass the password, when opening the document instead of relying on events.

For Word:

var WordApp = new Word.Application();
WordApp.Documents.Open("[your doc path].docx", ReadOnly: false, Password: "[your password]")

For Excel:

var ExcelApp = new Excel.Application();
ExcelApp.Workbooks.Open("[your doc path].xslx", ReadOnly: false, Password: "[your password]")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM