Skip to content

Commit ff25493

Browse files
authored
Add SortBy sample for autosort in PivotTable (#429)
1 parent cf2eeaa commit ff25493

4 files changed

Lines changed: 93 additions & 3 deletions

File tree

docs/docs-ref-autogen/excelscript/excelscript.pivotlayout.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,29 @@ methods:
484484
type: <xref uid="ExcelScript!ExcelScript.SortBy:enum" />
485485
return:
486486
type: void
487-
description: ''
487+
description: |-
488+
489+
490+
#### Examples
491+
492+
```TypeScript
493+
/**
494+
* This script shows how to use setAutoSortOnCell to automatically sort
495+
* a PivotTable's row labels based on values in a specific data column.
496+
*/
497+
function main(workbook: ExcelScript.Workbook) {
498+
// Get the "Farm Pivot" PivotTable.
499+
const pivotTable = workbook.getPivotTable("Farm Pivot");
500+
const sheet = pivotTable.getWorksheet();
501+
502+
// Get the PivotTable's layout object.
503+
const layout = pivotTable.getLayout();
504+
505+
// Pick a cell in the PivotTable's data area to sort by.
506+
const sortCell1 = sheet.getRange("N6");
507+
layout.setAutoSortOnCell(sortCell1, ExcelScript.SortBy.descending);
508+
}
509+
```
488510
- name: setEmptyCellText(emptyCellText)
489511
uid: ExcelScript!ExcelScript.PivotLayout#setEmptyCellText:member(1)
490512
package: ExcelScript!

docs/docs-ref-autogen/excelscript/excelscript.sortby.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ package: ExcelScript!
55
fullName: ExcelScript.SortBy
66
summary: Represents the sort direction.
77
remarks: >-
8+
9+
10+
11+
812
#### Used by
913
1014
@@ -17,6 +21,34 @@ remarks: >-
1721
[ExcelScript.PivotLayout](/javascript/api/office-scripts/excelscript/excelscript.pivotlayout):
1822
[setAutoSortOnCell](/javascript/api/office-scripts/excelscript/excelscript.pivotlayout#excelscript-excelscript-pivotlayout-setautosortoncell-member(1))
1923
24+
#### Examples
25+
26+
27+
```TypeScript
28+
29+
/**
30+
31+
* This script shows how to use setAutoSortOnCell to automatically sort
32+
33+
* a PivotTable's row labels based on values in a specific data column.
34+
35+
*/
36+
37+
function main(workbook: ExcelScript.Workbook) {
38+
// Get the "Farm Pivot" PivotTable.
39+
const pivotTable = workbook.getPivotTable("Farm Pivot");
40+
const sheet = pivotTable.getWorksheet();
41+
42+
// Get the PivotTable's layout object.
43+
const layout = pivotTable.getLayout();
44+
45+
// Pick a cell in the PivotTable's data area to sort by.
46+
const sortCell1 = sheet.getRange("N6");
47+
layout.setAutoSortOnCell(sortCell1, ExcelScript.SortBy.descending);
48+
}
49+
50+
```
51+
2052
isPreview: false
2153
isDeprecated: false
2254
fields:

docs/sample-scripts/samples.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4043,6 +4043,24 @@
40434043
// Example log: "Grand total of Sum of Crates Sold Wholesale: 11000"
40444044
});
40454045
}
4046+
'ExcelScript.PivotLayout#setAutoSortOnCell:member(1)':
4047+
- |-
4048+
/**
4049+
* This script shows how to use setAutoSortOnCell to automatically sort
4050+
* a PivotTable's row labels based on values in a specific data column.
4051+
*/
4052+
function main(workbook: ExcelScript.Workbook) {
4053+
// Get the "Farm Pivot" PivotTable.
4054+
const pivotTable = workbook.getPivotTable("Farm Pivot");
4055+
const sheet = pivotTable.getWorksheet();
4056+
4057+
// Get the PivotTable's layout object.
4058+
const layout = pivotTable.getLayout();
4059+
4060+
// Pick a cell in the PivotTable's data area to sort by.
4061+
const sortCell1 = sheet.getRange("N6");
4062+
layout.setAutoSortOnCell(sortCell1, ExcelScript.SortBy.descending);
4063+
}
40464064
'ExcelScript.PivotLayout#setLayoutType:member(1)':
40474065
- |-
40484066
/**
@@ -6199,6 +6217,24 @@
61996217
// Set the left margin of the slicer.
62006218
fruitSlicer.setLeft(400);
62016219
}
6220+
'ExcelScript.SortBy:enum':
6221+
- |-
6222+
/**
6223+
* This script shows how to use setAutoSortOnCell to automatically sort
6224+
* a PivotTable's row labels based on values in a specific data column.
6225+
*/
6226+
function main(workbook: ExcelScript.Workbook) {
6227+
// Get the "Farm Pivot" PivotTable.
6228+
const pivotTable = workbook.getPivotTable("Farm Pivot");
6229+
const sheet = pivotTable.getWorksheet();
6230+
6231+
// Get the PivotTable's layout object.
6232+
const layout = pivotTable.getLayout();
6233+
6234+
// Pick a cell in the PivotTable's data area to sort by.
6235+
const sortCell1 = sheet.getRange("N6");
6236+
layout.setAutoSortOnCell(sortCell1, ExcelScript.SortBy.descending);
6237+
}
62026238
'ExcelScript.SortDataOption:enum':
62036239
- |-
62046240
/**

generate-docs/API Coverage Report.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,7 +2275,7 @@ ExcelScript,ExcelScript.PivotLayout,"repeatAllItemLabels(repeatLabels)",Method,F
22752275
ExcelScript,ExcelScript.PivotLayout,"setAltTextDescription(altTextDescription)",Method,Great,false
22762276
ExcelScript,ExcelScript.PivotLayout,"setAltTextTitle(altTextTitle)",Method,Great,false
22772277
ExcelScript,ExcelScript.PivotLayout,"setAutoFormat(autoFormat)",Method,Great,false
2278-
ExcelScript,ExcelScript.PivotLayout,"setAutoSortOnCell(cell, sortBy)",Method,Good,false
2278+
ExcelScript,ExcelScript.PivotLayout,"setAutoSortOnCell(cell, sortBy)",Method,Good,true
22792279
ExcelScript,ExcelScript.PivotLayout,"setEmptyCellText(emptyCellText)",Method,Excellent,false
22802280
ExcelScript,ExcelScript.PivotLayout,"setEnableFieldList(enableFieldList)",Method,Good,false
22812281
ExcelScript,ExcelScript.PivotLayout,"setFillEmptyCells(fillEmptyCells)",Method,Excellent,false
@@ -2986,7 +2986,7 @@ ExcelScript,ExcelScript.SlicerStyle,"duplicate()",Method,Fine,false
29862986
ExcelScript,ExcelScript.SlicerStyle,"getName()",Method,Fine,false
29872987
ExcelScript,ExcelScript.SlicerStyle,"getReadOnly()",Method,Good,false
29882988
ExcelScript,ExcelScript.SlicerStyle,"setName(name)",Method,Fine,false
2989-
ExcelScript,ExcelScript.SortBy,N/A,Enum,Good,false
2989+
ExcelScript,ExcelScript.SortBy,N/A,Enum,Good,true
29902990
ExcelScript,ExcelScript.SortBy,"ascending",EnumField,Great,false
29912991
ExcelScript,ExcelScript.SortBy,"descending",EnumField,Great,false
29922992
ExcelScript,ExcelScript.SortDataOption,N/A,Enum,Missing,true

0 commit comments

Comments
 (0)