Skip to main content

Acquisition of the number of seats

Explains the functions used when you want to get the number of sheets from a specific spreadsheet.

function to use

Spreadsheet.getNumSheets();

Use getNumSheets() provided in the Spreadsheet class.

You may need to authenticate at the first execution because you will access the spreadsheet when execution.

Sample code

/**
* Eligible spreadsheet ID
* https://docs.google.com/spreadsheets/d/〇〇〇/edit part of 〇〇〇
*/
const SPREAD_SHEET_ID = '_______________';

/**
* Returns the number of sheets on the spreadsheet
*/
const getNumSheets = () => {
/** Target spreadsheet */
const ss = SpreadsheetApp.openById(SPREAD_SHEET_ID);

/** Number of sheets on the spreadsheet */
const numSheets = ss.getNumSheets();

console.log(numSheets);
return numSheets;
};

When you execute, the log shows the number of seats on the target sheet.