ExcelScript.TextConditionalFormat interface
表示特定的文本条件格式。
注解
示例
/**
* This script adds conditional formatting to the first column in the worksheet.
* This formatting gives the cells a green fill if they have text starting with "Excel".
*/
function main(workbook: ExcelScript.Workbook) {
// Get the first column in the current worksheet.
const currentSheet = workbook.getActiveWorksheet();
const firstColumn = currentSheet.getRange("A:A");
// Add conditional formatting based on the text in the cells.
const textConditionFormat: ExcelScript.TextConditionalFormat =
firstColumn.addConditionalFormat(ExcelScript.ConditionalFormatType.containsText).getTextComparison();
// Set the conditional format to provide a green fill.
textConditionFormat.getFormat().getFill().setColor("green");
// Apply the condition rule that the text begins with "Excel".
const textRule: ExcelScript.ConditionalTextComparisonRule = {
operator: ExcelScript.ConditionalTextOperator.beginsWith,
text: "Excel"
};
textConditionFormat.setRule(textRule);
}
方法
get |
返回格式对象,该对象封装条件格式的字体、填充、边框和其他属性。 |
get |
条件格式的规则。 |
set |
条件格式的规则。 |
方法详细信息
getFormat()
返回格式对象,该对象封装条件格式的字体、填充、边框和其他属性。
getFormat(): ConditionalRangeFormat;
返回
getRule()
setRule(rule)
条件格式的规则。
setRule(rule: ConditionalTextComparisonRule): void;
参数
返回
void