Page 1 of 1

Can't add new row with repeat content controll

PostPosted: Fri Jul 31, 2015 10:41 pm
by Ben1980
Hi,
i am new to docx4j and openDoPE .
I have a template docx file which i have to populate with data. I use Content Control Toolkit to add the binding.

cctoolkit.png
toolkit
cctoolkit.png (103.94 KiB) Viewed 4743 times

To fill the template with data i use the ContentControlsMergeXML example which works ok.
But the problem is that it adds only the one exisitng row to the tables (see Off66394.docx).
How do i add more rows to the table?
I thought manipulating the custom.xml (see code below) and binding it to the template file would be sufficient.

Code: Select all
<dok>
  <Text1>Wow
  </Text1>
  <Text2>Wow2
  </Text2>
  <Table1>
    <items>
      <item>
        <Table1Col1>AA
        </Table1Col1>
        <Table1Col2>BB
        </Table1Col2>
        <Table1Col3>CC
        </Table1Col3>
      </item>
      <item>
        <Table1Col1>AAA
        </Table1Col1>
        <Table1Col2>BBB
        </Table1Col2>
        <Table1Col3>CCC
        </Table1Col3>
      </item>
    </items>
  </Table1>
  <Table2>
    <items>
      <item>
        <Table2Col1>AA
        </Table2Col1>
        <Table2Col2>BB
        </Table2Col2>
        <Table2Col3>CC
        </Table2Col3>
      </item>
      <item>
        <Table2Col1>AAA
        </Table2Col1>
        <Table2Col2>BBB
        </Table2Col2>
        <Table2Col3>CCC
        </Table2Col3>
      </item>
    </items>
  </Table2>
</dok>


What am i doing wrong?

Re: Can't add new row with repeat content controll

PostPosted: Fri Jul 31, 2015 11:28 pm
by jason
If you want to do repeats (or conditions, or various other things), you need to use one of the OpenDoPE addins, not the content control toolkit.

Or if you have Word 2013, you can use the repeat content controls and the mapping tool baked into that. But you'll need docx4j 3.2.2 (currently in beta) to process those, and I wouldn't recommend this approach; see http://www.docx4java.org/blog/2015/01/w ... rime-time/

You might also be interested in http://www.docx4java.org/blog/2015/01/i ... -now-what/

Re: Can't add new row with repeat content controll

PostPosted: Sat Aug 01, 2015 12:24 am
by Ben1980
Thanks, that helped allready a lot.
But still i only get 2 rows instead of 3.
Itonly writes data whichis allready define at item1.xml.
Is the bind methd not exchanging them?

Code: Select all
<dok>
   <text_A>text_A</text_A>
   <text_B>text_B</text_B>
   <Table_A>
      <lines>
         <lineitem>
            <col1>A</col1>
            <col2>B</col2>
            <col3>C</col3>
         </lineitem>
         <lineitem>
            <col1>AA</col1>
            <col2>BB</col2>
            <col3>CC</col3>
         </lineitem>
         <lineitem>
            <col1>AAA</col1>
            <col2>BBB</col2>
            <col3>CCC</col3>
         </lineitem>
      </lines>
   </Table_A>
   <text_C>text_C</text_C>
   <Table_B>
      <lines>
         <lineitem>
            <col1>A</col1>
            <col2>B</col2>
            <col3>C</col3>
         </lineitem>
         <lineitem>
            <col1>AA</col1>
            <col2>BB</col2>
            <col3>CC</col3>
         </lineitem>
         <lineitem>
            <col1>AAA</col1>
            <col2>BBB</col2>
            <col3>CCC</col3>
         </lineitem>
      </lines>
   </Table_B>
</dok>

Re: Can't add new row with repeat content controll

PostPosted: Sat Aug 01, 2015 7:10 am
by jason
What does your code look like?

Re: Can't add new row with repeat content controll

PostPosted: Sun Aug 02, 2015 9:54 pm
by Ben1980
My code looks like this:

Code: Select all
WordprocessingMLPackage wordProcessor = WordprocessingMLPackage.load(template);       
String input_XML = "/home/Ben/Dokumente/input.xml";

try {
    FileInputStream xmlStream = new FileInputStream(new File(input_XML));
    Docx4J.bind(wordProcessor, xmlStream, Docx4J.FLAG_BIND_INSERT_XML | Docx4J.FLAG_BIND_BIND_XML);
} catch (FileNotFoundException e) {
    e.printStackTrace();
}
wordProcessor.save(filename);

Re: Can't add new row with repeat content controll

PostPosted: Mon Aug 03, 2015 11:50 pm
by jason
Your docx is using w15 repeats:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
      <w:sdt>
        <w:sdtPr>
          <w:alias w:val="w15 repeatingSection /dok[1]/Table_A[1]/lines[1]/lineitem[1]"/>
          <w:id w:val="1291631503"/>
          <w15:dataBinding w:prefixMappings="" w:xpath="/dok[1]/Table_A[1]/lines[1]/lineitem" w:storeItemID="{9ABA7121-9348-4605-AEDB-5AA3E1F1EF43}"/>
          <w15:repeatingSection>
            <w15:sectionTitle w:val="w15 repeatingSection /dok[1]/Table_A[1]/lines[1]/lineitem[1]"/>
          </w15:repeatingSection>
        </w:sdtPr>
        <w:sdtEndPr/>
        <w:sdtContent>
          <w:sdt>
            <w:sdtPr>
              <w:alias w:val="w15 repeatingSectionItem"/>
              <w:id w:val="982486135"/>
              <w15:repeatingSectionItem/>
            </w:sdtPr>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


You need docx4j 3.2.2 beta to process these.

Re: Can't add new row with repeat content controll

PostPosted: Tue Aug 04, 2015 12:00 am
by Ben1980
Ah ok, but i used openDoPE to add them. Hmm ok is w15 from word2013?
Ok i am using only 3.2.2.
Is 3.2.2 possible to get over mavencentral?
I am asking because i solve my dependencies over gradle.

Re: Can't add new row with repeat content controll

PostPosted: Tue Aug 04, 2015 9:47 am
by jason
Ben1980 wrote:Ah ok, but i used openDoPE to add them.


You didn't :-) The OpenDoPE addins can't create w15 repeats. Maybe you used that proof of concept webapp linked in the http://www.docx4java.org/blog/2015/01/i ... -now-what/ blog post?

As it says there:

these are Word 2013 repeatingItem structures, not OpenDoPE repeats. (We recommend you use OpenDoPE repeats, but the tool creates Word 2013 repeatingItems, so you can see what Word 2013 users get out of the box)


Just to be clear, I recommend you avoid using Word 2013 repeats: http://www.docx4java.org/blog/2015/01/w ... rime-time/

Ben1980 wrote:Hmm ok is w15 from word2013?


Correct

Ben1980 wrote:Ok i am using only 3.2.2.


You mean 3.2.1?

Ben1980 wrote:Is 3.2.2 possible to get over mavencentral?
I am asking because i solve my dependencies over gradle.


I'll look to release it latest this week.

In the meantime, you can download it and install it manually to your local maven repo

But if it were me, I'd throw out the docx, and start again, using the OpenDoPE addin. And that way, you won't even need 3.2.2

Re: Can't add new row with repeat content controll

PostPosted: Tue Aug 04, 2015 4:30 pm
by Ben1980
Indeed i used the webapp, it seemed to me a good idea after reading your post. Made it quite easy because i could focus on geting the right xml and afterwards create the docx.
Yes i use 3.2.1, sorry for the confusion.
I will try with the openDoPE addin. But to be honest, i find this tool very inconvenient to use.

Re: Can't add new row with repeat content controll

PostPosted: Wed Aug 05, 2015 6:35 am
by Ben1980
Ok i created a new template only with openDoPE. But still its not filling in additional rows.

This is what i try to write into:
Code: Select all
<dok>
   <lines>
      <lineitem>
         <col1>test1</col1>
         <col2>test2</col2>
         <col3>test3</col3>
      </lineitem>
      <lineitem>
         <col1>test11</col1>
         <col2>test22</col2>
         <col3>test33</col3>
      </lineitem>
      <lineitem>
         <col1>test111</col1>
         <col2>test222</col2>
         <col3>test333</col3>
      </lineitem>
   </lines>
</dok>

Re: Can't add new row with repeat content controll

PostPosted: Wed Aug 05, 2015 8:54 am
by jason
Your docx contains:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
      <w:sdt>
        <w:sdtPr>
          <w:tag w:val="od:xpath=x4"/>          
        </w:sdtPr>
        <w:sdtContent>
          <w:tr >
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


That is, your table row is wrapped in a content control, but its not a repeat content control (a repeat content control has tag value od:repeat=...).

I'm not sure how you did that, but that's not going to work.

Re: Can't add new row with repeat content controll

PostPosted: Thu Aug 06, 2015 6:40 am
by Ben1980
Ok i updated the template, its repeating now, but always the same content.
I think i still dindt get the point. Is there any docx template example? the ones on github are allready for word 2013 as fahr as i see.

Code: Select all
<dok>
   <lines>
      <lineitem>
         <col1>test1</col1>
         <col2>test2</col2>
         <col3>test3</col3>
      </lineitem>
      <lineitem>
         <col1>test11</col1>
         <col2>test22</col2>
         <col3>test33</col3>
      </lineitem>
      <lineitem>
         <col1>test111</col1>
         <col2>test222</col2>
         <col3>test333</col3>
      </lineitem>
      <lineitem>
         <col1>test1111</col1>
         <col2>test2222</col2>
         <col3>test3333</col3>
      </lineitem>
      <lineitem>
         <col1>test11111</col1>
         <col2>test22222</col2>
         <col3>test33333</col3>
      </lineitem>
   </lines>
</dok>

Re: Can't add new row with repeat content controll

PostPosted: Wed Aug 12, 2015 11:27 am
by jason
The sample https://github.com/plutext/docx4j/blob/ ... sions.java

uses

Code: Select all
   String input_DOCX = System.getProperty("user.dir") + "/sample-docs/word/databinding/invoice.docx";
   String input_XML = System.getProperty("user.dir") + "/sample-docs/word/databinding/invoice-data.xml";


which demo OpenDoPE repeats.

Re: Can't add new row with repeat content controll

PostPosted: Wed Aug 26, 2015 12:57 am
by Ben1980
Sorry for the late response, I was on holidays :D

Thanks this worked very well.
But interesting for me, its only working with the standard text but not with conditionals.
So applying any formatting wouldn't be possible right?

Re: Can't add new row with repeat content controll

PostPosted: Wed Aug 26, 2015 8:28 am
by jason
What do you mean by "conditionals"?

If you mean an OpenDoPE conditional content control (ie a content control with tag od:condition), they work fine. The invoice.docx example contains one, last time i checked.

If you mean alternative row formatting, see docx-java-f6/coloring-table-rows-alternatively-on-an-opentope-template-t2241.html

Or do you mean something else?

Re: Can't add new row with repeat content controll

PostPosted: Wed Aug 26, 2015 5:25 pm
by Ben1980
Yes i meant the od:condition.
Thats right the Payment instructions are done with od:condition but the Description and Price are od:xpath.
This works for me only if i use the "Bind this ..." functionality which converts the content control to plain text.

Re: Can't add new row with repeat content controll

PostPosted: Wed Aug 26, 2015 10:28 pm
by jason
You can nest content controls ie put the od:xpath content control inside an od:condition content control.

Word's UI can make it a little confusing, but its easier if you have "Design Mode" turned on.