We're sorry AsposeCloud doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.cloud

How to insert HTML text in Mail Merge Word template using Aspose.Words Cloud API

Hi,
I am also trying to implement similar functionality where I want to show styles done on rich text field in asponse word document. HTML is not getting rendered in word document instead it is showing html tags.
Can anyone help me with this?

awais.hafeez
@SagarGurav,

Please ZIP and attach your input document, Aspose.Words generated output document showing the undesired behavior and source code to reproduce the same issue on our end. We will investigate the issue on our end and provide you more information.

@SagarGurav

Thank you for contacting Aspose Support.

You need to escape HTML characters in data source string and use "format"="html" attribute. The Mail merge data file should look as follows:

{
  "dataSourceList": {
    "contractDS": {
      "contractDescription": { 
      	"format":"html",
    	"htmlText": "<b>Test me 1<br><br><i>Test me 2<br><br><u>Test me 2</u></i></b><br>"
      }
    }
  }
}

I have written following cURL example to make things more clear:

curl -v "https://api.aspose.cloud/v1.1/words/SampleDocTemplate_Input.docx/executeTemplate?destFileName=TestPostExecuteTemplate.docx" \
-X POST \
-T TestExecuteTemplateData.txt \
-H "Content-Type: multipart/form-data" \
-H "Accept: application/json" \
-H "Authorization: Bearer MXTzwebiZWrbla_p9R3w3bbJ6lYToz_bycz3SMlJ6WGKXdRepanhB1bd_rWluOZWg3IA-LmMypP7BxPlV0a_5wXy96liygkIu9FpuJ6bxtD3J8vhQ9-Wl05haDnZlVwj9-t4fSYBIHfnSnvIh06qCXkK-2wKYfRPkNDi7VDyzKC362aQ_NKNOvgEzGQWaM8bb0vejURdzTWT23Hp_oLH54EmtCW38Y-YexaKbH-gI1bJ2D8ErPmqTaGlrvu5AFVWS5R9jVigxiugrd8IwMYkU7Nirwjm1LV0xebTK6V0GidCF6bWnQNpG3bRjGcnfANTipFDomY74dMlPHPzNML1hpGW52o2Ovgd-2lIAbL2Q1lzgRXHYmdP9HyVKqVOy_-5_RRPrDKxF8MuCiu8yDC24J4AEM_pPA0sSIuUlJQijAvAOGT8-0LgxVmifwVwxf014T6tpLkv_pKXcdwKo8pGk9FstmA"

Input File: SampleDocTemplate_Input.docx.zip (12.1 KB)
Mail Merge Data: TestExecuteTemplateData.txt.zip (1.2 KB)
Output File: TestPostExecuteTemplate.docx.zip (17.5 KB)

I hope the above is helpful to you.

It worked for me.
Thank you for your reply.

@SagarGurav

That’s good to know. Please keep using Aspose Cloud APIs.

I was trying to render HTML Table using Aspose in similar format that you replied earlier but was not able to convert that html table into actual table instead it was display HTML tags.
Can you help me with this?

@SagarGurav

Please share the input files so that we can reproduce the issue on our end. I have marked this thread private only you and Aspose Staff have access to it.

Input :

{"dataSourceList":{"contractDS":{"contractDescription":{"htmlText":"<table><br>  <tr><br>    <th>Company</th><br>    <th>Contact</th><br>    <th>Country</th><br>  </tr><br>  <tr><br>    <td>Alfreds Futterkiste</td><br>    <td>Maria Anders</td><br>    <td>Germany</td><br>  </tr><br>  <tr><br>    <td>Centro comercial Moctezuma</td><br>    <td>Francisco Chang</td><br>    <td>Mexico</td><br>  </tr><br></table>","format":"html"}}}}

Output :
image.png (5.8 KB)

Let me know if need any inputs.

@SagarGurav

Thank you for sharing the input file. Please spare us some time to diagnose the issue.

@SagarGurav

The API is working fine. It looks like your HTML code was not encoded properly. You may use https://codebeautify.org/html-encode-string or http://www.convertstring.com/EncodeDecode/HtmlEncode to encode HTML String.

Input File: SampleDocTemplate_Input.docx.zip (12.4 KB)
Mail Merge Data File: MailMergeData.zip (896 Bytes)
Output File: SampleDocTemplate_Out.docx.zip (18.4 KB)

The cURL example looks as follow:

curl -v "https://api.aspose.cloud/v1.1/words/SampleDocTemplate_Input.docx/executeTemplate?destFileName=SampleDocTemplate_Out.docx" \
-X POST \
-T MailMergeData.txt \
-H "Content-Type: multipart/form-data" \
-H "Accept: application/json" \
-H "Authorization: Bearer A03jLSHkq6zu_A8kpxU6xPKOEkBFn7fX6_hhKkAO0-2AFeI0UgB_M_D4O1cLkZSbfgGpbpA7oos3P8BhpbvDqHjcIkzTnSXBPkBJpRpWGdj2DwuQ9kd_FuBMTiU5NBZ3gUOwDGuY7bUJejPw8NzOFsk6Lt9z9CCR2lOyWUpKzlPSTl3DSaIkZRKluuccL4sT-PqeDkOHgn6mewV0P0GsrBkoQo6LDk1RozojGDYvPDAqVPFHmwc20MHnMtXlE5CA-koBJa0LmXKFBRKNqv1COa9l4qrDRRtNcx1yJWPdpvY6udg3a1oD36qlzSNiMNaAFZNWESzK3lZEgr6uAFZeG6SC4SHcws6OITJKm7P_VAjGElvAEAtnaO4qng6myB2prDUNIYHcwQkN4DaUPoQguJnPXbeB2WKV-u07p3y0fxAUZ82TOcew_LO-vCb15pBSsvpIHX3n3XE-egWrngqShI3uDNE"

Thanks Sohail for your help. It worked out again.

1 Like

Hi,

We are facing font issue :
Data displayed in 1st highlighted text is dynamically rendered from data type : text field in salesforce
Whereas 2nd highlight(below text) is dynamically rendered from data type : rich text area field in salesforce.

image.png (7.2 KB)

We want to show both data in same format

Needed asap.

Thanks,
Sagar.

@SagarGurav

Please share the input file, code and other details that may help us in reproducing the issue on our end. We will guide you as we are able to reproduce the issue on our end.

Hi,

PFA for input file and required details:
Aspose_Font_Issue.zip (24.6 KB)

Let me know if u face any issues in understanding it.

@SagarGurav

Thank you for sharing the details. We are writing the cURL example for your use case and will update you shortly.

You have any updates on this issue?
waiting for your response.

@SagarGurav

Please use following Mail Merge Data file, it would solve the issue: TestExecuteTemplateData.zip (1008 Bytes).

The data file used CSS Style to set text Font Family and Font size:

<p style="font-size:9pt; font-family: Arial">Speaker</p>

after encoding htmlText looks as follows:

&lt;p style=&quot;font-size:9pt; font-family: Arial&quot;&gt;Speaker&lt;/p&gt;

Input File: SampleDocTemplateFONT_ISSUE_Input.docx.zip (10.5 KB)
Output File: SampleDocFONT_ISSUE_Output.docx.zip (20.2 KB)

and the cURL example would look as follows:

curl -v "https://api.aspose.cloud/v1.1/words/SampleDocTemplateFONT_ISSUE_Input.docx/executeTemplate?destFileName=SampleDocFONT_ISSUE_Output.docx" \
-X POST \
-T TestExecuteTemplateData.txt \
-H "Content-Type: multipart/form-data" \
-H "Accept: application/json" \
-H "Authorization: Bearer HTXtrjieK6IoaUeM3OTkBuqDFp_CoHrxlIxi4v4mnzzTNJgliIu9kKLO0Oc2-nGJGRtDi62dFa1gTJ4eZ9X2k274fbcRseWpqjOV6JJvEHuZpxUVb6dxFx6Gn9bfgoJoNCoDNds6malpTM8xF23aB4PA2IaAV1xhnx7sIfZdzRad1hwA1S47WdxSaBq8BamRplQUjQ4fIcKLlxwvQw5vVx8VPoXb1asdpM1hOvby-Qsxaioum0j8wz4Lf2dEiBGVd7uHqXUM2Aopv7bswJw2mxbb7s2Gndl6abSDOpS42CXMyyah9YWa3DU9m3urpmr2_0LDsbfVVKsSORj3Z3fcpn9SYwIaU6bQ9jGgT_XgyRpqvfvBjdh5cuODIQmEs6XDo6Hm50_1Efce6Bko0jeC7jINZah2zyB7KaOGzCgF9d8SXCFeiBLQEykMICOEMjSsZiKO__3heAZA-_O5-9dfoF5oPXo"

I hope this helps.