Excel.IconSetConditionalFormat class
表示条件格式的图标集条件。
- 扩展
注解
属性
context | 与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。 |
criteria | 规则的条件和图标集的数组,条件图标的潜在自定义图标。 请注意,对于第一个条件,只能修改自定义图标,而类型、公式和运算符在设置时将被忽略。 |
reverse |
如果 |
show |
如果 |
style | 如果已设置,则显示条件格式的图标集选项。 |
方法
load(options) | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
set(properties, options) | 同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。 |
set(properties) | 基于现有的已加载对象,同时对对象设置多个属性。 |
toJSON() | 重写 JavaScript |
属性详细信息
context
criteria
规则的条件和图标集的数组,条件图标的潜在自定义图标。 请注意,对于第一个条件,只能修改自定义图标,而类型、公式和运算符在设置时将被忽略。
criteria: Excel.ConditionalIconCriterion[];
属性值
注解
示例
// 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();
});
reverseIconOrder
如果 true
为 ,则反转图标集的图标顺序。 请注意,如果使用自定义图标,则无法设置此设置。
reverseIconOrder: boolean;
属性值
boolean
注解
showIconOnly
style
如果已设置,则显示条件格式的图标集选项。
style: Excel.IconSet | "Invalid" | "ThreeArrows" | "ThreeArrowsGray" | "ThreeFlags" | "ThreeTrafficLights1" | "ThreeTrafficLights2" | "ThreeSigns" | "ThreeSymbols" | "ThreeSymbols2" | "FourArrows" | "FourArrowsGray" | "FourRedToBlack" | "FourRating" | "FourTrafficLights" | "FiveArrows" | "FiveArrowsGray" | "FiveRating" | "FiveQuarters" | "ThreeStars" | "ThreeTriangles" | "FiveBoxes";
属性值
Excel.IconSet | "Invalid" | "ThreeArrows" | "ThreeArrowsGray" | "ThreeFlags" | "ThreeTrafficLights1" | "ThreeTrafficLights2" | "ThreeSigns" | "ThreeSymbols" | "ThreeSymbols2" | "FourArrows" | "FourArrowsGray" | "FourRedToBlack" | "FourRating" | "FourTrafficLights" | "FiveArrows" | "FiveArrowsGray" | "FiveRating" | "FiveQuarters" | "ThreeStars" | "ThreeTriangles" | "FiveBoxes"
注解
示例
// 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();
});
方法详细信息
load(options)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()
。
load(options?: Excel.Interfaces.IconSetConditionalFormatLoadOptions): Excel.IconSetConditionalFormat;
参数
提供要加载对象的属性的选项。
返回
load(propertyNames)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()
。
load(propertyNames?: string | string[]): Excel.IconSetConditionalFormat;
参数
- propertyNames
-
string | string[]
逗号分隔的字符串或指定要加载的属性的字符串数组。
返回
load(propertyNamesAndPaths)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()
。
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Excel.IconSetConditionalFormat;
参数
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select
是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand
一个逗号分隔的字符串,指定要加载的导航属性。
返回
set(properties, options)
同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。
set(properties: Interfaces.IconSetConditionalFormatUpdateData, options?: OfficeExtension.UpdateOptions): void;
参数
一个 JavaScript 对象,其属性按同构方式构造为调用方法的对象的属性。
- options
- OfficeExtension.UpdateOptions
提供一个选项,用于在 properties 对象尝试设置任何只读属性时禁止显示错误。
返回
void
set(properties)
基于现有的已加载对象,同时对对象设置多个属性。
set(properties: Excel.IconSetConditionalFormat): void;
参数
- properties
- Excel.IconSetConditionalFormat
返回
void
toJSON()
重写 JavaScript toJSON()
方法,以便在将 API 对象传递给 JSON.stringify()
时提供更有用的输出。
JSON.stringify
(,反过来又调用toJSON
传递给它的 对象的 方法。) 而原始Excel.IconSetConditionalFormat
对象是 API 对象,toJSON
该方法返回一个纯 JavaScript 对象, (类型为 Excel.Interfaces.IconSetConditionalFormatData
) ,其中包含原始对象中任何已加载子属性的浅表副本。
toJSON(): Excel.Interfaces.IconSetConditionalFormatData;