Open Microsoft Word docx file with Java

后端 未结 6 1849
灰色年华
灰色年华 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:09

    There is Apache POI project for working with MS Office files. DOCX file is just a zip file with series of XML files inside, so you can unzip the file and work with XML. The XML spec (Open XML) is known.

    0 讨论(0)
  • 2021-01-20 16:09

    You can use docx4j too. http://www.docx4java.org/trac/docx4j

    0 讨论(0)
  • 2021-01-20 16:17

    Have you tried to open it using the Open Office api? It can work with a lot of documents types.

    I used it with MS Excel files .xls ( old version ) format.

    Hope this can help you.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-20 16:22

    I have used both docx4j and Apache's POI libraries, if you are working with .docx I would recommend .docx4j. Automated alot of the process of creating a .docx.
    There is a great exmaple here : http://java.dzone.com/articles/create-complex-word-docx on how to create a .docx using the docx4j package.

    0 讨论(0)
  • 2021-01-20 16:28

    I haven't personally used it, but it looks like Apache POI will work for you: http://poi.apache.org/

    0 讨论(0)
提交回复
热议问题