Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

XL.Sheet.AddConditionalFormatting

Adds a conditional formatting rules to the sheet.

Component Version macOS Windows Linux Server iOS SDK
XL 14.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "XL.Sheet.AddConditionalFormatting"; BookRef; SheetIndex; rowFirst; rowLast; ColFirst; ColLast )   More

Parameters

Parameter Description Example
BookRef The reference number for the workbook. $ref
SheetIndex The index of the sheet. This number ranges from 0 to XL.Book.SheetCount-1. 0
rowFirst The first row for the area. First row has index 0. $row
rowLast The last row for the area. First row has index 0. $row
ColFirst The first column for the area. First column has index 0. $column
ColLast The last column for the area. First column has index 0. $column+1

Result

Returns conditional formatting index number or error.

Description

Adds a conditional formatting rules to the sheet.
Requires LibXL 4.1 and only for xlsx files.

With version 5.1 you need to pass a rectangle here for the first range.

Examples

Highlighting alternating rows:

# add conditional format
Set Variable [ $cFormat ; Value: MBS("XL.Book.AddConditionalFormat"; $book) ]
Set Variable [ $r ; Value: MBS("XL.ConditionalFormat.SetFillPattern"; $book; $cFormat; 1 /* solid */) ]
Set Variable [ $r ; Value: MBS("XL.ConditionalFormat.SetPatternBackgroundColor"; $book; $cFormat; MBS("XL.Color.Pack"; $book; 240; 240; 240)) ]
#
Set Variable [ $CF ; Value: MBS("XL.Sheet.addConditionalFormatting"; $book; $sheet) ]
Set Variable [ $r ; Value: MBS("XL.ConditionalFormating.AddRange"; $book; $CF; 4; 20; 1; 10) ]
Set Variable [ $r ; Value: MBS("XL.ConditionalFormating.AddRule"; $book; $CF; 6 /* Expression */; $cFormat; "=MOD(ROW(),2)=0") ]

See also

Release notes

Blog Entries

Created 30th March 2024, last changed 30th January 2026


XL.NewBook - XL.Sheet.AddDataValidation