Page 1 of 1

Add some paragraph in place of a run

PostPosted: Sat May 13, 2017 12:59 am
by Zanza
Hello,
I'm developping a feature that should generate 2007+ word report, from a template.

In input, i have a template .docm, and some text, image, and table, I need to add in it.
To identify the place to add those image, Run and Tbl, I can only use a run but no placeholders.

How can I find the P which contain my identifier text, and add after this one, some other P or Tbl ?

(The initial P can, and should be remove, but that's not very important).

Thank you !

Re: Add some paragraph in place of a run

PostPosted: Sat May 13, 2017 7:10 pm
by jason
To find your run, use TraversalUtil or the XPath API (see Getting Started for details).

Then, to replace a run with block level content (eg a Tbl), you'll need to split the paragraph (ie make a copy, then delete content, so the first runs are in the first P, and the others in the second).

To find the P, find its index in the parent content list (standard Java list manipulations).

You can of course use docx4j to implement your own approach to report generation.

But I'd strongly recommend you instead look into docx4j's OpenDoPE support, which does this stuff already.

Re: Add some paragraph in place of a run

PostPosted: Wed May 31, 2017 12:12 am
by Zanza
Thank's for your help !

For the OpenDoPE , it would actually been a lot of supplementary work to use it in the corporate process..