Skip to content

Commit 0fd767f

Browse files
authored
Add top/bottom conditional formatting sample (#312)
1 parent bd4eaca commit 0fd767f

File tree

6 files changed

+54
-10
lines changed

6 files changed

+54
-10
lines changed

docs/docs-ref-autogen/excel/excelscript/excelscript.conditionaldatabarrule.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ remarks: |-
1111
1212
```TypeScript
1313
/**
14-
* This script creates data bar conditional formatting on the select ranged.
14+
* This script creates data bar conditional formatting on the selected range.
1515
* The scale of the data bar goes from 0 to 1000.
1616
*/
1717
function main(workbook: ExcelScript.Workbook) {

docs/docs-ref-autogen/excel/excelscript/excelscript.conditionalformat.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ methods:
165165
166166
```TypeScript
167167
/**
168-
* This script creates data bar conditional formatting on the select ranged.
168+
* This script creates data bar conditional formatting on the selected range.
169169
* The scale of the data bar goes from 0 to 1000.
170170
*/
171171
function main(workbook: ExcelScript.Workbook) {
@@ -417,7 +417,31 @@ methods:
417417
content: 'getTopBottom(): TopBottomConditionalFormat | undefined;'
418418
return:
419419
type: '<xref uid="ExcelScript!ExcelScript.TopBottomConditionalFormat:interface" /> | undefined'
420-
description: ''
420+
description: |-
421+
422+
423+
#### Examples
424+
425+
```TypeScript
426+
/**
427+
* This script applies top/bottom conditional formatting to a range.
428+
* The top 2 values in the range will have the cell fill color changed to green.
429+
*/
430+
function main(workbook: ExcelScript.Workbook) {
431+
// Get the range to format.
432+
const sheet = workbook.getWorksheet("TopBottom");
433+
const dataRange = sheet.getRange("B2:D5");
434+
435+
// Set the fill color to green for the top 2 values in the range.
436+
const topBottomFormat = dataRange.addConditionalFormat(
437+
ExcelScript.ConditionalFormatType.topBottom).getTopBottom();
438+
topBottomFormat.getFormat().getFill().setColor("green");
439+
topBottomFormat.setRule({
440+
rank: 2, /* The numeric threshold. */
441+
type: ExcelScript.ConditionalTopBottomCriterionType.topItems /* The type of the top/bottom condition. */
442+
});
443+
}
444+
```
421445
- name: getType()
422446
uid: 'ExcelScript!ExcelScript.ConditionalFormat#getType:member(1)'
423447
package: ExcelScript!

docs/docs-ref-autogen/excel/excelscript/excelscript.conditionalformatruletype.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ remarks: |-
1111
1212
```TypeScript
1313
/**
14-
* This script creates data bar conditional formatting on the select ranged.
14+
* This script creates data bar conditional formatting on the selected range.
1515
* The scale of the data bar goes from 0 to 1000.
1616
*/
1717
function main(workbook: ExcelScript.Workbook) {

docs/docs-ref-autogen/excel/excelscript/excelscript.databarconditionalformat.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ remarks: |-
1111
1212
```TypeScript
1313
/**
14-
* This script creates data bar conditional formatting on the select ranged.
14+
* This script creates data bar conditional formatting on the selected range.
1515
* The scale of the data bar goes from 0 to 1000.
1616
*/
1717
function main(workbook: ExcelScript.Workbook) {

docs/sample-scripts/excel-scripts.yaml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@
915915
'ExcelScript.ConditionalDataBarRule:interface':
916916
- |-
917917
/**
918-
* This script creates data bar conditional formatting on the select ranged.
918+
* This script creates data bar conditional formatting on the selected range.
919919
* The scale of the data bar goes from 0 to 1000.
920920
*/
921921
function main(workbook: ExcelScript.Workbook) {
@@ -1016,7 +1016,7 @@
10161016
'ExcelScript.ConditionalFormat#getDataBar:member(1)':
10171017
- |-
10181018
/**
1019-
* This script creates data bar conditional formatting on the select ranged.
1019+
* This script creates data bar conditional formatting on the selected range.
10201020
* The scale of the data bar goes from 0 to 1000.
10211021
*/
10221022
function main(workbook: ExcelScript.Workbook) {
@@ -1122,6 +1122,26 @@
11221122
};
11231123
textConditionFormat.setRule(textRule);
11241124
}
1125+
'ExcelScript.ConditionalFormat#getTopBottom:member(1)':
1126+
- |-
1127+
/**
1128+
* This script applies top/bottom conditional formatting to a range.
1129+
* The top 2 values in the range will have the cell fill color changed to green.
1130+
*/
1131+
function main(workbook: ExcelScript.Workbook) {
1132+
// Get the range to format.
1133+
const sheet = workbook.getWorksheet("TopBottom");
1134+
const dataRange = sheet.getRange("B2:D5");
1135+
1136+
// Set the fill color to green for the top 2 values in the range.
1137+
const topBottomFormat = dataRange.addConditionalFormat(
1138+
ExcelScript.ConditionalFormatType.topBottom).getTopBottom();
1139+
topBottomFormat.getFormat().getFill().setColor("green");
1140+
topBottomFormat.setRule({
1141+
rank: 2, /* The numeric threshold. */
1142+
type: ExcelScript.ConditionalTopBottomCriterionType.topItems /* The type of the top/bottom condition. */
1143+
});
1144+
}
11251145
'ExcelScript.ConditionalFormatColorCriterionType:enum':
11261146
- |-
11271147
/**
@@ -1211,7 +1231,7 @@
12111231
'ExcelScript.ConditionalFormatRuleType:enum':
12121232
- |-
12131233
/**
1214-
* This script creates data bar conditional formatting on the select ranged.
1234+
* This script creates data bar conditional formatting on the selected range.
12151235
* The scale of the data bar goes from 0 to 1000.
12161236
*/
12171237
function main(workbook: ExcelScript.Workbook) {
@@ -1533,7 +1553,7 @@
15331553
'ExcelScript.DataBarConditionalFormat:interface':
15341554
- |-
15351555
/**
1536-
* This script creates data bar conditional formatting on the select ranged.
1556+
* This script creates data bar conditional formatting on the selected range.
15371557
* The scale of the data bar goes from 0 to 1000.
15381558
*/
15391559
function main(workbook: ExcelScript.Workbook) {

generate-docs/API Coverage Report.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ ExcelScript.ConditionalFormat,"getRange()",Method,Poor,false
11641164
ExcelScript.ConditionalFormat,"getRanges()",Method,Poor,false
11651165
ExcelScript.ConditionalFormat,"getStopIfTrue()",Method,Poor,false
11661166
ExcelScript.ConditionalFormat,"getTextComparison()",Method,Fine,true
1167-
ExcelScript.ConditionalFormat,"getTopBottom()",Method,Poor,false
1167+
ExcelScript.ConditionalFormat,"getTopBottom()",Method,Good,true
11681168
ExcelScript.ConditionalFormat,"getType()",Method,Poor,false
11691169
ExcelScript.ConditionalFormat,"setPriority(priority)",Method,Poor,false
11701170
ExcelScript.ConditionalFormat,"setStopIfTrue(stopIfTrue)",Method,Poor,false

0 commit comments

Comments
 (0)