Word (docx) template based reports
-
Hello,
I have created all reports in the past as HTML, but one customer would like to use Word to design the reporting templates. I was initially quite skeptical, but I see more and more the reason why this could make sense from a business point of view.So I'm thinking about using a library such as docxtemplated to dynamically replace tags and generate a docx document (see https://docxtemplater.readthedocs.io/en/latest/index.html), which could be optionally converted to PDF using Libre or Open Office.
Since I like jsreport, I'm wondering if anybody has done something similar and/or whether it would be possible to implement a custom receipe for this.
-
Hi,
just adding the link to one existing recipe for generating docs.
It was created by the one of contributors from the community.
It can work nicely in some limited scenarios.
https://github.com/jsreport/jsreport-html-embedded-in-docxIf it doesn't work for you, feel free to ping me directly when having some questions regarding creating custom recipes.
-
Hi Jan,
Thanks a lot for your response. We will start implementing a custom recipe for docxtemplater in the next few days and will contribute it back to the community. Will ping you directly in case we will face some issues.
-
Hi Jan,
We have started today thinking about how to integrate docxtemplate with jsreport and I'm not sure whether this is actually possible without major modifications. The idea is to upload a docx template to jsreports (which is in itself a zip file). So the first attempt to implement a custom engine failed, because we need to read the template in binary mode in order to be able to unzip it. Any suggestion how this can be done?
-
Could you try to describe more in details how would you like this to work?
I would guess that it will (from one part) work the same way as the
xlsx
recipe.
There will be a new entity "docx template" which will represent the binary docx file uploaded by user.
This entity will be associated with the normal template. Just like the xlsx template.
The new recipe will somehow run a tool of your choice and fill the associated template.
So I believe very similar whatxlsx
recipe does.
The difference would be that there will be a tool used to fill the docx.
Where inxlsx
we unzip the xlsx, fill it using templating engines and zip it back.Here you can find xlsx sources
https://github.com/jsreport/jsreport-xlsx
-
Thank you very much for your response. I just looked at the source code of xlsx and the approach is indeed very similar, but there are a few differences. Docxtemplater has tags inside the word template and is in this sense an engine and not a recipe. We envision the process as follows:
- User prepares a word template with custom placeholders/tags as described here: https://docxtemplater.readthedocs.io/en/latest/tag_types.html
- He uploads the word template to jsreport
- A custom engine renders a new docx file
- This file will be passed optionally to a custom recipe to convert it to PDF
We probably need to implement a custom engine (docx) as well as a custom recipe (docx-to-pdf). Any view on this?
-
FYI we had some conversation also over email
I am now working on implementing this.
I come back to you soon.
-
I released required extensions. Please check the documentation and let me know if it is suitable for you.
https://jsreport.net/learn/docxtemplater
https://jsreport.net/learn/unoconv