Skip to content

Commit e424b0c

Browse files
authored
[excel] (Range, Table) Various small samples for Office Scripts (#344)
* Various small samples for Office Scripts * Add missing comment
1 parent 714b0b3 commit e424b0c

File tree

7 files changed

+174
-10
lines changed

7 files changed

+174
-10
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,26 @@ methods:
23042304
type: boolean
23052305
return:
23062306
type: '<xref uid="ExcelScript!ExcelScript.RemoveDuplicatesResult:interface" />'
2307-
description: ''
2307+
description: |-
2308+
2309+
2310+
#### Examples
2311+
2312+
```TypeScript
2313+
/**
2314+
* This script removes duplicate rows from a range.
2315+
*/
2316+
function main(workbook: ExcelScript.Workbook) {
2317+
// Get the used range of the active worksheet.
2318+
const usedRange = workbook.getActiveWorksheet().getUsedRange();
2319+
2320+
// Remove any row that has a same value in the 0-indexed column as a previous row.
2321+
const removedResults = usedRange.removeDuplicates([0], true);
2322+
2323+
// Log the count of removed rows.
2324+
console.log(`Rows removed: ${removedResults.getRemoved()}.`);
2325+
}
2326+
```
23082327
- name: 'replaceAll(text, replacement, criteria)'
23092328
uid: 'ExcelScript!ExcelScript.Range#replaceAll:member(1)'
23102329
package: ExcelScript!

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,26 @@ uid: 'ExcelScript!ExcelScript.RemoveDuplicatesResult:interface'
44
package: ExcelScript!
55
fullName: ExcelScript.RemoveDuplicatesResult
66
summary: Represents the results from `Range.removeDuplicates`<!-- -->.
7-
remarks: ''
7+
remarks: |-
8+
9+
10+
#### Examples
11+
12+
```TypeScript
13+
/**
14+
* This script removes duplicate rows from a range.
15+
*/
16+
function main(workbook: ExcelScript.Workbook) {
17+
// Get the used range of the active worksheet.
18+
const usedRange = workbook.getActiveWorksheet().getUsedRange();
19+
20+
// Remove any row that has a same value in the 0-indexed column as a previous row.
21+
const removedResults: ExcelScript.RemoveDuplicatesResult = usedRange.removeDuplicates([0], true);
22+
23+
// Log the count of removed rows.
24+
console.log(`Rows removed: ${removedResults.getRemoved()}.`);
25+
}
26+
```
827
isPreview: false
928
isDeprecated: false
1029
type: interface

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,25 @@ methods:
856856
type: boolean
857857
return:
858858
type: void
859-
description: ''
859+
description: |-
860+
861+
862+
#### Examples
863+
864+
```TypeScript
865+
/**
866+
* This script sets all the tables in the workbook to have banded rows.
867+
*/
868+
function main(workbook: ExcelScript.Workbook) {
869+
// Get all the tables.
870+
const tables = workbook.getTables();
871+
872+
// For each table, set the banded row formatting to true.
873+
tables.forEach((table) => {
874+
table.setShowBandedRows(true);
875+
});
876+
}
877+
```
860878
- name: setShowFilterButton(showFilterButton)
861879
uid: 'ExcelScript!ExcelScript.Table#setShowFilterButton:member(1)'
862880
package: ExcelScript!

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,21 @@ methods:
227227
type: string
228228
return:
229229
type: void
230-
description: ''
230+
description: |-
231+
232+
233+
#### Examples
234+
235+
```TypeScript
236+
/**
237+
* This script renames a column in an existing table.
238+
*/
239+
function main(workbook: ExcelScript.Workbook) {
240+
// Get the "Employee" table.
241+
const employeeTable = workbook.getTable("Employee");
242+
243+
// Rename a column from "EmplID" to "Employee ID".
244+
const idColumn = employeeTable.getColumnByName("EmplID");
245+
idColumn.setName("Employee ID");
246+
}
247+
```

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,23 @@ methods:
123123
content: 'reapply(): void;'
124124
return:
125125
type: void
126-
description: ''
126+
description: |-
127+
128+
129+
#### Examples
130+
131+
```TypeScript
132+
/**
133+
* This script reapplies all the current sorting criteria to existing tables.
134+
*/
135+
function main(workbook: ExcelScript.Workbook) {
136+
// Get all the tables.
137+
const tables = workbook.getTables();
138+
139+
// For each table, reapply that table's current sorting parameters.
140+
tables.forEach((table) => {
141+
const sort: ExcelScript.TableSort = table.getSort();
142+
sort.reapply();
143+
});
144+
}
145+
```

docs/sample-scripts/excel-scripts.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,6 +4283,21 @@
42834283
const range = selectedSheet.getRange("A1:A4");
42844284
range.merge();
42854285
}
4286+
'ExcelScript.Range#removeDuplicates:member(1)':
4287+
- |-
4288+
/**
4289+
* This script removes duplicate rows from a range.
4290+
*/
4291+
function main(workbook: ExcelScript.Workbook) {
4292+
// Get the used range of the active worksheet.
4293+
const usedRange = workbook.getActiveWorksheet().getUsedRange();
4294+
4295+
// Remove any row that has a same value in the 0-indexed column as a previous row.
4296+
const removedResults = usedRange.removeDuplicates([0], true);
4297+
4298+
// Log the count of removed rows.
4299+
console.log(`Rows removed: ${removedResults.getRemoved()}.`);
4300+
}
42864301
'ExcelScript.Range#replaceAll:member(1)':
42874302
- |-
42884303
/**
@@ -5048,6 +5063,21 @@
50485063
const otherRangeCorner = otherSheet.getRange("A1");
50495064
otherRangeCorner.copyFrom(source, ExcelScript.RangeCopyType.all);
50505065
}
5066+
'ExcelScript.RemoveDuplicatesResult:interface':
5067+
- |-
5068+
/**
5069+
* This script removes duplicate rows from a range.
5070+
*/
5071+
function main(workbook: ExcelScript.Workbook) {
5072+
// Get the used range of the active worksheet.
5073+
const usedRange = workbook.getActiveWorksheet().getUsedRange();
5074+
5075+
// Remove any row that has a same value in the 0-indexed column as a previous row.
5076+
const removedResults: ExcelScript.RemoveDuplicatesResult = usedRange.removeDuplicates([0], true);
5077+
5078+
// Log the count of removed rows.
5079+
console.log(`Rows removed: ${removedResults.getRemoved()}.`);
5080+
}
50515081
'ExcelScript.ReplaceCriteria#completeMatch:member':
50525082
- |-
50535083
/**
@@ -5814,6 +5844,20 @@
58145844
table.reapplyFilters();
58155845
});
58165846
}
5847+
'ExcelScript.Table#setShowBandedRows:member(1)':
5848+
- |-
5849+
/**
5850+
* This script sets all the tables in the workbook to have banded rows.
5851+
*/
5852+
function main(workbook: ExcelScript.Workbook) {
5853+
// Get all the tables.
5854+
const tables = workbook.getTables();
5855+
5856+
// For each table, set the banded row formatting to true.
5857+
tables.forEach((table) => {
5858+
table.setShowBandedRows(true);
5859+
});
5860+
}
58175861
'ExcelScript.Table#setShowHeaders:member(1)':
58185862
- |-
58195863
/**
@@ -5908,6 +5952,19 @@
59085952
`=[@[${productColumnName1}]]*[@[${productColumnName2}]]`
59095953
);
59105954
}
5955+
'ExcelScript.TableColumn#setName:member(1)':
5956+
- |-
5957+
/**
5958+
* This script renames a column in an existing table.
5959+
*/
5960+
function main(workbook: ExcelScript.Workbook) {
5961+
// Get the "Employee" table.
5962+
const employeeTable = workbook.getTable("Employee");
5963+
5964+
// Rename a column from "EmplID" to "Employee ID".
5965+
const idColumn = employeeTable.getColumnByName("EmplID");
5966+
idColumn.setName("Employee ID");
5967+
}
59115968
'ExcelScript.TableSort#apply:member(1)':
59125969
- |-
59135970
/**
@@ -5924,6 +5981,21 @@
59245981
// Sort the table using the first column.
59255982
newTable.getSort().apply([{ key: 0, ascending: true }]);
59265983
}
5984+
'ExcelScript.TableSort#reapply:member(1)':
5985+
- |-
5986+
/**
5987+
* This script reapplies all the current sorting criteria to existing tables.
5988+
*/
5989+
function main(workbook: ExcelScript.Workbook) {
5990+
// Get all the tables.
5991+
const tables = workbook.getTables();
5992+
5993+
// For each table, reapply that table's current sorting parameters.
5994+
tables.forEach((table) => {
5995+
const sort: ExcelScript.TableSort = table.getSort();
5996+
sort.reapply();
5997+
});
5998+
}
59275999
'ExcelScript.TextConditionalFormat:interface':
59286000
- |-
59296001
/**

generate-docs/API Coverage Report.csv

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,7 +2453,7 @@ ExcelScript.Range,"hideGroupDetails(groupOption)",Method,Poor,false
24532453
ExcelScript.Range,"insert(shift)",Method,Fine,true
24542454
ExcelScript.Range,"merge(across)",Method,Fine,true
24552455
ExcelScript.Range,"moveTo(destinationRange)",Method,Poor,false
2456-
ExcelScript.Range,"removeDuplicates(columns, includesHeader)",Method,Poor,false
2456+
ExcelScript.Range,"removeDuplicates(columns, includesHeader)",Method,Fine,true
24572457
ExcelScript.Range,"replaceAll(text, replacement, criteria)",Method,Poor,true
24582458
ExcelScript.Range,"select()",Method,Poor,true
24592459
ExcelScript.Range,"setColumnHidden(columnHidden)",Method,Poor,false
@@ -2635,7 +2635,7 @@ ExcelScript.ReadingOrder,N/A,Enum,Missing,false
26352635
ExcelScript.ReadingOrder,"context",EnumField,Good,false
26362636
ExcelScript.ReadingOrder,"leftToRight",EnumField,Poor,false
26372637
ExcelScript.ReadingOrder,"rightToLeft",EnumField,Poor,false
2638-
ExcelScript.RemoveDuplicatesResult,N/A,Class,Fine,false
2638+
ExcelScript.RemoveDuplicatesResult,N/A,Class,Fine,true
26392639
ExcelScript.RemoveDuplicatesResult,"getRemoved()",Method,Poor,false
26402640
ExcelScript.RemoveDuplicatesResult,"getUniqueRemaining()",Method,Poor,false
26412641
ExcelScript.ReplaceCriteria,N/A,Class,Fine,false
@@ -3016,7 +3016,7 @@ ExcelScript.Table,"setHighlightLastColumn(highlightLastColumn)",Method,Poor,fals
30163016
ExcelScript.Table,"setName(name)",Method,Poor,false
30173017
ExcelScript.Table,"setPredefinedTableStyle(predefinedTableStyle)",Method,Poor,false
30183018
ExcelScript.Table,"setShowBandedColumns(showBandedColumns)",Method,Poor,false
3019-
ExcelScript.Table,"setShowBandedRows(showBandedRows)",Method,Poor,false
3019+
ExcelScript.Table,"setShowBandedRows(showBandedRows)",Method,Poor,true
30203020
ExcelScript.Table,"setShowFilterButton(showFilterButton)",Method,Poor,false
30213021
ExcelScript.Table,"setShowHeaders(showHeaders)",Method,Poor,true
30223022
ExcelScript.Table,"setShowTotals(showTotals)",Method,Poor,true
@@ -3030,14 +3030,14 @@ ExcelScript.TableColumn,"getName()",Method,Poor,false
30303030
ExcelScript.TableColumn,"getRange()",Method,Poor,false
30313031
ExcelScript.TableColumn,"getRangeBetweenHeaderAndTotal()",Method,Fine,true
30323032
ExcelScript.TableColumn,"getTotalRowRange()",Method,Poor,false
3033-
ExcelScript.TableColumn,"setName(name)",Method,Poor,false
3033+
ExcelScript.TableColumn,"setName(name)",Method,Poor,true
30343034
ExcelScript.TableSort,N/A,Class,Fine,false
30353035
ExcelScript.TableSort,"apply(fields, matchCase, method)",Method,Fine,true
30363036
ExcelScript.TableSort,"clear()",Method,Poor,false
30373037
ExcelScript.TableSort,"getFields()",Method,Poor,false
30383038
ExcelScript.TableSort,"getMatchCase()",Method,Poor,false
30393039
ExcelScript.TableSort,"getMethod()",Method,Poor,false
3040-
ExcelScript.TableSort,"reapply()",Method,Poor,false
3040+
ExcelScript.TableSort,"reapply()",Method,Poor,true
30413041
ExcelScript.TableStyle,N/A,Class,Fine,false
30423042
ExcelScript.TableStyle,"delete()",Method,Poor,false
30433043
ExcelScript.TableStyle,"duplicate()",Method,Poor,false

0 commit comments

Comments
 (0)