Page 1 of 1

Online Demo PartsList Generated Java Code

PostPosted: Mon Jun 07, 2021 9:29 pm
by gengstah
Hello,

I am trying out the Java code generated in http://webapp.docx4java.org/OnlineDemo/PartsList.html but I am getting the error below:
Word found unreadable content in helloworld.docx Do you want to recover the contents of this document? ...


I attached the template I wish to use in this post and I am saving the document like so:
Code: Select all
public class Foo {
   
   public static void main(String[] args) throws Exception {
      
      // Create the package
      WordprocessingMLPackage wordMLPackage = new WordprocessingMLPackage();
      
      // Create the main document part (word/document.xml)
      MainDocumentPart wordDocumentPart = new MainDocumentPart();
      
      // Create main document part content
      //ObjectFactory factory = Context.getWmlObjectFactory();
      //org.docx4j.wml.Body body = factory.createBody();
      org.docx4j.wml.Document wmlDocumentEl = createIt();
      //wmlDocumentEl.setBody(body);
      
      // Put the content in the part
      wordDocumentPart.setJaxbElement(wmlDocumentEl);
      
      // Add the main document part to the package relationships// (creating it if necessary)
      wordMLPackage.addTargetPart(wordDocumentPart);
      
      // Save it
      wordMLPackage.save(new java.io.File("helloworld.docx") );
      
   }
   
   public static Document createIt() {

      [...]

      return document;
   }
}


Is there anything I missed? I just copied and pasted the generated Java code from PartsListt