Skip to main content

SetColor

Sets the format color for the color scale criterion.

Syntax

expression.SetColor(oColor);

expression - A variable that represents a ApiColorScaleCriterion class.

Parameters

NameRequired/OptionalData typeDefaultDescription
oColorRequiredApiColorThe ApiColor object specifying the color.

Returns

This method doesn't return any data.

Example

Assign a specific color to a color scale rule point in a spreadsheet.

// How do I change the color used at a boundary point of a color scale rule in a spreadsheet?

// Customize the gradient appearance of a color scale rule by updating the color at one of its stops in a spreadsheet.

let worksheet = Api.GetActiveSheet();

worksheet.GetRange("A1").SetValue("Test Data");
worksheet.GetRange("A2").SetValue(10);
worksheet.GetRange("A3").SetValue(30);
worksheet.GetRange("A4").SetValue(50);
worksheet.GetRange("A5").SetValue(70);
worksheet.GetRange("A6").SetValue(90);

let dataRange = worksheet.GetRange("A2:A6");
let formatConditions = dataRange.GetFormatConditions();

let colorScale = formatConditions.AddColorScale(2);
let criteria = colorScale.GetColorScaleCriteria();

if (criteria && criteria.length > 0) {
worksheet.GetRange("C1").SetValue("Before Color:");
worksheet.GetRange("C2").SetValue(criteria[0].GetColor() ? "Set" : "None");

let newColor = Api.CreateColorFromRGB(255, 0, 0);
criteria[0].SetColor(newColor);

worksheet.GetRange("C3").SetValue("After Color:");
worksheet.GetRange("C4").SetValue(criteria[0].GetColor() ? "Set" : "None");
}