Convert DOC file to DOCX with Java

前端 未结 7 1956
天涯浪人
天涯浪人 2021-02-20 12:43

I need to use DOCX files (actually the XML contained in them) in a Java software I\'m currently developing, but some people in my company still use the DOC format.

Do yo

7条回答
  •  误落风尘
    2021-02-20 13:24

    I needed the same conversion ,after researching a lot found Jodconvertor can be useful in it , you can download the jar from https://code.google.com/p/jodconverter/downloads/list

    Add jodconverter-core-3.0-beta-4-sources.jar file to your project lib

      //1) Create OfficeManger Object     
    OfficeManager officeManager = new DefaultOfficeManagerConfiguration()
                    .setOfficeHome(new File("/opt/libreoffice4.4"))
                    .buildOfficeManager();
            officeManager.start();
        // 2) Create JODConverter converter   
            OfficeDocumentConverter converter = new OfficeDocumentConverter(
                    officeManager);
    // 3)Create DocumentFormat for docx
    DocumentFormat docx = converter.getFormatRegistry().getFormatByExtension("docx");
            docx.setStoreProperties(DocumentFamily.TEXT,
                    Collections.singletonMap("FilterName", "MS Word 2007 XML"));
    //4)Call convert funtion in converter object
    converter.convert(new File("doc/AdvancedTable.doc"), new File(
                    "docx/AdvancedTable.docx"), docx);
    

提交回复
热议问题