guigrpa / docx-templates

Template-based docx report creation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Loop with sections and dynamic headers

philip-roeggla opened this issue · comments

I did not find the solution in the docs, maybe you can help me:
I would like to loop through data, generating sections for each datum, with a header set from that datum. For example

[Ms-Word-Header]
+++FOR datum in data+++
+++INS $datum.headerText+++
[Ms-Word-Body]
+++INS $datum.content+++
[Ms-Word-SectionBreak]
+++END-FOR datum+++

Which does not work this way, since it seems, you can't have template code parted over header and body. I tried to define the loop only in the body, and reference the data later on in the header, but then it does not find it.

Is there a way to do this?

Thanks! And als thanks for the great library!

I'm afraid that's currently not possible. The document's headers and its body are contained in separate XML trees in the docx file and are processed separately. This makes it difficult to implement something like you describe.

Ok, thanks!