Word Template Demo Project
- Generate fully styled Word documents populated with data from your Mendix application!
- Dynamically populate rich text fields, images, item lists (bullets) and tables with your Mendix data.
- Even Excel graphs (Stacked Bar / Line) based on Mendix data are included!
- No need for Aspose or other paid third party license; pure Mendix and Java!
- The Word document can also be downloaded to PDF. For PDF charts aren’t supported
Also see my blog for more details: https://medium.com/mendix/how-i-automated-word-templating-in-mendix-with-the-apache-poi-api-4549163b0acc
Generate fully styled Word documents populated with data from your Mendix application! Even Excel graphs based on Mendix data are included! No need for Aspose or other paid third party license; pure Mendix and Java!
Typical usage scenario
When your Mendix app needs to be able to generate Word documents with proper styling as well as potential Excel graphs based on data from your Mendix application.
- The Word document is based on a template, maintained in Word;
- All styles from the Word document (font size, color, etc) will be maintained;
- The Word document can be updated with data coming from your Mendix app, preserving all styling. This works for plain text and when used in bullets / headers / tables as well;
- If your Word document has Stacked Bar Chart templates, the Stacked Bar Charts can be updated with data coming from your Mendix app! Currently only Stacked Bar Charts and Line Charts are included;
- Exporting to PDF is not fully working yet, see limitations. Mostly charts aren’t working.
Limitations (not included)
- Other types of Chart templates than Stacked Bar and Line Charts;
- PDF export is not working perfectly yet. For plain text it will work, but Charts are not included and table margins are looking off;
- Export to Word replacing tokens (=BookmarkValue) in the template for Mendix values (=ReplacementValue), preserving font styles;
- Adding custom tables, rich text, (un)ordered lists and images
- Adding one or many Stacked Bar and/or Line Charts with data form Mendix.
The solution uses quite some jar files. Be aware those can conflict with the Mendix modules also using Apache POI jars, like the Excel Importer and Excel Exporter modules.
- For replacing words in Word:
- poi-5.2.2, poi-ooxml-5.2.2, poi-ooxml-full-5.2.2
- For updating Excel charts to in Word templates the jars:
- For transforming Word docs to PDF the jars:
This is a test project which comes with data, created by an after startup microflow. If the database is empty it will create both the entities which are needed for proper demonstration of the power of the module:
- WordReplacer: Mendix entities which are used to change the content of the Word file. The Java action ‘JA_WordDoc_Generate’ will search the Word file and if hits of ‘BookmarkValue’ are found, change them to the content of ‘ReplacementValue’;
- Chart / ChartValue: Mendix entities used to populate the Excel Stacked Bar Chart categories and series. It can be confusing to understand what categories and series are within the context of this module, hence you should really check with the example entities created within this module in after startup. Send an e-mail to ivo.sturm@firstconsulting to get the example word document which is needed for step 1.
- Run the test project;
- Read the content in the group boxes on the home page:
- Step 1: Upload the Word template file which can be found in the resources folder of this project
- Step 2: If needed, change the Word file, as well as change the bookmark values;
- Step 3: If needed, change the Excel Charts in the Word file, as well as change the series and categories values;
- Step 4: Export the Word document with updated Word and Excel content from your Mendix application.
For a demo, see https://wordexporter127-sandbox.mxapps.io/index.html?profile=Responsive
If in doubt on what is going wrong, proper Trace logging is added; set the Log level of the ‘Word’ node to Trace to see what is happening within Mendix!