Monday, December 1, 2014

Word Templater

While migrating some of my portal apps from PHP to native SAP HANA apps i was looking for a javascript library that is able to replace some placeholders inside a word docx template.

After some googling i found the Github project docxtemplater. Having a look at the examples i found out that such a task is also able directly on the client/browser side.

Curious about that i thought i should give it a try inside UI5.

Demo UI for docxtemplater example

Now let us go into detail.

First of all a lot of cool javascript libs are bundled as Node Packaged Modules so they can easily be integrated into node.js server side code libraries. Using node.js tools like browserify you are easily able to package a server side javascript library into one file to be used on client side.

To be able to use docxtemplater you have to build your own version of the needed library as decribed in the corresponding build manual. Be sure to use the 1.x branch from github, because the API has dramatically changed and the following example depends on 1.x.

Sadly JS Bin is not easily able to include custom javascript libs so i used it only as a copy/paste container for a custom quick start project.

The JS Bin JavaScript sections contains the commented code. Inside the example i introduce the native library introduced with version 1.22.

JS Bin

We use this internally while marketing is publishing the companies corporate word templates and you can easily inject global text replacements. This forces everyone to use the lastest corporate templates by easily automate redundant tasks. Think about an UI5 app with selectable text fragments to automatically generate target word file ;-)

Have fun.


  1. Hi,

    I'm edi9999, the creator of docxtemplater. Happy to see you using docxtemplater v1. It was just released officially yesterday.

    When I try out the JSBin, I get an error: DocxGen is not defined.

    Anyway, I'm going to checkout openui5

  2. Hi Edgar,
    currently i am not able to host custom libs and the is no public wordtemplater.js available inside JSBin. If you host a public/linkable lib of version 1.x please let me know.

    The JSBin is only a copy template. The linked Word.docx is also not available.

    If you will allow me to link your hosted demos (example word file and of course docxgen version 1.x i would be able to update JSBin to a working and testable example.

    Cheers Holger


Thank you for your comment!

The comment area is not intended to be used for promoting sites!
Please do not use such links or your comment will be deleted.


Note: Only a member of this blog may post a comment.