ExcelScript.CellValueConditionalFormat interface
Represents a cell value conditional format.
TypeScript
/**
* This script applies conditional formatting to a range.
* That formatting is conditional upon the cell's numerical value.
* Any value between 50 and 75 will have the cell fill color changed and the font made italic.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the range to format.
const sheet = workbook.getActiveWorksheet();
const ratingColumn = sheet.getRange("D2:D20");
// Add cell value conditional formatting.
const cellValueConditionalFormatting : ExcelScript.CellValueConditionalFormat
= ratingColumn.addConditionalFormat(ExcelScript.ConditionalFormatType.cellValue).getCellValue();
// Create the condition, in this case when the cell value is between 50 and 75.
let rule: ExcelScript.ConditionalCellValueRule = {
formula1: "50",
formula2: "75",
operator: ExcelScript.ConditionalCellValueOperator.between
};
cellValueConditionalFormatting.setRule(rule);
// Set the format to apply when the condition is met.
let format = cellValueConditionalFormatting.getFormat();
format.getFill().setColor("yellow");
format.getFont().setItalic(true);
}
get |
Returns a format object, encapsulating the conditional formats font, fill, borders, and other properties. |
get |
Specifies the rule object on this conditional format. |
set |
Specifies the rule object on this conditional format. |
Returns a format object, encapsulating the conditional formats font, fill, borders, and other properties.
TypeScript
getFormat(): ConditionalRangeFormat;
Returns
Specifies the rule object on this conditional format.
TypeScript
getRule(): ConditionalCellValueRule;
Returns
Specifies the rule object on this conditional format.
TypeScript
setRule(rule: ConditionalCellValueRule): void;
Parameters
Returns
void
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Office Scripts feedback
Office Scripts is an open source project. Select a link to provide feedback: