Home

getSheets

getSheets is a method of the Spreadsheet class in Google Apps Script. It returns an array containing every sheet in the spreadsheet as Sheet objects.

The array preserves the tab order of the sheets. Each element represents one worksheet and exposes methods

Usage commonly involves obtaining the active spreadsheet and calling getSheets to retrieve the list, then iterating

Notes: The method requires authorization to access Google Sheets data. The returned array reflects the current

See also: getSheetByName, getActiveSpreadsheet, and the Sheet class.

to
read
and
modify
its
content
and
properties,
such
as
getName
and
getDataRange.
or
accessing
by
index.
Example:
var
ss
=
SpreadsheetApp.getActiveSpreadsheet();
var
sheets
=
ss.getSheets();
for
(var
i
=
0;
i
<
sheets.length;
i++)
{
Logger.log(sheets[i].getName());
}
You
can
also
access
a
specific
sheet
by
index
or
by
name
after
obtaining
the
array,
e.g.,
var
first
=
sheets[0];
or
var
dataSheet
=
ss.getSheetByName('Data');
state
of
the
spreadsheet,
including
any
sheets
that
have
been
added
or
removed.