spreadsheetAddConditionalFormatting

Adds a conditional formatting rule to the active sheet of a spreadsheet workbook. Pass a struct with range (A1 cell range), operator (equal, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual, notEqual or between, default equal), value (the comparison value) and format (the same format struct keys accepted by formatCell). Alternatively pass { type: "colorScale", range, colors: [ ... ] } with two or three colours to add a colour-scale rule. The fluent member form is addConditionalFormatting({...}).

spreadsheetAddConditionalFormatting(spreadsheetObj, formatStruct) → returns any

This function requires RustCFML.  Not supported on Lucee, Adobe ColdFusion, etc.

Argument Reference

spreadsheetObj any
Required

The spreadsheet workbook object to add the conditional formatting to.

format struct
Required

Struct describing the rule: range (A1 cell range), operator (equal|greaterThan|greaterThanOrEqual|lessThan|lessThanOrEqual|notEqual|between), value, format (cellIs rule), or type="colorScale" with a colors array of 2 or 3 colour names/hex values.

Compatibility

RustCFML:

Not supported on wasm32.

Examples
Sample code invoking the spreadsheetAddConditionalFormatting function

A cellIs rule that bolds and fills matching cells yellow.

wb = Spreadsheet("xlsx");
spreadsheetAddConditionalFormatting(wb, {
	range: "B2:B100",
	operator: "greaterThan",
	value: "100",
	format: { bold: true, bgcolor: "yellow" }
});

A three-colour scale from red to green across a range.

wb = Spreadsheet("xlsx");
spreadsheetAddConditionalFormatting(wb, {
	range: "B2:B100",
	type: "colorScale",
	colors: ["red", "yellow", "green"]
});

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub