Modifying .docx file using Freemarker

837 views
Skip to first unread message

jin.dh...@teknion.com

unread,
May 27, 2016, 4:54:51 PM5/27/16
to Fujitsu RunMyProcess Developer Community
Hello,

I am currently trying to create a composite api which will run a Freemarker script to generate a .docx file from a template.

I have a template .docx called "payment_template.zip" in this file.

What I want to do is unzip that and modify the word/document.xml file before zipping those files back to a new file name and modify the extension back to .docx

Is this possible?

API.png

Pray Desai

unread,
May 27, 2016, 5:07:51 PM5/27/16
to suppor...@runmyprocess.com
Hi Jin,

Yes, it is possible to generate Microsoft Word Documents from RunMyProcess, not as straightforward as PDF creation. 

1) Have a word .doc template with desired labels and corresponding unique template variables where you will inject values from RunMyProcess. (similar to .xsl template).
2) Rename this .doc template with ".zip" and upload it to RunMyProcess. (one-time).

3) From the process, unzip this template using unzip_file() freemarker function
4) Get the document that ends with "word/document.xml" from this unzipped file
5) Get its xml template content using file_content() freemarker function

6) Replace one by one all template variables in xml with your process variable using replace() freemarker function like :
?replace("template_var1",process_var1?default("")?xml?replace("\n","<w:br/>")?j_string)

7) Save this modified xml content in the same unzipped xml template using save_file() freemarker function
8) Zip all the unzipped files including the updated xml template using zip_file() freemarker function and rename it with ".docx".

Incase, you have to inject images in this word doc, then there are some extra steps involved like updating media in the unzipped contents.

Refer :

Regards,
Pray Desai,
Fujitsu RunMyProcess.

--

teknion.com <http://www.teknion.com>

<https://www.facebook.com/Teknion> <https://twitter.com/teknion>
<https://www.pinterest.com/teknion/>
<https://www.linkedin.com/company/teknion> <https://instagram.com/teknion/>
<https://www.youtube.com/Teknion>
<https://itunes.apple.com/us/app/teknion-eshow-chicago/id529619476?mt=8>

Confidentiality Notice: This communication, including any attachments, may
contain information that is confidential and privileged. [It may constitute
non-public information and is intended to be conveyed only to the
designated recipient(s).] If the reader or recipient of this communication
is not the intended recipient, or you believe that you have received this
communication in error, please notify us immediately by return e-mail and
promptly delete this e-mail including any attachments without reading or
saving them in any manner. Any other distribution, copying or disclosure is
prohibited and may be unlawful. We accept no responsibility for changes
made to this e-mail or to any attachments after transmission from our
office.

--
Fujitsu - RunMyProcess
---
You received this message because you are subscribed to the Google Groups "Fujitsu RunMyProcess Developer Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supportforum...@runmyprocess.com.
To post to this group, send email to suppor...@runmyprocess.com.
Visit this group at https://groups.google.com/a/runmyprocess.com/group/supportforum/.
To view this discussion on the web visit https://groups.google.com/a/runmyprocess.com/d/msgid/supportforum/0bc54a60-bc1e-4cd0-bdef-141383ce30f5%40runmyprocess.com.
For more options, visit https://groups.google.com/a/runmyprocess.com/d/optout.

jin.dh...@teknion.com

unread,
May 30, 2016, 2:46:26 PM5/30/16
to Fujitsu RunMyProcess Developer Community, jin.dh...@teknion.com
OK, great.

So now I have the following script to grab my data and unzip the template.

<#assign template_file = "cee46700-241f-11e6-9baf-02b3a23437c9">

<#assign dealer_name = ${dealer_name} >
<#assign dealer = ${dealer} >
<#assign req_by = ${created_by} >
<#assign prod_no = ${product_id} >
<#assign item_desc = ${description_of_items} >
<#assign req_type = ${request_type} >
<#assign list_price = ${price} >
<#assign quantity = ${quantity} >
<#assign created_date = ${now()} >
<#assign exp_date = ${due_date} >
<#assign size = ${size} >
<#assign leg = ${leg} >
<#assign metal_colour = ${metal_colour} >
<#assign fabric = ${fabric} >
<#assign top_finish_type = ${top_finish_type} >
<#assign top_finish_colour = ${top_finish_colour} >
<#assign top_thickness = ${top_thickness} >
<#assign top_edging_colour = ${top_edging_colour} >
<#assign edging_style = ${edging_style} >
<#assign chassis_colour = ${chassis_colour} >
<#assign chassis_edging = ${chassis_edging} >
<#assign grommet_location_colour = ${grommet_location_colour} >
<#assign handle_type_location = ${handle_type_location} >

<#assign doc_name = "Bvld Special Pricing - ${dealer} - ${created_date}" >

${unzip_file(template_file)}


How can I test this? I click on "launch test" and start a test, but there is no output from the unzip_file function. It returns a filedescriptor type object which your Docs doesn't give any details about.

Pray Desai

unread,
May 31, 2016, 4:08:12 PM5/31/16
to suppor...@runmyprocess.com, jin.dh...@teknion.com
Hi Jin,

You can loop through the array of files unzipped and get the id of file that ends with "word/_rels/document.xml.rels".
Reply all
Reply to author
Forward
0 new messages