Page 1 of 1

Weird docx4j/word behaviour

PostPosted: Thu May 29, 2014 2:47 am
by turtle
I'm currently reviewing my "mail merge" program which gives me a NPE in getDatafieldNameFromInstr with some docx files.

Which is weird is that some problematic mergefields are wrapped in XML.

E.g. the displayed field name (in Word) is "ih16_nummerierung_stromkreis:aufgabe_dringlichkeit" where the xml content displays
<w:r>
<w:instrText xml:space="preserve"> MERGEFIELD ih1</w:instrText>
</w:r>
<w:r>
<w:instrText xml:space="preserve">6_nummerierung_stromkreis:aufgabe_dringlichkeit \* MERGEFORMAT </w:instrText>
</w:r>
This seems to puzzle docx4j :o and I wonder how to fix this problem?

Are there any switches in Word or docx4j which will change the default behavior?

Re: Weird docx4j/word behaviour

PostPosted: Thu May 29, 2014 8:24 am
by jason
There are 2 things which I'd explore:

1. whether the field being split into 2 w:instrText is causing issues; see whether the following works:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<w:r>
<w:instrText xml:space="preserve"> MERGEFIELD ih16_nummerierung_stromkreis:aufgabe_dringlichkeit \* MERGEFORMAT </w:instrText>
</w:r>
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


A split field should still work though; if it doesn't, its a bug.

2. whether the colon between stromkreis and aufgabe is causing issues.

Note that you haven't posted the complete XML for that field; it'll start earlier at fldChar, and end further on with fldChar end.

You can (should) also turn on debug level logging for the package org.docx4j.model.fields, and please, if you want help with the NPE, post the full stacktrace, and the version of docx4j you are using.

Re: Weird docx4j/word behaviour

PostPosted: Fri May 30, 2014 4:58 pm
by turtle
Thx for replying :)

As I'm (almost) a noob concerning word I didn't fully understand what I should (and how to) do in your point 1.
I'm just making a word (template) document which should be filled with some text from my program which reads the text from a database. So I don't know what a split field is or how to make word work so that the mergefield is there completeley. But I'm sure that everything would work this way, as there are a number of fields in my template which are in proper format.

I've also uploaded the complete XML for that field.

And I also uploaded my debug log.

Re: Weird docx4j/word behaviour

PostPosted: Fri May 30, 2014 5:02 pm
by turtle
Sorry, log is missing (808 kb) as maximum file size is exceeded.