ExcelScript.CellValueConditionalFormat interface

表示单元格值条件格式。

注解

示例

/**
 * 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);
}

方法

getFormat()

返回格式对象,该对象封装条件格式字体、填充、边框和其他属性。

getRule()

指定此条件格式的规则对象。

setRule(rule)

指定此条件格式的规则对象。

方法详细信息

getFormat()

返回格式对象,该对象封装条件格式字体、填充、边框和其他属性。

getFormat(): ConditionalRangeFormat;

返回

getRule()

指定此条件格式的规则对象。

getRule(): ConditionalCellValueRule;

返回

setRule(rule)

指定此条件格式的规则对象。

setRule(rule: ConditionalCellValueRule): void;

参数

返回

void