Skip to content

Commit 321ea3d

Browse files
authored
Add Table and LinekdWorkbook samples (#346)
1 parent e424b0c commit 321ea3d

File tree

7 files changed

+154
-16
lines changed

7 files changed

+154
-16
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,27 @@ methods:
2626
content: 'breakLinks(): void;'
2727
return:
2828
type: void
29-
description: ''
29+
description: |-
30+
31+
32+
#### Examples
33+
34+
```TypeScript
35+
/**
36+
* This script removes all links to other workbooks.
37+
*/
38+
function main(workbook: ExcelScript.Workbook) {
39+
// Get all the linked workbook references.
40+
const externalWorkbooks: ExcelScript.LinkedWorkbook[] = workbook.getLinkedWorkbooks();
41+
console.log(`There are ${externalWorkbooks.length} other workbooks linked to from this workbook.`);
42+
43+
// Remove all the links to those workbooks.
44+
// This changes the value of cells with workbook links to "#CONNECT!".
45+
externalWorkbooks.forEach((workbookLink) => {
46+
workbookLink.breakLinks();
47+
});
48+
}
49+
```
3050
- name: refreshLinks()
3151
uid: 'ExcelScript!ExcelScript.LinkedWorkbook#refreshLinks:member(1)'
3252
package: ExcelScript!

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,25 @@ methods:
178178
content: 'clearFilters(): void;'
179179
return:
180180
type: void
181-
description: ''
181+
description: |-
182+
183+
184+
#### Examples
185+
186+
```TypeScript
187+
/**
188+
* This script clears the filters from all tables in the workbook.
189+
*/
190+
function main(workbook: ExcelScript.Workbook) {
191+
// Get all the tables in the workbook.
192+
const tables = workbook.getTables();
193+
194+
// Remove any active filters from each table.
195+
tables.forEach((table) => {
196+
table.clearFilters();
197+
});
198+
}
199+
```
182200
- name: convertToRange()
183201
uid: 'ExcelScript!ExcelScript.Table#convertToRange:member(1)'
184202
package: ExcelScript!

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,27 @@ methods:
210210
content: 'getTotalRowRange(): Range;'
211211
return:
212212
type: '<xref uid="ExcelScript!ExcelScript.Range:interface" />'
213-
description: ''
213+
description: |-
214+
215+
216+
#### Examples
217+
218+
```TypeScript
219+
/**
220+
* This script logs the value in the total row of a table column.
221+
*/
222+
function main(workbook: ExcelScript.Workbook) {
223+
// Get the table named "Cities".
224+
const table = workbook.getTable("Cities");
225+
226+
// Get the total row from the "Population" column.
227+
const column = table.getColumn("Population");
228+
const totalRange = column.getTotalRowRange();
229+
230+
// Log the total value.
231+
console.log(totalRange.getValue());
232+
}
233+
```
214234
- name: setName(name)
215235
uid: 'ExcelScript!ExcelScript.TableColumn#setName:member(1)'
216236
package: ExcelScript!

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,6 @@ methods:
10241024
// Trigger a refresh of linked workbook content.
10251025
workbook.refreshAllLinksToLinkedWorkbooks();
10261026
}
1027-
}
10281027
```
10291028
- name: getLinkedWorkbooks()
10301029
uid: 'ExcelScript!ExcelScript.Workbook#getLinkedWorkbooks:member(1)'
@@ -1040,7 +1039,27 @@ methods:
10401039
content: 'getLinkedWorkbooks(): LinkedWorkbook[];'
10411040
return:
10421041
type: '<xref uid="ExcelScript!ExcelScript.LinkedWorkbook:interface" />[]'
1043-
description: ''
1042+
description: |-
1043+
1044+
1045+
#### Examples
1046+
1047+
```TypeScript
1048+
/**
1049+
* This script removes all links to other workbooks.
1050+
*/
1051+
function main(workbook: ExcelScript.Workbook) {
1052+
// Get all the linked workbook references.
1053+
const externalWorkbooks: ExcelScript.LinkedWorkbook[] = workbook.getLinkedWorkbooks();
1054+
console.log(`There are ${externalWorkbooks.length} other workbooks linked to from this workbook.`);
1055+
1056+
// Remove all the links to those workbooks.
1057+
// This changes the value of cells with workbook links to "#CONNECT!".
1058+
externalWorkbooks.forEach((workbookLink) => {
1059+
workbookLink.breakLinks();
1060+
});
1061+
}
1062+
```
10441063
- name: getName()
10451064
uid: 'ExcelScript!ExcelScript.Workbook#getName:member(1)'
10461065
package: ExcelScript!

docs/sample-scripts/excel-scripts.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,6 +2740,22 @@
27402740
// Apply the label filter to the field.
27412741
field.applyFilter({ labelFilter: filter });
27422742
}
2743+
'ExcelScript.LinkedWorkbook#breakLinks:member(1)':
2744+
- |-
2745+
/**
2746+
* This script removes all links to other workbooks.
2747+
*/
2748+
function main(workbook: ExcelScript.Workbook) {
2749+
// Get all the linked workbook references.
2750+
const externalWorkbooks: ExcelScript.LinkedWorkbook[] = workbook.getLinkedWorkbooks();
2751+
console.log(`There are ${externalWorkbooks.length} other workbooks linked to from this workbook.`);
2752+
2753+
// Remove all the links to those workbooks.
2754+
// This changes the value of cells with workbook links to "#CONNECT!".
2755+
externalWorkbooks.forEach((workbookLink) => {
2756+
workbookLink.breakLinks();
2757+
});
2758+
}
27432759
'ExcelScript.ListDataValidation:interface':
27442760
- |-
27452761
/**
@@ -5711,6 +5727,20 @@
57115727
// Add the rows to the end of the table.
57125728
table.addRows(-1, rowData);
57135729
}
5730+
'ExcelScript.Table#clearFilters:member(1)':
5731+
- |-
5732+
/**
5733+
* This script clears the filters from all tables in the workbook.
5734+
*/
5735+
function main(workbook: ExcelScript.Workbook) {
5736+
// Get all the tables in the workbook.
5737+
const tables = workbook.getTables();
5738+
5739+
// Remove any active filters from each table.
5740+
tables.forEach((table) => {
5741+
table.clearFilters();
5742+
});
5743+
}
57145744
'ExcelScript.Table#convertToRange:member(1)':
57155745
- |-
57165746
/**
@@ -5952,6 +5982,22 @@
59525982
`=[@[${productColumnName1}]]*[@[${productColumnName2}]]`
59535983
);
59545984
}
5985+
'ExcelScript.TableColumn#getTotalRowRange:member(1)':
5986+
- |-
5987+
/**
5988+
* This script logs the value in the total row of a table column.
5989+
*/
5990+
function main(workbook: ExcelScript.Workbook) {
5991+
// Get the table named "Cities".
5992+
const table = workbook.getTable("Cities");
5993+
5994+
// Get the total row from the "Population" column.
5995+
const column = table.getColumn("Population");
5996+
const totalRange = column.getTotalRowRange();
5997+
5998+
// Log the total value.
5999+
console.log(totalRange.getValue());
6000+
}
59556001
'ExcelScript.TableColumn#setName:member(1)':
59566002
- |-
59576003
/**
@@ -6288,6 +6334,21 @@
62886334
// Trigger a refresh of linked workbook content.
62896335
workbook.refreshAllLinksToLinkedWorkbooks();
62906336
}
6337+
'ExcelScript.Workbook#getLinkedWorkbooks:member(1)':
6338+
- |-
6339+
/**
6340+
* This script removes all links to other workbooks.
6341+
*/
6342+
function main(workbook: ExcelScript.Workbook) {
6343+
// Get all the linked workbook references.
6344+
const externalWorkbooks: ExcelScript.LinkedWorkbook[] = workbook.getLinkedWorkbooks();
6345+
console.log(`There are ${externalWorkbooks.length} other workbooks linked to from this workbook.`);
6346+
6347+
// Remove all the links to those workbooks.
6348+
// This changes the value of cells with workbook links to "#CONNECT!".
6349+
externalWorkbooks.forEach((workbookLink) => {
6350+
workbookLink.breakLinks();
6351+
});
62916352
}
62926353
'ExcelScript.Workbook#getName:member(1)':
62936354
- |-

generate-docs/API Coverage Report.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,7 @@ ExcelScript.LinkedDataTypeState,"fetchingData",EnumField,Missing,false
19541954
ExcelScript.LinkedDataTypeState,"none",EnumField,Missing,false
19551955
ExcelScript.LinkedDataTypeState,"validLinkedData",EnumField,Missing,false
19561956
ExcelScript.LinkedWorkbook,N/A,Class,Good,false
1957-
ExcelScript.LinkedWorkbook,"breakLinks()",Method,Poor,false
1957+
ExcelScript.LinkedWorkbook,"breakLinks()",Method,Fine,true
19581958
ExcelScript.LinkedWorkbook,"refreshLinks()",Method,Poor,false
19591959
ExcelScript.ListDataValidation,N/A,Class,Fine,true
19601960
ExcelScript.ListDataValidation,"inCellDropDown",Property,Good,false
@@ -2982,7 +2982,7 @@ ExcelScript.Table,N/A,Class,Poor,true
29822982
ExcelScript.Table,"addColumn(index, values, name)",Method,Fine,true
29832983
ExcelScript.Table,"addRow(index, values)",Method,Fine,true
29842984
ExcelScript.Table,"addRows(index, values)",Method,Fine,true
2985-
ExcelScript.Table,"clearFilters()",Method,Poor,false
2985+
ExcelScript.Table,"clearFilters()",Method,Poor,true
29862986
ExcelScript.Table,"convertToRange()",Method,Fine,true
29872987
ExcelScript.Table,"delete()",Method,Poor,true
29882988
ExcelScript.Table,"deleteRowsAt(index, count)",Method,Poor,false
@@ -3029,7 +3029,7 @@ ExcelScript.TableColumn,"getIndex()",Method,Poor,false
30293029
ExcelScript.TableColumn,"getName()",Method,Poor,false
30303030
ExcelScript.TableColumn,"getRange()",Method,Poor,false
30313031
ExcelScript.TableColumn,"getRangeBetweenHeaderAndTotal()",Method,Fine,true
3032-
ExcelScript.TableColumn,"getTotalRowRange()",Method,Poor,false
3032+
ExcelScript.TableColumn,"getTotalRowRange()",Method,Poor,true
30333033
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
@@ -3154,7 +3154,7 @@ ExcelScript.Workbook,"getIsDirty()",Method,Poor,false
31543154
ExcelScript.Workbook,"getLastWorksheet(visibleOnly)",Method,Poor,false
31553155
ExcelScript.Workbook,"getLinkedWorkbookByUrl(key)",Method,Poor,false
31563156
ExcelScript.Workbook,"getLinkedWorkbookRefreshMode()",Method,Fine,true
3157-
ExcelScript.Workbook,"getLinkedWorkbooks()",Method,Poor,false
3157+
ExcelScript.Workbook,"getLinkedWorkbooks()",Method,Fine,true
31583158
ExcelScript.Workbook,"getName()",Method,Poor,true
31593159
ExcelScript.Workbook,"getNamedItem(name)",Method,Poor,false
31603160
ExcelScript.Workbook,"getNames()",Method,Poor,true

generate-docs/scripts/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)