Home

getActiveSheet

getActiveSheet is a method of the Spreadsheet class in Google Apps Script. It returns the currently active sheet (the sheet that is currently selected) within the active spreadsheet. The method is commonly used in bound scripts to access or manipulate the sheet that the user has open at runtime.

Return value and behavior: getActiveSheet returns a Sheet object representing the active sheet. In most cases

Usage pattern: A typical usage pattern is to obtain the active spreadsheet and then its active sheet,

Considerations: getActiveSheet is most reliable in scripts bound to a specific spreadsheet and when the user

it
will
reflect
the
sheet
the
user
is
viewing,
but
in
some
contexts
it
may
return
null
if
there
is
no
active
sheet
available.
The
result
is
used
as
the
starting
point
for
further
operations
on
that
sheet,
such
as
reading
or
writing
data,
formatting,
or
navigation.
for
example:
var
sheet
=
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
This
sheet
object
can
then
be
used
to
access
ranges,
values,
and
properties,
such
as
var
values
=
sheet.getDataRange().getValues();
or
var
name
=
sheet.getName();
has
an
active
sheet
at
the
time
the
script
runs.
In
web
apps,
add-ons,
or
triggers
where
there
is
no
user
interface,
the
concept
of
an
active
sheet
may
not
apply,
and
alternative
methods
to
reference
a
specific
sheet
or
spreadsheet
may
be
appropriate.
Related
methods
include
getSheetByName
for
selecting
a
particular
sheet
and
getActiveSpreadsheet
for
references
to
the
containing
spreadsheet.