apps-script-utils 2.1.1 Help

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

spreadsheet

GoogleAppsScript.Spreadsheet.Spreadsheet

The spreadsheet whose tabs are reordered.

callback (optional)

(a: string, b: string) => number

Compares two sheet names, as Array#sort expects.

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

src/appsscript/sheet/sortSheets.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.