Free Support Forum - aspose.cloud

Conditional formatting of a cell/ row (background color) using aspose cloud word for nodejs


#1

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.


#2

@yogibittint

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.


#3

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)


#4

@yogibittint

Thanks for sharing expected output document. We are looking into your requirements and will update you soon.


#5

@yogibittint

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)


#6

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.


#7

@yogibittint,

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?


#8

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).


#9

@yogibittint

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);
});