getSheetById
function getSheetById(
sheetId: number,
ss?: GoogleAppsScript.Spreadsheet.Spreadsheet | undefined | null
): GoogleAppsScript.Spreadsheet.Sheet | null;
An id survives a rename and a reorder, which is what makes it the right handle to store in a property or a config. Apps Script offers no lookup by id, so the sheets are walked and compared.
The spreadsheet defaults to the active one. A sheet that is not there gives null rather than an exception, so a stored id that no longer resolves is a case to handle, not a crash.
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The sheet id to look for. |
|
| The spreadsheet to look in. The active one by default. |
Returns
GoogleAppsScript.Spreadsheet.Sheet | null — the sheet, or null when no sheet carries that id.
Examples
Looking up
const sheet = getSheetById(0);
if (sheet === null) {
throw new Error("That sheet is gone.");
}
See also
Source
23 September 2026
This documentation was generated with AI (Claude) from the library's source code.