问题
Problem
The following code works for .docx files with password upto 15 characters:
using Word = Microsoft.Office.Interop.Word;
var app = new Word.Application();
var doc = app.Documents.Open("file.docx", PasswordDocument: "<short password>");
For longer password the .Open method fails with COMExcetion of message: "Command failed".
Question(s)
With longer password, how can I:
Encrypt/decrypt word files?
Recognize that given password opens the file?
(optionally) Open the file in Microsoft Word application programmatically?
Along with the links also sample code would be greatly appreciated.
Notes
Tried in all versions of Microsoft.Office.Interop.Word.dll: 12.0.0.0, 14.0.0.0 and 15.0.0.0
Spire.Doc seems to be solving points 1. and 2., but it is commercial and free version is pretty limited.
来源:https://stackoverflow.com/questions/27820525/cannot-open-decrypt-encrypt-docx-with-password-longer-than-15-characters-in-ne