Open Microsoft Word docx file with Java

后端 未结 6 1851
灰色年华
灰色年华 2021-01-20 15:46

How can I open a Microsoft Word docx file in Java? furthermore, how can I open it if it is password protected?

For instance,

File f = new File(\"hell         


        
6条回答
  •  生来不讨喜
    2021-01-20 16:21

    If the docx is password protected, it won't be a zip file. It will be a compound file. See Overview of Protected Office Open XML Documents

    To read a compound file in Java, use POIFS. POIFS is part of POI (docx4j uses it as well, so if you download the docx4j distribution, you'll be able to use the POIFS API)

    Once you have decrypted the encrypted package, you can read it using docx4j or POI.

    Edit: OK, now docx4j can handle password-protected docx automatically.

提交回复
热议问题