sortSheets
function sortSheets(
spreadsheet: GoogleAppsScript.Spreadsheet.Spreadsheet,
callback?: (a: string, b: string) => number
): void;
By name, ascending, unless a comparison function is given — it receives two sheet names and works like the one Array#sort takes.
The tabs are moved one at a time, and each move is a call to the service, so a spreadsheet with many sheets takes a moment.
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The spreadsheet whose tabs are reordered. |
|
| Compares two sheet names, as |
Returns
void — nothing; the spreadsheet is changed in place.
Examples
Sorting the tabs
const spreadsheet = SpreadsheetApp.getActive();
sortSheets(spreadsheet); // alphabetically by name
sortSheets(spreadsheet, (a, b) => b.localeCompare(a)); // reversed
See also
Source
23 September 2026
This documentation was generated with AI (Claude) from the library's source code.