用 Java 打开受密码保护的 Word 文件?
假设密码已知,如何在 Java 中打开受密码保护的 Microsoft Word(.doc、.docx)文件?
How can I open a password-protected Microsoft word(.doc, .docx) file in Java, assuming that the password is known?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以用com4j试试。
http://msdn.microsoft。 com/en-us/library/microsoft.office.interop.word.documents.open2000.aspx
由于“open”方法中有一个名为“PasswordDocument”的参数,我认为可以打开一个受密码保护的文件。
希望这就是您正在寻找的内容;)
编辑:我在 Word 中录制了这个宏。
所以 com4j 中的 open 方法应该看起来像这样(密码是“Hallo”):
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.
So the open method in com4j should look somethin like this (password is "Hallo"):
Apache POI 项目是一个很好的起点,它支持 Office 97-2003 和 OOXML (2007-2010) 格式。如果您主要对从这些文件中提取文本感兴趣,您还应该查看 Tika 项目,它有一些很好的代码,例如 OfficeParser.java
您需要在第 220 行左右替换您已知的密码在 parse() 方法中:
-- 默认密码设置为最无用的密码“VelvetSweatshop”(!)
A good starting point would be the Apache POI project which supports Office 97-2003 and OOXML (2007-2010) formats. If you are mainly interested in extracting text from those files, you should also look at the Tika project that has some good code, such as OfficeParser.java
You will want to substitute in your known password(s) around line 220 in the parse() method:
-- the default password is set to the mostly useless password "VelvetSweatshop" (!)
在我们的项目中,我们使用 Aspose 来管理 Office 文档,但我们不处理受密码保护的文档,但我想这个库可以处理这种情况......
In our projects, we use Aspose to manage Office documents, but we do not deal with password-protected documents, but I imagine that this library handles such cases...