I want to shade the cell color depending on the condition.
Here’s my template and sample JSON data saved under test foldertest.zip (10.3 KB)
.Conditional formatting is not working and the API documentation is not helping. I want to use if block and want to change the table cell background depending on the condition where the value is 0.
Thanks for your inquiry. Please note you need to use actual IF Field for conditional IF block. Please find attached sample template demoIf.zip (10.9 KB). And for conditional formatting, we will appreciate it if you please share an expected document here. We will look into it and will guide you accordingly.
I didnt understand your demoif template. Like how to use if else condition. I have attached the expected output for the above template and JSON data.demo if expected output.zip (9.8 KB)
Thanks for sharing expected output document. We are looking into your requirements and will update you soon.
Please note Aspose.Words Cloud does not support to change cell/row background color using Mail Merge/Mustache Template. However, you can format text conditionally as per your requirement. Please find the sample template and output, hopefully it will help you to accomplish the task.demoIf.zip (22.2 KB)
the demoif zip which you ll have provided. Doesn’t contain any solution or syntax of the same. Please provide pproper solution or syntax, which I can implement.
As stated above, you can change the text color using mail merge. It does not support changing cell/row background color conditionally using Mail Merge/Mustache Template. Please elaborate, what do you mean that it doesn’t contain any solution or syntax of the same?
Sir, can you please share the snippets for changing the text color conditionally using Mail Merge/ Mustache Template. I have attached expected output word file.Expected Output.zip (11.0 KB).
Please find sample Mail Merge Node.js code snippetdemoIf.zip (10.9 KB). Hopefully it will help you to accomplish the task.
const { WordsApi, PostExecuteTemplateRequest } = require("asposewordscloud");
wordsApi = new WordsApi("xxxxx-xxxx-xxxx-xxxxx-xxxxx", "xxxxxxxxxxxxxxxxxxxxx");
var StorageApi = require("asposestoragecloud");
storageApi = new StorageApi({ appSid: "xxxxxxxx-xxxx-xxxxx-xxxx", apiKey: "xxxxxxxxxxxxxxxxxx", baseURI: "https://api.aspose.cloud/v1.1" });
var fs = require('fs');
const templateLocalPath = "demoIf.docx";
const dataLocalPath = "C:/Temp/demoData.json";
const remoteFileName = "ExecuteTemplateIf.docx";
// Upload File
storageApi.PutCreate(templateLocalPath, null, null, templateLocalPath, (responseMessage) => {
console.log("Uploaded File");
});
// MailMerge Template
var request = new PostExecuteTemplateRequest();
request.name = templateLocalPath;
request.data = fs.readFileSync(dataLocalPath, "utf8");
request.destFileName=remoteFileName;
wordsApi.postExecuteTemplate(request).then((result) => {
console.log(result.body.code);
}).catch(function(err) {
// Deal with an error
console.log(err);
});
Maybe you have already noticed that we have released Aspose.Words Cloud API Version V4.0. It has many major breaking changes. However, in reference to this post, please note we have simplified the Mail Merge operation and introduced storage methods in the API. Now a single Mail Merge API will be used for both Mail Merge fields and Mustache template. Please check the sample updated Node.js code for your reference.
const { WordsApi, UploadFileRequest, ExecuteMailMergeRequest } = require("asposewordscloud");
var fs = require('fs');
// Please get your App Key and App SID from https://dashboard.aspose.cloud/#/apps.
wordsApi = new WordsApi("xxxx-xxxx-xxxxx-xxxx-xxxxxx", "xxxxxxxxxxxxxxxxxxx");
const localFile = "C:/Temp/SampleMailMergeTemplate.docx";
const dataFile = "C:/Temp/SampleMailMergeTemplateData.txt";
const localDataFile = fs.readFileSync(dataFile, 'utf8');
const remoteFileName = "TestExecuteMailMerge.docx";
const resultFileName = "MailMerge_output.docx";
const remoteFolder = "Temp";
//Upload File
const uploadRequest = new UploadFileRequest({
fileContent: fs.createReadStream(localFile),
path: remoteFolder + "/" + remoteFileName
});
wordsApi.uploadFile(uploadRequest).then((resultApi) => {
console.log('uploaded...');
}).catch(function(err) {
// Deal with an error
console.log(err);
});
//Mail Merge
const request = new ExecuteMailMergeRequest({
name: remoteFileName,
data: localDataFile,
folder: remoteFolder,
withRegions: false,
destFileName: remoteFolder + "/" + remoteFileName
});
wordsApi.executeMailMerge(request).then((result) => {
console.log(result.body);
console.log('Completed...');
}).catch(function(err) {
// Deal with an error
console.log(err);
});