Page 1 of 1

Issue loading Word 2013 docx

PostPosted: Fri Oct 24, 2014 5:43 am
by mistahmikey
A complete noob here. Tried to use the following code to load up a 2013 docx:

Code: Select all
package myartifact;

import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.apache.log4j.BasicConfigurator;

public class HelloMavenCentral {

   public static void main(String[] args) throws Exception {

      BasicConfigurator.configure();
      
      WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
      String filename = "C:\\Users\\Mike\\Desktop\\My.docx";

      wordMLPackage.load(new java.io.File(filename) );

   }
}


Bombs out trying to find the "officeDocument" relationship type. There is a hard coded check for:

http://schemas.openxmlformats.org/offic ... ceDocument

but what appears in the relationship specification for the actual document is:

http://purl.oclc.org/ooxml/officeDocume ... ceDocument


Here is the problematic code:

Code: Select all
package org.docx4j.openpackaging;

import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.parts.relationships.RelationshipsPart;
import org.docx4j.relationships.Relationship;

public class PackageRelsUtil { 
   
   public static String getNameOfMainPart(RelationshipsPart packageRels) throws Docx4JException  {
      
      // find rel of type officeDocument
      for (Relationship rel : packageRels.getRelationships().getRelationship() ) {
         
         if (rel.getType().equals(
               "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument") ) {
            return rel.getTarget();
         }
      }
      throw new Docx4JException("No relationship of type officeDocument");
   }
   
}


Let me know if there is anything I can do to avoid this.

Thanks.

Re: Issue loading Word 2013 docx

PostPosted: Fri Oct 24, 2014 6:19 am
by jason
Could you please attach your sample docx? Was it created in Word 2013, or some other way?