ExcelScript.CustomConditionalFormat interface

表示自定义条件格式类型。

注解

示例

/**
 * This script applies a custom three-color conditional formatting to the selected range.
 * The three colors represent positive, negative, or no changes from the values in the previous column.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the selected cells.
  let selectedRange = workbook.getSelectedRange();

  // Apply a rule for positive change from the previous column.
  let positiveChange = selectedRange.addConditionalFormat(ExcelScript.ConditionalFormatType.custom);
  positiveChange.getCustom().getFormat().getFill().setColor("lightgreen");
  positiveChange.getCustom().getRule().setFormula(`=${selectedRange.getCell(0, 0).getAddress()}>${selectedRange.getOffsetRange(0, -1).getCell(0, 0).getAddress()}`);

  // Apply a rule for negative change from the previous column.
  let negativeChange = selectedRange.addConditionalFormat(ExcelScript.ConditionalFormatType.custom);
  negativeChange.getCustom().getFormat().getFill().setColor("pink");
  negativeChange.getCustom().getRule().setFormula(`=${selectedRange.getCell(0, 0).getAddress()}<${selectedRange.getOffsetRange(0, -1).getCell(0, 0).getAddress()}`);

  // Apply a rule for no change from the previous column.
  let noChange = selectedRange.addConditionalFormat(ExcelScript.ConditionalFormatType.custom);
  noChange.getCustom().getFormat().getFill().setColor("lightyellow");
  noChange.getCustom().getRule().setFormula(`=${selectedRange.getCell(0, 0).getAddress()}=${selectedRange.getOffsetRange(0, -1).getCell(0, 0).getAddress()}`);
}

方法

getFormat()

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

getRule()

指定 Rule 此条件格式上的 对象。

方法详细信息

getFormat()

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

getFormat(): ConditionalRangeFormat;

返回

getRule()

指定 Rule 此条件格式上的 对象。

getRule(): ConditionalFormatRule;

返回