Hi
I have a word document which has 5 merge fields in a table, using words catalog template, cannot get it to mailmerge in the API no errors produces document. It might be the structure of my xml, any ideas.
Hope that makes sense.
Hi
I have a word document which has 5 merge fields in a table, using words catalog template, cannot get it to mailmerge in the API no errors produces document. It might be the structure of my xml, any ideas.
Hope that makes sense.
You can automate Word Mail Merge from XML data in Node.js using Aspose.Words REST API as follows. If you face any issue then please share your template and data file along with the sample code. We will look into it and will guide you. Please also check the following documentation for sample templates and data.
const { WordsApi, ExecuteMailMergeOnlineRequest } = require("asposewordscloud");
var fs = require('fs');
// initialize the API
// Please get your App Key and App SID from https://dashboard.aspose.cloud/#/apps.
wordsApi = new WordsApi("xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxx");
// set paths of Template and data file
const localDocumentFile = "C:/Temp/MailMergeSamples/coverageChangeTemplate.docx";
const localDataFile = "C:/Temp/MailMergeSamples/coverageChange.json";
// Mail Merge
const request = new ExecuteMailMergeOnlineRequest({
template: fs.createReadStream(localDocumentFile),
data: fs.createReadStream(localDataFile),
withRegions: true,
cleanup: "EmptyParagraphs,UnusedRegions,UnusedFields,ContainingFields,RemoveTitleRow,RemoveTitleRowInInnerTables"
});
wordsApi.executeMailMergeOnline(request).then((result) => {
console.log(result.path);
fs.writeFileSync('C:/Temp/MailMerge_cust.docx', result.body);
console.log('Completed...');
}).catch(function(err) {
// Deal with an error
console.log(err);
});
Hi
Managed to get it working, thank you check examples again. Another question is possible to put mailmerge fields in the header part of a document.
Thank you
Yes, you can add Mail Merge fields in the header of the template. Please find a sample template and data file for reference.HtmlImageTemplate.zip (13.6 KB)