Excel.ConditionalFormat class
条件付き書式の範囲、書式、ルール、およびその他のプロパティをカプセル化するオブジェクト。 条件付き書式オブジェクト モデルの詳細については、「Excel の範囲に条件付き書式を適用する」を参照してください。
- Extends
注釈
使用元
プロパティ
| cell |
現在の条件付き書式が |
| cell |
現在の条件付き書式が |
| color |
現在の条件付き書式が |
| color |
現在の条件付き書式が |
| context | オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。 |
| custom | 現在の条件付き書式がカスタム型の場合、カスタム条件付き書式プロパティを返します。 |
| custom |
現在の条件付き書式がカスタム型の場合、カスタム条件付き書式プロパティを返します。 |
| data |
現在の条件付き書式がデータ バーの場合、データ バーのプロパティを返します。 |
| data |
現在の条件付き書式がデータ バーの場合、データ バーのプロパティを返します。 |
| icon |
現在の条件付き書式が |
| icon |
現在の条件付き書式が |
| id | 現在の |
| preset | 事前設定された条件の条件付き書式を返します。 詳細については、 |
| preset |
事前設定された条件の条件付き書式を返します。 詳細については、 |
| priority | この条件付き書式が現在存在する条件付き書式コレクション内の優先度 (またはインデックス)。 これを変更すると、他の条件付き形式の優先順位も変更され、連続する優先順位が可能になります。 負の優先順位を使用して、後ろから始めます。 境界よりも大きい優先度を取得して、最大 (負の数の場合は最小) の優先度に設定されます。 また、優先順位を変更した場合、さらに変更を加える場合は、その新しい優先順位の場所でオブジェクトの新しいコピーを再フェッチする必要があることに注意してください。 |
| stop |
この条件付き書式の条件が満たされた場合、優先順位の低い書式はそのセルに影響を及ぼしません。 データ バー、アイコン セット、カラー スケールには |
| text |
現在の条件付き書式がテキスト型の場合、特定のテキスト条件付き書式プロパティを返します。 たとえば、単語 "Text" に一致するセルを書式設定する場合などです。 |
| text |
現在の条件付き書式がテキスト型の場合、特定のテキスト条件付き書式プロパティを返します。 たとえば、単語 "Text" に一致するセルを書式設定する場合などです。 |
| top |
現在の条件付き書式が |
| top |
現在の条件付き書式が |
| type | 条件付き書式の一種。 一度に設定できるのは 1 つだけです。 |
メソッド
| change |
条件付き書式ルール タイプをセル値に変更します。 |
| change |
条件付き書式ルールの種類をカラー スケールに変更します。 |
| change |
条件付き書式ルール タイプをテキスト比較に変更します。 |
| change |
条件付き書式ルールの種類をカスタムに変更します。 |
| change |
条件付き書式ルール タイプをデータ バーに変更します。 |
| change |
条件付き書式ルールの種類をアイコン セットに変更します。 |
| change |
条件付き書式ルール タイプを事前設定された条件に変更します。 |
| change |
条件付き書式ルール タイプを上/下に変更します。 |
| delete() | この条件付き書式を削除します。 |
| get |
条件付き書式が適用された範囲を返す。 条件付き書式が複数の範囲に適用されている場合は、エラーをスローします。 |
| get |
条件付き書式が適用される範囲を返します。 条件付き書式が複数の範囲に適用されている場合、このメソッドは |
| get |
条件付き書式が適用される 1 つ以上の四角形の範囲からなる |
| load(options) | オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| set(properties, options) | オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクト、または同じ型の別の API オブジェクトを渡すことができます。 |
| set(properties) | 既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。 |
| set |
条件付き書式ルールが適用される範囲を設定します。 |
| toJSON() | API オブジェクトが |
プロパティの詳細
cellValue
現在の条件付き書式が CellValue 型の場合、セル値の条件付き書式プロパティを返します。
readonly cellValue: Excel.CellValueConditionalFormat;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/14-conditional-formatting/conditional-formatting-basic.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
const range = sheet.getRange("B21:E23");
const conditionalFormat = range.conditionalFormats
.add(Excel.ConditionalFormatType.cellValue);
conditionalFormat.cellValue.format.font.color = "red";
conditionalFormat.cellValue.rule = { formula1: "=0", operator: "LessThan" };
await context.sync();
});
cellValueOrNullObject
現在の条件付き書式が CellValue 型の場合、セル値の条件付き書式プロパティを返します。
readonly cellValueOrNullObject: Excel.CellValueConditionalFormat;
プロパティ値
注釈
colorScale
現在の条件付き書式が ColorScale 型の場合、カラー スケールの条件付き書式プロパティを返します。
readonly colorScale: Excel.ColorScaleConditionalFormat;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/14-conditional-formatting/conditional-formatting-basic.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
const range = sheet.getRange("B2:M5");
const conditionalFormat = range.conditionalFormats
.add(Excel.ConditionalFormatType.colorScale);
const criteria = {
minimum: { formula: null, type: Excel.ConditionalFormatColorCriterionType.lowestValue, color: "blue" },
midpoint: { formula: "50", type: Excel.ConditionalFormatColorCriterionType.percent, color: "yellow" },
maximum: { formula: null, type: Excel.ConditionalFormatColorCriterionType.highestValue, color: "red" }
};
conditionalFormat.colorScale.criteria = criteria;
await context.sync();
});
colorScaleOrNullObject
現在の条件付き書式が ColorScale 型の場合、カラー スケールの条件付き書式プロパティを返します。
readonly colorScaleOrNullObject: Excel.ColorScaleConditionalFormat;
プロパティ値
注釈
context
オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。
context: RequestContext;
プロパティ値
custom
現在の条件付き書式がカスタム型の場合、カスタム条件付き書式プロパティを返します。
readonly custom: Excel.CustomConditionalFormat;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/14-conditional-formatting/conditional-formatting-basic.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
const range = sheet.getRange("B8:E13");
const conditionalFormat = range.conditionalFormats.add(Excel.ConditionalFormatType.custom);
conditionalFormat.custom.rule.formula = '=IF(B8>INDIRECT("RC[-1]",0),TRUE)';
conditionalFormat.custom.format.font.color = "green";
await context.sync();
});
customOrNullObject
現在の条件付き書式がカスタム型の場合、カスタム条件付き書式プロパティを返します。
readonly customOrNullObject: Excel.CustomConditionalFormat;
プロパティ値
注釈
dataBar
現在の条件付き書式がデータ バーの場合、データ バーのプロパティを返します。
readonly dataBar: Excel.DataBarConditionalFormat;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/14-conditional-formatting/conditional-formatting-basic.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
const range = sheet.getRange("B8:E13");
const conditionalFormat = range.conditionalFormats
.add(Excel.ConditionalFormatType.dataBar);
conditionalFormat.dataBar.barDirection = Excel.ConditionalDataBarDirection.leftToRight;
await context.sync();
});
dataBarOrNullObject
現在の条件付き書式がデータ バーの場合、データ バーのプロパティを返します。
readonly dataBarOrNullObject: Excel.DataBarConditionalFormat;
プロパティ値
注釈
iconSet
現在の条件付き書式が IconSet 型の場合、アイコン セットの条件付き書式プロパティを返します。
readonly iconSet: Excel.IconSetConditionalFormat;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/14-conditional-formatting/conditional-formatting-basic.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
const range = sheet.getRange("B8:E13");
const conditionalFormat = range.conditionalFormats
.add(Excel.ConditionalFormatType.iconSet);
const iconSetCF = conditionalFormat.iconSet;
iconSetCF.style = Excel.IconSet.threeTriangles;
/*
The iconSetCF.criteria array is automatically prepopulated with
criterion elements whose properties have been given default settings.
You can't write to each property of a criterion directly. Instead,
replace the whole criteria object.
With a "three*" icon set style, such as "threeTriangles", the third
element in the criteria array (criteria[2]) defines the "top" icon;
e.g., a green triangle. The second (criteria[1]) defines the "middle"
icon. The first (criteria[0]) defines the "low" icon, but it
can often be left empty as the following object shows, because every
cell that does not match the other two criteria always gets the low
icon.
*/
iconSetCF.criteria = [
{} as any,
{
type: Excel.ConditionalFormatIconRuleType.number,
operator: Excel.ConditionalIconCriterionOperator.greaterThanOrEqual,
formula: "=700"
},
{
type: Excel.ConditionalFormatIconRuleType.number,
operator: Excel.ConditionalIconCriterionOperator.greaterThanOrEqual,
formula: "=1000",
}
];
await context.sync();
});
iconSetOrNullObject
現在の条件付き書式が IconSet 型の場合、アイコン セットの条件付き書式プロパティを返します。
readonly iconSetOrNullObject: Excel.IconSetConditionalFormat;
プロパティ値
注釈
id
現在の ConditionalFormatCollectionの条件付き書式の優先順位。
readonly id: string;
プロパティ値
string
注釈
preset
事前設定された条件の条件付き書式を返します。 詳細については、Excel.PresetCriteriaConditionalFormatを参照してください。
readonly preset: Excel.PresetCriteriaConditionalFormat;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/14-conditional-formatting/conditional-formatting-basic.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
const range = sheet.getRange("B2:M5");
const conditionalFormat = range.conditionalFormats
.add(Excel.ConditionalFormatType.presetCriteria);
conditionalFormat.preset.format.font.color = "white";
conditionalFormat.preset.rule = { criterion: Excel.ConditionalFormatPresetCriterion.oneStdDevAboveAverage };
await context.sync();
});
presetOrNullObject
事前設定された条件の条件付き書式を返します。 詳細については、Excel.PresetCriteriaConditionalFormatを参照してください。
readonly presetOrNullObject: Excel.PresetCriteriaConditionalFormat;
プロパティ値
注釈
priority
この条件付き書式が現在存在する条件付き書式コレクション内の優先度 (またはインデックス)。 これを変更すると、他の条件付き形式の優先順位も変更され、連続する優先順位が可能になります。 負の優先順位を使用して、後ろから始めます。 境界よりも大きい優先度を取得して、最大 (負の数の場合は最小) の優先度に設定されます。 また、優先順位を変更した場合、さらに変更を加える場合は、その新しい優先順位の場所でオブジェクトの新しいコピーを再フェッチする必要があることに注意してください。
priority: number;
プロパティ値
number
注釈
stopIfTrue
この条件付き書式の条件が満たされた場合、優先順位の低い書式はそのセルに影響を及ぼしません。 データ バー、アイコン セット、カラー スケールにはStopIfTrueの概念がないため、値がnullされます。
stopIfTrue: boolean;
プロパティ値
boolean
注釈
textComparison
現在の条件付き書式がテキスト型の場合、特定のテキスト条件付き書式プロパティを返します。 たとえば、単語 "Text" に一致するセルを書式設定する場合などです。
readonly textComparison: Excel.TextConditionalFormat;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/14-conditional-formatting/conditional-formatting-basic.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
const range = sheet.getRange("B16:D18");
const conditionalFormat = range.conditionalFormats
.add(Excel.ConditionalFormatType.containsText);
conditionalFormat.textComparison.format.font.color = "red";
conditionalFormat.textComparison.rule = { operator: Excel.ConditionalTextOperator.contains, text: "Delayed" };
await context.sync();
});
textComparisonOrNullObject
現在の条件付き書式がテキスト型の場合、特定のテキスト条件付き書式プロパティを返します。 たとえば、単語 "Text" に一致するセルを書式設定する場合などです。
readonly textComparisonOrNullObject: Excel.TextConditionalFormat;
プロパティ値
注釈
topBottom
現在の条件付き書式が TopBottom 型の場合、上位/下位の条件付き書式プロパティを返します。 たとえば、上位 10% または下位 10 の項目を書式設定する場合などです。
readonly topBottom: Excel.TopBottomConditionalFormat;
プロパティ値
注釈
topBottomOrNullObject
現在の条件付き書式が TopBottom 型の場合、上位/下位の条件付き書式プロパティを返します。 たとえば、上位 10% または下位 10 の項目を書式設定する場合などです。
readonly topBottomOrNullObject: Excel.TopBottomConditionalFormat;
プロパティ値
注釈
type
条件付き書式の一種。 一度に設定できるのは 1 つだけです。
readonly type: Excel.ConditionalFormatType | "Custom" | "DataBar" | "ColorScale" | "IconSet" | "TopBottom" | "PresetCriteria" | "ContainsText" | "CellValue";
プロパティ値
Excel.ConditionalFormatType | "Custom" | "DataBar" | "ColorScale" | "IconSet" | "TopBottom" | "PresetCriteria" | "ContainsText" | "CellValue"
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/14-conditional-formatting/conditional-formatting-basic.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
const worksheetRange = sheet.getRange();
worksheetRange.conditionalFormats.load("type");
await context.sync();
let cfRangePairs: { cf: Excel.ConditionalFormat, range: Excel.Range }[] = [];
worksheetRange.conditionalFormats.items.forEach(item => {
cfRangePairs.push({
cf: item,
range: item.getRange().load("address")
});
});
await context.sync();
if (cfRangePairs.length > 0) {
cfRangePairs.forEach(item => {
console.log(item.cf.type);
});
} else {
console.log("No conditional formats applied.");
}
});
メソッドの詳細
changeRuleToCellValue(properties)
条件付き書式ルール タイプをセル値に変更します。
changeRuleToCellValue(properties: Excel.ConditionalCellValueRule): void;
パラメーター
- properties
- Excel.ConditionalCellValueRule
セル値の条件付き書式ルールに設定するプロパティ。
返品
void
注釈
changeRuleToColorScale()
changeRuleToContainsText(properties)
条件付き書式ルール タイプをテキスト比較に変更します。
changeRuleToContainsText(properties: Excel.ConditionalTextComparisonRule): void;
パラメーター
- properties
- Excel.ConditionalTextComparisonRule
テキスト比較条件付き書式ルールに設定するプロパティ。
返品
void
注釈
changeRuleToCustom(formula)
条件付き書式ルールの種類をカスタムに変更します。
changeRuleToCustom(formula: string): void;
パラメーター
- formula
-
string
カスタム条件付き書式ルールに設定する数式。
返品
void
注釈
changeRuleToDataBar()
changeRuleToIconSet()
changeRuleToPresetCriteria(properties)
条件付き書式ルール タイプを事前設定された条件に変更します。
changeRuleToPresetCriteria(properties: Excel.ConditionalPresetCriteriaRule): void;
パラメーター
- properties
- Excel.ConditionalPresetCriteriaRule
事前設定された条件の条件付き書式ルールに設定するプロパティ。
返品
void
注釈
changeRuleToTopBottom(properties)
条件付き書式ルール タイプを上/下に変更します。
changeRuleToTopBottom(properties: Excel.ConditionalTopBottomRule): void;
パラメーター
- properties
- Excel.ConditionalTopBottomRule
上位/下位の条件付き書式ルールに設定するプロパティ。
返品
void
注釈
delete()
getRange()
条件付き書式が適用された範囲を返す。 条件付き書式が複数の範囲に適用されている場合は、エラーをスローします。
getRange(): Excel.Range;
返品
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/14-conditional-formatting/conditional-formatting-basic.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
const worksheetRange = sheet.getRange();
worksheetRange.conditionalFormats.load("type");
await context.sync();
let cfRangePairs: { cf: Excel.ConditionalFormat, range: Excel.Range }[] = [];
worksheetRange.conditionalFormats.items.forEach(item => {
cfRangePairs.push({
cf: item,
range: item.getRange().load("address")
});
});
await context.sync();
if (cfRangePairs.length > 0) {
cfRangePairs.forEach(item => {
console.log(item.cf.type);
});
} else {
console.log("No conditional formats applied.");
}
});
getRangeOrNullObject()
条件付き書式が適用される範囲を返します。 条件付き書式が複数の範囲に適用されている場合、このメソッドは isNullObject プロパティが true に設定されたオブジェクトを返します。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。
getRangeOrNullObject(): Excel.Range;
返品
注釈
getRanges()
条件付き書式が適用される 1 つ以上の四角形の範囲からなる RangeAreasを返します。
getRanges(): Excel.RangeAreas;
返品
注釈
load(options)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(options?: Excel.Interfaces.ConditionalFormatLoadOptions): Excel.ConditionalFormat;
パラメーター
読み込むオブジェクトのプロパティのオプションを指定します。
返品
load(propertyNames)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNames?: string | string[]): Excel.ConditionalFormat;
パラメーター
- propertyNames
-
string | string[]
読み込むプロパティを指定するコンマ区切りの文字列または文字列の配列。
返品
load(propertyNamesAndPaths)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Excel.ConditionalFormat;
パラメーター
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select は読み込むプロパティを指定するコンマ区切りの文字列であり、 propertyNamesAndPaths.expand は読み込むナビゲーションのプロパティを指定するコンマ区切りの文字列です。
返品
set(properties, options)
オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクト、または同じ型の別の API オブジェクトを渡すことができます。
set(properties: Interfaces.ConditionalFormatUpdateData, options?: OfficeExtension.UpdateOptions): void;
パラメーター
- properties
- Excel.Interfaces.ConditionalFormatUpdateData
メソッドが呼び出されたオブジェクトのプロパティと同型構造のプロパティを持つ JavaScript オブジェクト。
- options
- OfficeExtension.UpdateOptions
プロパティ オブジェクトが読み取り専用プロパティを設定しようとした場合にエラーを抑制するオプションを提供します。
返品
void
set(properties)
既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。
set(properties: Excel.ConditionalFormat): void;
パラメーター
- properties
- Excel.ConditionalFormat
返品
void
setRanges(ranges)
条件付き書式ルールが適用される範囲を設定します。
setRanges(ranges: Range | RangeAreas | string): void;
パラメーター
- ranges
-
Excel.Range | Excel.RangeAreas | string
このルールを適用する 1 つまたは複数の範囲のコレクション。
返品
void
注釈
toJSON()
API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Excel.ConditionalFormat オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Excel.Interfaces.ConditionalFormatData と型指定) を返します。
toJSON(): Excel.Interfaces.ConditionalFormatData;