Embedding a table inside a word template

Hi,

We have the following situation.

We have a template of a word document which include a template.

Currently the cells in the above table included only text which was just fine.

Now we have customers that are asking to either:

  1. Text like they do today.
  2. Images.
  3. Another table.

What is the best practice to achieve this?

Thanks,

Yishay

Hi Yishay,

Thanks for your inquiry. Could you please attach your input and expected output Word documents here for our reference? We will then provide you more information on this.

Hi Tahir,

An example document is as attached.

As for the input, I can’t attach it because I’m asking for your help to understand how to create it.

The concept is that text1 can be ordinary text like “lorem ipsum”, but it can also be a table or a picture.

Thanks,

Yishay

Hi,

For the input we want to send something like the HTML created by jQuery Text Editors like this one:

http://akzhan.github.io/jwysiwyg/help/examples/02-full.html

Thanks,

Yishay

Hi Yishay,

Thanks for sharing the detail. Please use {{**Image:**MyFieldName}} syntax to insert an image mail merge field into template document.

Regarding inserting table while performing mail merge operation, please use html which contains the table tag. Following restrictions apply when passing HTML.

  • html fragment in xml must be encoded. e.g.

2 < 3

in xml must be following:

2 < 3

  • Setting styles through “style” attribute of element doesn’t work now e.g., if you use the html fragment

Text

, you will get document without any styles

  • The only way now to set styles is using of inline css. e.g. if you use the following fragment .cr

Text

, you will get document with styles as in browser

HTML will be passed between starting and ending tag of any merge field in XML
e.g.

HTML goes here…

Hi Tahir,

we are using JSON and not XML.

I tried using your example in one of our documents (see the JSON input at the end of this message) and all I got in the output was .cr

Text

It didn’t rendered as the wanted HTML.

Thanks,

Yishay

{"protocol":[{"serial_number":"M-00000158","meeting_place":"On Site","meeting_date":"12/07/2015","printing_date":"10/08/2015","project_name":"בבלי 13","written_by":"Yishay Haspel","participent":[{"name":"No Information"}],"meeting_subject":[{"descriptionTitle":"","description":"","issue_description":"× ×•×©× כלש×"וא","issue_index":".1","task_description":"","task_index":"","handler":"","due_date":""},{"descriptionTitle":"","description":"","issue_description":"","issue_index":"","task_description":"

.crText

","task_index":".1.1","handler":"","due_date":""},{"descriptionTitle":"","description":"","issue_description":"","issue_index":"","task_description":"","task_index":"","handler":"","due_date":""},{"descriptionTitle":"","description":"","issue_description":"","issue_index":"","task_description":"× ×•×©× כלש×"וא","task_index":"","handler":"ישי ×"ספל","due_date":""}],"correspondence":[{"name":"No Information"}]}]}

Hi Yishay,

We will share JSON example with you shortly.

Best Regards,

Hi Yishay,

At the moment HTML is working in XML format only. A new feature request to support the same for JSON format has been logged into our issue tracking system as SAASWORDS-246. We will keep you updated on this issue in this thread.

XML example is attached for your reference if you can use it as a workaround in the meantime.

Best Regards,

Hi,

Either I’m doing something wrong or you don’t support Tables and Images in your service.

I sent the attached XML and in return I got this in the word:

<span style="font-size:10.0pt;mso-bidi-font-size:12.0pt;
font-family:"Times New Roman",serif;mso-fareast-font-family:"Times New Roman";
mso-bidi-font-family:David;mso-ansi-language:EN-US;mso-fareast-language:HE;
mso-bidi-language:HE">h2{color:green} .color_red{color:red} .color_green{color:green}
.color_magenta{color:magenta} .color_olive{color:olive}
.color_teal{color:teal}123456 

What is the problem with the information I sent? Do we have some problem in our implementation or do you have a problem with the service?

Thanks,

Yishay

Hi,

Is there an option to use HTML to word instead?

I mean, is there a way that we could embed the HTML from the example I sent you in an HTML template instead of using the docx template?

If not, is there a way to use HTML to PDF instead?

Many thanks,

Yishay

Hi Yishay,

First of all I would like to share that the issue has been resolved and you can send HTML in JSON format also. Please check attached JSON as an example; this will fill the data field in the template with HTML.

As far as converting HTML to Word or PDF is concerned, this feature is already supported and you can pass HTML as input document and set DOC/DOCX or PDF as output formats in any conversion example e.g.
https://docs.aspose.cloud/words/convert/

In addition to that, executeTemplate API supports HTML templates also so you can use mustache fields in HTML templates and fill them with data as you do with DOCX templates.

Best Regards,

Hi Muhammad,

that’s great, but before we invest more days, we need to understand if this will solve the issue we got with the docx template.

We sent in the mustache field an HTML containing an image and a table and the rendered docx contained only the raw text without the table and without the image.

Many thanks,

Yishay

Hi Yishay,

We are working on the template and will share working template and JSON with you soon.

Best Regards,

Hi Muhammad,

That’s great, but XML will be sufficient, we already changed our implementation to use XML instead of JSON as you directed us.

Thanks,

Yishay

Hi Muhammad,

this issue started on the 9th of August, we done everything we could on our side to solve it, and it becomes more urgent each day because we have prospecting clients waiting to see this as part of their evaluation of our products.

Can you please help us with this?

Thanks,

Yishay

Hi Yishay,

I do not see any issue at my end and I get the attached output when I use previously shared template and XML at my end. You can see both table and image are visible.

What I can see from your XML is that you have used start and end tags like ‘<’ and ‘>’ in your HTML. As already shared, these tags are not supported when passing HTML and you should encode these tags just like I have done in my case. Please check attached XML with HTML for reference.

You can see ‘<’ is replaced with ‘<’ and ‘>’ is replaced with ‘>’. Please make these changes and let us know if you still see any issue.

Best Regards,

Hi Muhammad,

Thanks for the quick replay, from looking into your example I understood that we had two mistakes:

  1. We didn’t know we need the “format=“HTML”” attribute on the xml element.

  2. We didn’t know the inside information should be escaped (as you mentioned in the previous massage).

We done both and now the created Word suffer from two issues (please see the attached file for the XML):

  1. The image doesn’t show up.

  2. The table is different than how it is shown in the browser (the width:500px had no effect)

Thanks,

Yishay

Hi Yishay,

Sorry, I do not see any attachment with your post.

Best Regards,

Sorry, here it is.

Hi Yishay,

We are investigating the XML and will update you shortly.

Best Regards,