ExcelScript.ConditionalFormat interface

条件付き書式の範囲、書式、規則、およびその他のプロパティをカプセル化するオブジェクト。

メソッド

delete()

この条件付き書式を削除します。

getCellValue()

現在の条件付き書式が型の場合は、セル値の条件付き書式プロパティを CellValue 返します。

getColorScale()

現在の条件付き書式が型の場合は、カラー スケールの条件付き書式プロパティを ColorScale 返します。

getCustom()

現在の条件付き書式がカスタム型の場合は、カスタム条件付き書式プロパティを返します。

getDataBar()

現在の条件付き書式がデータ バーの場合は、データ バーのプロパティを返します。

getIconSet()

現在の条件付き書式が型の場合は、アイコン セットの条件付き書式プロパティを IconSet 返します。

getId()

現在 ConditionalFormatCollectionの の条件付き書式の優先順位。

getPreset()

事前設定された条件の条件付き形式を返します。 詳細については、ExcelScript.PresetCriteriaConditionalFormatを参照してください。

getPriority()

この条件付き書式が現在存在する条件付き書式コレクション内の優先順位 (またはインデックス)。 これを変更すると、他の条件付き形式の優先順位も変更され、連続した優先順位が可能になります。 バックから始める場合は、負の優先順位を使用します。 境界を超える優先順位は、最大 (負の場合は最小) の優先順位を取得して設定します。 また、優先度を変更する場合は、さらに変更を加える場合は、その新しい優先度の場所にあるオブジェクトの新しいコピーを再フェッチする必要があることに注意してください。

getRange()

条件付き書式が適用される範囲を返します。 条件付き書式が複数の範囲に適用されている場合、このメソッドは を返します undefined

getRanges()

条件付き書式が RangeAreas適用される 1 つまたは複数の四角形の範囲を含む 、 を返します。

getStopIfTrue()

この条件付き書式の条件が満たされた場合、優先順位の低い書式はそのセルに影響を及ぼしません。 値は null 、これらの概念 StopIfTrue がないため、データ バー、アイコン セット、カラー スケールにあります。

getTextComparison()

現在の条件付き書式がテキスト型の場合は、特定のテキスト条件付き書式プロパティを返します。 たとえば、"Text" という単語に一致するセルの書式を設定します。

getTopBottom()

現在の条件付き書式が型の場合は、上位/下位の条件付き書式プロパティを TopBottom 返します。 たとえば、上位 10% または下位 10 個の項目を書式設定します。

getType()

条件付き書式の種類。 一度に設定できるのは 1 つだけです。

setPriority(priority)

この条件付き書式が現在存在する条件付き書式コレクション内の優先順位 (またはインデックス)。 これを変更すると、他の条件付き形式の優先順位も変更され、連続した優先順位が可能になります。 バックから始める場合は、負の優先順位を使用します。 境界を超える優先順位は、最大 (負の場合は最小) の優先順位を取得して設定します。 また、優先度を変更する場合は、さらに変更を加える場合は、その新しい優先度の場所にあるオブジェクトの新しいコピーを再フェッチする必要があることに注意してください。

setStopIfTrue(stopIfTrue)

この条件付き書式の条件が満たされた場合、優先順位の低い書式はそのセルに影響を及ぼしません。 値は null 、これらの概念 StopIfTrue がないため、データ バー、アイコン セット、カラー スケールにあります。

メソッドの詳細

delete()

この条件付き書式を削除します。

delete(): void;

戻り値

void

getCellValue()

現在の条件付き書式が型の場合は、セル値の条件付き書式プロパティを CellValue 返します。

getCellValue(): CellValueConditionalFormat | undefined;

戻り値

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

}

getColorScale()

現在の条件付き書式が型の場合は、カラー スケールの条件付き書式プロパティを ColorScale 返します。

getColorScale(): ColorScaleConditionalFormat | undefined;

戻り値

/**
 * This script applies a red, white, and blue color scale to the selected range.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the selected range.
  let selectedRange = workbook.getSelectedRange();

  // Create a new conditional formatting object by adding one to the range.
  let conditionalFormatting = selectedRange.addConditionalFormat(ExcelScript.ConditionalFormatType.colorScale);

  // Set the colors for the three parts of the scale: minimum, midpoint, and maximum.
  conditionalFormatting.getColorScale().setCriteria({
    minimum: {
      color:"#F8696B", /* A pale red. */
      type:ExcelScript.ConditionalFormatColorCriterionType.lowestValue
    },
    midpoint: {
      color: "#FCFCFF", /* Slightly off-white. */
      formula:'=50',type:ExcelScript.ConditionalFormatColorCriterionType.percentile
    },
    maximum: {
      color: "#5A8AC6", /* A pale blue. */
      type:ExcelScript.ConditionalFormatColorCriterionType.highestValue
    }
  });
}

getCustom()

現在の条件付き書式がカスタム型の場合は、カスタム条件付き書式プロパティを返します。

getCustom(): CustomConditionalFormat | undefined;

戻り値

/**
 * This script applies a custom conditional formatting to the selected range.
 * A light-green fill is applied to a cell if the value is larger than the value in the row's 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()}`);
}

getDataBar()

現在の条件付き書式がデータ バーの場合は、データ バーのプロパティを返します。

getDataBar(): DataBarConditionalFormat | undefined;

戻り値

/**
 * This script creates data bar conditional formatting on the selected range.
 * The scale of the data bar goes from 0 to 1000.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the selected range.
  const selected = workbook.getSelectedRange();
  
  // Create new conditional formatting on the range.
  const format = selected.addConditionalFormat(ExcelScript.ConditionalFormatType.dataBar);
  const dataBarFormat = format.getDataBar();

  // Set the lower bound of the data bar formatting to be 0.
  const lowerBound: ExcelScript.ConditionalDataBarRule = {
    type: ExcelScript.ConditionalFormatRuleType.number,
    formula: "0"
  };
  dataBarFormat.setLowerBoundRule(lowerBound);

  // Set the upper bound of the data bar formatting to be 1000.
  const upperBound: ExcelScript.ConditionalDataBarRule = {
    type: ExcelScript.ConditionalFormatRuleType.number,
    formula: "1000"
  };
  dataBarFormat.setUpperBoundRule(upperBound);
}

getIconSet()

現在の条件付き書式が型の場合は、アイコン セットの条件付き書式プロパティを IconSet 返します。

getIconSet(): IconSetConditionalFormat | undefined;

戻り値

/**
 * This script applies icon set conditional formatting to a range.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the range "A1:A5" on the current worksheet.
  const sheet = workbook.getActiveWorksheet();
  const range = sheet.getRange("A1:A5");

  // Create icon set conditional formatting on the range.
  const conditionalFormatting = range.addConditionalFormat(ExcelScript.ConditionalFormatType.iconSet);

  // Use the "3 Traffic Lights (Unrimmed)" set.
  conditionalFormatting.getIconSet().setStyle(ExcelScript.IconSet.threeTrafficLights1);

  // Set the criteria to use a different icon for the bottom, middle, and top thirds of the values in the range.
  conditionalFormatting.getIconSet().setCriteria([
    {
      formula:'=0',operator:ExcelScript.ConditionalIconCriterionOperator.greaterThanOrEqual,
      type:ExcelScript.ConditionalFormatIconRuleType.percent
    },
    {
      formula:'=33',operator:ExcelScript.ConditionalIconCriterionOperator.greaterThanOrEqual,
      type:ExcelScript.ConditionalFormatIconRuleType.percent},
    {
      formula:'=67',operator:ExcelScript.ConditionalIconCriterionOperator.greaterThanOrEqual,
      type:ExcelScript.ConditionalFormatIconRuleType.percent
    }]);
}

getId()

現在 ConditionalFormatCollectionの の条件付き書式の優先順位。

getId(): string;

戻り値

string

getPreset()

事前設定された条件の条件付き形式を返します。 詳細については、ExcelScript.PresetCriteriaConditionalFormatを参照してください。

getPreset(): PresetCriteriaConditionalFormat | undefined;

戻り値

/**
 * This script applies a conditional format that uses a preset criterion.
 * Any cell in row 1 will have the color fill set to green if it is a duplicate value
 * (of anything else in row 1).
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the range for row 1.
  const sheet = workbook.getActiveWorksheet();
  const formattedRange = sheet.getRange("1:1");

  // Add new conditional formatting to that range.
  const conditionalFormat = formattedRange.addConditionalFormat(
    ExcelScript.ConditionalFormatType.presetCriteria);

  // Set the conditional formatting to apply a green fill.
  const presetFormat = conditionalFormat.getPreset();
  presetFormat.getFormat().getFill().setColor("green");

  // Set a rule to apply the conditional format when values are duplicated in the range.
  const duplicateRule: ExcelScript.ConditionalPresetCriteriaRule = {
    criterion: ExcelScript.ConditionalFormatPresetCriterion.duplicateValues
  };
  presetFormat.setRule(duplicateRule);
}

getPriority()

この条件付き書式が現在存在する条件付き書式コレクション内の優先順位 (またはインデックス)。 これを変更すると、他の条件付き形式の優先順位も変更され、連続した優先順位が可能になります。 バックから始める場合は、負の優先順位を使用します。 境界を超える優先順位は、最大 (負の場合は最小) の優先順位を取得して設定します。 また、優先度を変更する場合は、さらに変更を加える場合は、その新しい優先度の場所にあるオブジェクトの新しいコピーを再フェッチする必要があることに注意してください。

getPriority(): number;

戻り値

number

getRange()

条件付き書式が適用される範囲を返します。 条件付き書式が複数の範囲に適用されている場合、このメソッドは を返します undefined

getRange(): Range;

戻り値

getRanges()

条件付き書式が RangeAreas適用される 1 つまたは複数の四角形の範囲を含む 、 を返します。

getRanges(): RangeAreas;

戻り値

getStopIfTrue()

この条件付き書式の条件が満たされた場合、優先順位の低い書式はそのセルに影響を及ぼしません。 値は null 、これらの概念 StopIfTrue がないため、データ バー、アイコン セット、カラー スケールにあります。

getStopIfTrue(): boolean;

戻り値

boolean

getTextComparison()

現在の条件付き書式がテキスト型の場合は、特定のテキスト条件付き書式プロパティを返します。 たとえば、"Text" という単語に一致するセルの書式を設定します。

getTextComparison(): TextConditionalFormat | undefined;

戻り値

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

getTopBottom()

現在の条件付き書式が型の場合は、上位/下位の条件付き書式プロパティを TopBottom 返します。 たとえば、上位 10% または下位 10 個の項目を書式設定します。

getTopBottom(): TopBottomConditionalFormat | undefined;

戻り値

/**
 * This script applies top/bottom conditional formatting to a range.
 * The top 2 values in the range will have the cell fill color changed to green.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the range to format.
  const sheet = workbook.getWorksheet("TopBottom");
  const dataRange = sheet.getRange("B2:D5");

  // Set the fill color to green for the top 2 values in the range.
  const topBottomFormat = dataRange.addConditionalFormat(
    ExcelScript.ConditionalFormatType.topBottom).getTopBottom();
  topBottomFormat.getFormat().getFill().setColor("green");
  topBottomFormat.setRule({
    rank: 2, /* The numeric threshold. */
    type: ExcelScript.ConditionalTopBottomCriterionType.topItems /* The type of the top/bottom condition. */
  });
}

getType()

条件付き書式の種類。 一度に設定できるのは 1 つだけです。

getType(): ConditionalFormatType;

戻り値

setPriority(priority)

この条件付き書式が現在存在する条件付き書式コレクション内の優先順位 (またはインデックス)。 これを変更すると、他の条件付き形式の優先順位も変更され、連続した優先順位が可能になります。 バックから始める場合は、負の優先順位を使用します。 境界を超える優先順位は、最大 (負の場合は最小) の優先順位を取得して設定します。 また、優先度を変更する場合は、さらに変更を加える場合は、その新しい優先度の場所にあるオブジェクトの新しいコピーを再フェッチする必要があることに注意してください。

setPriority(priority: number): void;

パラメーター

priority

number

戻り値

void

setStopIfTrue(stopIfTrue)

この条件付き書式の条件が満たされた場合、優先順位の低い書式はそのセルに影響を及ぼしません。 値は null 、これらの概念 StopIfTrue がないため、データ バー、アイコン セット、カラー スケールにあります。

setStopIfTrue(stopIfTrue: boolean): void;

パラメーター

stopIfTrue

boolean

戻り値

void