Page 1 of 1

Word, first Binding, Beginner

PostPosted: Fri Feb 21, 2014 4:22 am
by nicky
Hello,

i'm new with docx4j and i had a look at some samples and played a little bit with it. My goal is to substitute fields in an effictive and for the user simple way. The user should be able create his word documents and i replace some data in this field and create pdf-Files out of it. Docx4J seems to be the perfect solution for it.

I tried the ContentControlsApplyBindings and it worked fine. I created a docx-File by the sample source, changed some content in den word-document and the xml-File (invoice-data.xml)... then i tried to create my own docx-File and fill it with data, like in the sample. But it doesn't work... and i don't understand why.

How did i create the input-docx File:
  • First i created a docx-File with Word 2013
  • Then i opened the developer mode and inserted an "only text content control field"
  • After that i added the xml-File (invoice-data.xml) as XML mapping
  • At the end i bind an element of the invoice-data.xml to my content control field.
After that i startet the sample with my new input file again but i got this exception:
Exception in thread "main" org.docx4j.openpackaging.exceptions.Docx4JException: Couldn't find CustomXmlDataStoragePart! exiting..
at org.docx4j.Docx4J.bind(Docx4J.java:299)
at org.docx4j.Docx4J.bind(Docx4J.java:275)
at org.docx4j.samples.ContentControlBindingExtensions.main(ContentControlBindingExtensions.java:99)


What's wrong? What did i miss? The sample ContentControlsMergeXML also doesn't work in my workspace... thank you very much in advance for your support.

Environment:
  • Java 7
  • Windows 7 64bit
  • Winword 2013
  • docx4J 3.0.2-SNAPShot

Re: Word, first Binding, Beginner

PostPosted: Fri Feb 21, 2014 9:05 pm
by nicky
In CustomerXmlDataStoragePartSelector.java in line 66 wordMLPackage.getMainDocumentPart().getXPathsPart() returns null.

How can i set the XPathsPart in a word-Document?

At the moment i set my xpath with a visual basic macro by using the tags of the content control fields. The VB-Code looks like this:
Code: Select all
For counter = 1 To ActiveDocument.ContentControls.Count
        ActiveDocument.ContentControls(counter).XMLMapping.SetMapping ActiveDocument.ContentControls(counter).Tag
Next counter


Anybody an idea what's wrong?

Re: Word, first Binding, Beginner

PostPosted: Fri Feb 21, 2014 9:59 pm
by jason
Please try http://www.docx4java.org/docx4j/docx4j- ... 140221.jar

It contains a couple of fixes as a result of your feedback, so things work when the OpenDoPE parts aren't present (which is probably a less common use case / code path)

Re: Word, first Binding, Beginner

PostPosted: Fri Feb 21, 2014 10:36 pm
by nicky
Now it works :) Just did a small test, will continue testing on Monday. Thank's a lot!

Re: Word, first Binding, Beginner

PostPosted: Tue Feb 25, 2014 12:03 am
by nicky
Ok, this easy stuff now works. I tried different examples.

I also switched my word version. Now i'm using Word2010 and the XmlMappingTaskPane-AddIn for word. The xml-binding is now done in word by the XML-Mapping View of the XmlMappingTaskPane-AddIn. So an office user can map the xml to the content controls easily.

I'd like to have the same easy way for loops... so i just tried to change the example-tag od:repeat=x2 to od:repeat:/invoice/items/item So i don't want to create an extra xpath-xml, upload it into the word-file and access the variables. I want to do it direct, without an extra xpath xml. Is this possible? Thanks a lot in advance.

BR

Re: Word, first Binding, Beginner

PostPosted: Tue Feb 25, 2014 12:49 am
by nicky
Ok, i found the OpenDope Word AddIn (http://opendope.codeplex.com/documentation), with this it should work.

Re: Word, first Binding, Beginner

PostPosted: Tue Feb 25, 2014 8:18 am
by jason
The stuff on codeplex is old/out-of-date.

You'd be better off using one of the authoring tools at http://www.opendope.org/implementations.html