This topic describes the API operations that are related to the FormatConditions object of table documents.
FormatConditions
Range.FormatConditions
Queries all conditional formats in a specified range.
Syntax
expression.Range.FormatConditions
expression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Query a range object. const range = await app.Range('A1'); // Query all conditional formats in the range. const formatConditions = await range.FormatConditions; }
Methods
Range.FormatConditions.Add()
Adds a conditional format to a specified range by using the Add()
method.
Syntax
expression.Range.FormatConditions.Add({ Type, Operator, Formula1, Formula2 })
expression: the document type application object.
Parameters
Property
Data type
Required
Description
Type
Enum
Yes
Specifies whether the conditional format is based on a cell value or an expression. For more information, see XlFormatConditionType.
Operator
Number
No
The conditional format operator. For more information, see XlFormatConditionOperator.
Formula1
Number
No
The value or expression associated with the conditional format. The value of this parameter can be a constant, a string, a cell reference, or a formula.
Formula2
Number
No
The value or expression associated with the second part of the conditional format if the Operator parameter is set to
xlBetween
orxlNotBetween
. The value can be a constant, a string, a cell reference, or a formula.Ignore this parameter if the value of the Operator parameter is not
xlBetween
orxlNotBetween
.
Example
async function example() { await instance.ready(); const app = instance.Application; // Query a range object. const range = await app.Range('A4:D5'); // Select the range. await range.Select(); // Set a formula. range.Formula = 'Aliyun'; // Query all conditional formats. const formatConditions = await range.FormatConditions; // Add a conditional format. await formatConditions.Add( app.Enum.XlFormatConditionType.xlExpression, undefined, '=D1=1', ); }
Range.FormatConditions.With()
Modifies a conditional format by using the With()
method.
Syntax
expression.Range.FormatConditions.With({ Interior, Font, Borders })
expression: the document type application object.
Parameters
Property
Data type
Required
Description
Interior
Object
No
The internal property object.
Font
Object
No
The font object.
Borders
Object
No
The border object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Query a range object. const range = await app.Range('A4:D5'); // Select the range. await range.Select(); // Set a formula. range.Formula = 'Aliyun'; // Query all conditional formats. const formatConditions = await range.FormatConditions; // Add a conditional format. await formatConditions.Add( app.Enum.XlFormatConditionType.xlExpression, undefined, '=D1=1', ); // Modify the conditional format. await formatConditionsAdd.With({ Interior: { Color: '#000000' }, Font: { Bold: true, Color: '#FF0000', Underline: 2, Italic: true, Strikethrough: true }, Border: { LineStyle: -4119, Color: '#FF0000' }, }); }