Free Support Forum - aspose.cloud

Use HTML in mailmerge online


#1

Hi,

As i can see in the docs it’s possible to use html in a mailmerge when the template is in the aspose storage. How about using HTML when using the mailmerge online? Is this possible? If so, is there any documentation for this?


#2

@sanderApp

Thank you for contacting Aspose Support.

As I can see in the docs it’s possible to use HTML in a mailmerge when the template is in the aspose storage. How about using HTML when using the mailmerge online? Is this possible?

Yes, this is possible. The API call remains same as explained here and here depending on whether you are using Mustache template or MailMerge template. You just need to replace data file with HTML file. The following cURL examples will make things more clear.

Populate MailMerge Template with Data Online
Input Document: template.doc (6.1 KB)
Mail Merge Data: TestExecuteMailMergeData.txt (2.3 KB)
Output Document: TestPostDocumentExecuteMailMerge.docx.zip (4.5 KB)

// First get Access Token
// Get App Key and App SID from https://dashboard.aspose.cloud/
curl -v "https://api.aspose.cloud/oauth2/token" \
-X POST \
-d 'grant_type=client_credentials&client_id=0B17F60A-6D69-426B-9ABD-79F35A6E9F7B&client_secret=53b8b19adffa41a3e87dbbd8858977ae' \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
  
curl -v "https://api.aspose.cloud/v1.1/words/executeMailMerge" \
-X PUT \
-F Template=@template.doc \
-F Data=@TestExecuteMailMergeData.txt \
-H "Content-Type: multipart/form-data" \
-H "Accept: multipart/form-data" \
-H "Authorization: Bearer DvWHBwff82KzMPzDtw1lJXl4IFahvvSzRJ9-IVRAgaM8_Xtf2FuWQ7co6IqbuFGUg0PoDE91vglvXYOFCTxCwy9rN8Xui9UsK-n8y1xwdltlCdxTGFxjK12tYBSb1JpFgjjE8kE9KJLITR7a9wKP_0Rropq6xOEvH0tXkEqgUxg8GmjPdHt1ew9nS7l2-A1bvr20E95qBhAWVTJ4Ckm9NHU6umYIOEjzKjkKRT26c16cPY5X3pGu9NV2Qjx-QhaDMNy0UFtH1GTphP_PZlPsHnirvJ2jgM0L3HwGcLEeTQenDjIFgaxQOem5juMTNAY1lrx3Il11ipQ7xYe299v4WeWZXUDdyH-Ohi3O4hz_Lb6Mhlc0rMyA4v6H9Smu_fPndHCUiPIZR8_Vbp9AQ72RkLidFYrlJQg8AfIfnFZRtD8mRXMjnuqPx8ZUpm8ODHlzbAg_FFgvre8vuKP6mYssbfga_7k" \
-o TestPostDocumentExecuteMailMerge.docx

Populate Mustache Template with Data Online
Input Document: SampleDocTemplate_Input.docx (12.4 KB)
Mail Merge Data: TestExecuteTemplateData.txt (1.1 KB)
Output Document: TestPostExecuteTemplate.docx (8.8 KB)

// First get Access Token
// Get App Key and App SID from https://dashboard.aspose.cloud/
curl -v "https://api.aspose.cloud/oauth2/token" \
-X POST \
-d 'grant_type=client_credentials&client_id=0B17F60A-6D69-426B-9ABD-79F35A6E9F7B&client_secret=53b8b19adffa41a3e87dbbd8858977ae' \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
  
// cURL example to populate Mustache Template with Data Online
curl -v "https://api.aspose.cloud/v1.1/words/executeTemplate" \
-X PUT \
-F Template=@SampleDocTemplate_Input.docx \
-F Data=@TestExecuteTemplateData.txt \
-H "Content-Type: multipart/form-data" \
-H "Accept: multipart/form-data" \
-H "Authorization: Bearer DvWHBwff82KzMPzDtw1lJXl4IFahvvSzRJ9-IVRAgaM8_Xtf2FuWQ7co6IqbuFGUg0PoDE91vglvXYOFCTxCwy9rN8Xui9UsK-n8y1xwdltlCdxTGFxjK12tYBSb1JpFgjjE8kE9KJLITR7a9wKP_0Rropq6xOEvH0tXkEqgUxg8GmjPdHt1ew9nS7l2-A1bvr20E95qBhAWVTJ4Ckm9NHU6umYIOEjzKjkKRT26c16cPY5X3pGu9NV2Qjx-QhaDMNy0UFtH1GTphP_PZlPsHnirvJ2jgM0L3HwGcLEeTQenDjIFgaxQOem5juMTNAY1lrx3Il11ipQ7xYe299v4WeWZXUDdyH-Ohi3O4hz_Lb6Mhlc0rMyA4v6H9Smu_fPndHCUiPIZR8_Vbp9AQ72RkLidFYrlJQg8AfIfnFZRtD8mRXMjnuqPx8ZUpm8ODHlzbAg_FFgvre8vuKP6mYssbfga_7k" \
-o TestPostExecuteTemplate.docx

We hope this helps.


#3

@sohail.aspose ,

Thanks for your response. Doing exactly the call from your response (Populate MailMerge Template with Data Online) is resulting in a doc file in the response which is exactly as the template. So it seems like something is going wrong. Nothing is merged.

Besides that, is it also possible to use XML instead of json for merging HTML data? I did add an example with a nested xml data file and a template. For example i want to insert HTML data into one field. Can you also give an example for this? Thanks!

TemplateAndData.zip (13.7 KB)


#4

@sanderApp

Besides that, is it also possible to use XML instead of json for merging HTML data?

Yes, you can use XML to merge HTML data.

Can you also give an example for this?

Here is the example:
Input Document: template.doc (6.1 KB)
XML Data: TemplateDataXML.txt (2.0 KB)
Output Document: TestPostDocumentExecuteMailMerge.docx (4.5 KB)

curl -v "https://api.aspose.cloud/v1.1/words/executeMailMerge" \
-X PUT \
-F Template=@template.doc \
-F Data=@TemplateDataXML.txt \
-H "Content-Type: multipart/form-data" \
-H "Accept: multipart/form-data" \
-H "Authorization: Bearer _eAiJs5bWvX0GvaRU9EVUSp1aSuzEP_yhKLbTuNVgLCO5KKhXnnoMFTeqPApSBnUZLevKqqAlMV-bPyCDujzb33T4wBGczQvrPegGQ5zgWCfe4H2MtKBPbG6hruGEgPD6uMdhhukDI4Bd6C9hUuP7DiMmCGn06Q05YNivPurdG2Vial3TbkpyJHzRn59dCQc6CEtX4GIcI0ct8IVJuEesBnRPR3CVC1Nx6yBd0JEppO4b5MKsAgcWruWd4h1phLWLnc0A1qbK3liRiaYu9aKsslP178bw4yHLr6hwpCKj9Ya1qkRBq7Q2JICrpqXT7A1Gz5lF4KSqDGCjE7zXBvsk7XW0FmQKI3orXD7A0nbNhd0hUany75zVrd_ijHJgPIlVf2bSsNt1TqUa_9GqK8dnqbf2_n-rilZQJFpGXyaoaB8E51PVSy0ntO43oaUkiwUT411N9FD-v8ryyDUyvyDRps5f_Y" \
-o TestPostDocumentExecuteMailMerge.docx

We hope it helps.