Home

openById

openById is a method used in Google Apps Script to open a Google Drive file by its unique identifier. It is implemented in several Apps Script services, most commonly DocumentApp, SpreadsheetApp, and SlidesApp, and it returns a service-specific object that represents the opened file.

When you call openById with a file’s ID, Apps Script resolves the ID and returns an object

Typical usage includes opening documents, spreadsheets, or presentations by ID, then performing further operations. For example,

Alternatives to openById include openByUrl, which takes a full URL to the file, and using DriveApp methods

of
the
corresponding
type,
such
as
a
Document,
Spreadsheet,
or
Presentation.
This
object
then
provides
methods
to
interact
with
the
file,
for
example
accessing
its
content,
metadata,
or
structure.
If
the
file
type
is
not
compatible
with
the
service
or
the
ID
is
invalid,
the
call
throws
an
error.
The
script
must
be
authorized
with
the
appropriate
scope
to
access
the
file.
a
document
can
be
opened
with
DocumentApp.openById(id)
and
browsed
via
getBody()
or
getName();
a
spreadsheet
can
be
opened
with
SpreadsheetApp.openById(id)
to
access
sheets
and
ranges;
a
presentation
can
be
opened
with
SlidesApp.openById(id)
to
manipulate
slides.
It
is
important
to
note
that
the
script
must
have
permission
to
access
the
file,
which
may
require
sharing
or
domain-level
access.
to
retrieve
a
file
by
ID
before
performing
type-specific
operations.