How can I open a password-protected Microsoft word(.doc, .docx) file in Java, assuming that the password is known?
You can try it with com4j.
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.documents.open2000.aspx
Since there is a parameter called "PasswordDocument" in the "open"-method, I think it is possible to open a password protected file.
Hope this is what you were searching for ;)
Edit: I recorded this Macro in Word.
Documents.Open FileName:="test.doc", ConfirmConversions:= _
False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:= _
"hallo", PasswordTemplate:="", Revert:=False, WritePasswordDocument:= _
"hallo", WritePasswordTemplate:="", Format:=wdOpenFormatAuto
So the open method in com4j should look somethin like this (password is "Hallo"):
_Document document = app.documents().open2000(doc, false, false, false, "hallo", "", false, "hallo", "", WdOpenFormat.wdOpenFormatAuto, false, true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With