opensagres / xdocreport

XDocReport means XML Document reporting. It's Java API to merge XML document created with MS Office (docx) or OpenOffice (odt), LibreOffice (odt) with a Java model to generate report and convert it if you need to another format (PDF, XHTML...).
https://github.com/opensagres/xdocreport
1.19k stars 368 forks source link

Is repeating bullet points possible #665

Open tomhillgreyridge opened 2 months ago

tomhillgreyridge commented 2 months ago

Description

I'm trying to create a document template where a list of bullet points is created from dynamic data. The problem is that I can't find a way to do a #foreach loop which doesn't either a) put all content in one bullet point or b) end up with either extra bullet points or extra spacing

What I've Tried

Putting it into the list item like this

image

and the result was all names on one line, like this

image

I thought the solution might be to put the #end onto a new bullet point so the bullet got repeated

image

which got me closer but I end up with an additional empty bullet point for the #end merge field.

image

So I thought I'd try moving the loop outside the list item

image

but that ends up with multiple lists

image

I've then tried fiddling around with the paragraph spacing before and after in Word itself to see whether that would do it, but I can't get to the point where it looks like it would if you typed it in Word, i.e.

image

Analysis

I assume this is an issue similar to the one with table rows where the loop needs to be moved outside the LI but I can't find an option similar to the @before-row / @after-row stuff for list items. One solution I can think of (which would probably be generically useful) would be to remove an element from the generated output DOCX if the only thing in that input element is a merge field - that way you don't end up with extra elements solely because of the #foreach merge fields.

That would also solve some of the problems with merge fields creating extra white-space in the output document.

The alternative might to to implement the solution used by https://github.com/thombergs/docx-stamper which is to use comments to store the expressions rather than merge fields

Questions

czerudla commented 1 month ago

Hi @tomhillgreyridge, I am not sure about Velocity, but in Freemarker, you can use separator notation sep https://freemarker.apache.org/docs/ref_directive_list.html#ref_list_sep So in yor case it will be done like this: