►
From YouTube: Office Scripts: Introduction to the make-up of a script
Description
See here for more details and additional samples: https://github.com/sumurthy/officescripts-projects/tree/main/Getting%20Started#gentle-introduction-to-script
Content:
0:00 Introduction to scripts
13:57 Switch to the Excel web app and access Office Scripts (Automate tab)
14:48 Start a new script - introduction to `main` function
15:28 Getter methods
19:06 Method chaining
21:49 Checking for `undefined` type and handling that condition
25:15 getCollection getter methods and collection handling
30:22 Using functions to organize your code, optional and required arguments
35:00 Setter methods and actions
37:48 Static-typing, implicit-any, explicit-any types
A
Hello
in
this
video
of
of
scripts
we're
going
to
take
a
deeper
look
into
the
script
itself.
A
script
contains
a
set
of
instructions
to
automate
tasks
within
excel
now.
Script
runs
from
start
to
finish
without
requiring
any
user
input.
So
that
means
it
has
all
the
information
it
needs
to
complete
its
automation,
task
and
scripts
do
not
interact
with
each
other.
A
script
can
only
invoke
functions
or
instructions
that
are
written
right
within
inside
it.
A
You
can
start
by
recording
or
creating
a
blank
script
or
edit
an
existing
script,
and
there
is
a
convenient
inbuilt
editor
right
within
excel,
so
there
is
no
setup,
no
configuration,
no
libraries
to
import
and
it's
a
very
easy
process
to
get
started
with
now
to
get
sort
of
familiarized
with
the
how
the
script
is
organized
and
to
be
able
to
begin
to
automate
your
tasks.
There
are
some
concepts
that
you
need
to
know,
beginning
with
the
typescript.
A
Syntax
scripts
are
written
in
typescape
language,
so
basic
understanding
of
the
syntax,
as
well
as
the
static
typings
used
within
typescript,
are
going
to
be
important.
Next,
the
excel
object
models
are
the
apis.
Now
these
are
the
interfaces
that
allows
you
to
interact
with
excel
itself.
So
it
is
important
that
you
understand
how
they
are,
how
to
navigate
around
how
to
discover
apis
and
use
them
in
your
script.
A
Then
there
is
the
structure
of
the
script
itself,
so
there
is
a
predefined
function
called
main,
which
is
the
entry
point
so
familiarity
with
that
function
and
the
argument
that
it
receives,
which
is
the
workbook
argument
and
then,
in
general,
just
how
to
go
about
organizing
your
script
in
a
way
that
is
easy
to
write
and
also
for
somebody
else
to
read
and
continue
to
edit
and
run
it,
and
then
there
is
the
actual
environment
where
you
put
all
of
these
things
together,
for
instance,
how
do
you
record?
How
do
you,
edit?
A
How
do
you
run?
How
do
you
examine
results
and
how
do
you
share
the
script
with
others
for
them
to
use?
So
these
are
all
some
of
the
basic
environment
concepts
that
you
will
need
to
understand,
so
we're
going
to
touch
upon
some
of
these
in
the
in
the
next
few
topics,
beginning
with
the
syntax.
As
I
mentioned,
the
office
scripts
is
written
in
a
typescript
language,
which
is
essentially
a
javascript
from
a
syntactical
standpoint,
and
but
it
also
includes
some
things
known
as
static
typing.
A
So
types
allows
you
to
describe
the
objects,
the
variables
it
allows
you
to
describe
the
functions
and
what
it
accepts,
what
it
returns
and
overall
it
helps
with
writing
better
scripts.
So
it
helps
you
to
avoid
common
mistakes
that
you
can
only
discover
later
on
in
during
the
runtime.
So
you
can
catch
mistakes
early.
It
also
assists
with
code
completion,
which
is
a
way
to
discover
the
type
of
objects
or
variables
and
then
figure
out
which
apis
to
call.
A
So
all
of
these
is
driven
by
the
the
static
typing
feature
provided
within
the
typescript
language
and
bottom
line.
Is
it
is
there
to
help
the
author
write,
a
better
quality
scripts
and
then
there
is
the
object
model,
the
apis
offered
by
office
scripts
to
interact
with
excel,
and
it
is
designed
for
end
users
who
may
not
have
a
whole
lot
of
coding
background.
So
it
is
easy
to
get
started
with
and
to
understand,
using
the
naming
conventions
and
simple
syntax
used
within
the
apis
to
help
you
start
begin
to
interact
with
excel
now.
A
A
A
Now.
Let's
look
at
the
main
function
that
I
reference.
So
all
of
the
functions
all
of
these
scripts
that
you're
going
to
see
will
contain
this
function
called
main
now
main
is
the
entry
point
to
a
script
and
main
function
is
required
to
be
present
in
all
of
the
scripts
without
the
main
function,
it
may
still
be
syntactically
a
valid
script,
but
there
is
no
entry
point
for
office
scripts
to
begin
the
execution.
A
So
it
is
important
that
you
keep
the
main
function
as
is,
and
also
the
very
first
argument
that
you
will
see
is
the
workbook
argument.
So
this
represents
the
actual
excel
file,
and
you
will
see
that
the
type
of
the
argument
is
also
provided
right
within
the
function
argument
list,
and
it
is
a
way
for
typescript
to
help.
A
You
understand
that
hey
you're,
receiving
a
workbook
argument
to
this
main
function
of
type
excel
script.workbook,
so
excel
script,
is
think
of
it
as
just
a
family
of
all
the
types
and
workbook
is
one
of
the
object
types
within
it.
Now
you
can
add,
you
can
add
additional
arguments
to
the
function,
but
it
is
important
that
you
keep
the
workbook
argument,
as
is
all
right.
A
So
the
additional
arguments
are
used
in
power,
automation,
scenarios
and
I'm
going
to
show
a
sample
of
that
in
the
in
the
coming
topics,
and
it
helps
the
additional
arguments.
Help
receive
data
to
the
script
and
also
the
main
function
can
return
results
out
of
it.
That
is
a
way
to
send
data
out,
but
for
simple
scenarios,
where
your
automation
runs
right
within
the
excel
application,
you
typically
have
only
one
argument,
which
is
just
the
workbook
argument.
A
Now
your
code,
your
actual
script,
logic
and
processing,
all
all
of
that
happens
right
within
the
within
the
main
function
itself,
which,
in
the
in
the
body
of
the
main
function,
as
you
can
see
here,.
A
All
right
so
again
keep
the
main
function,
as
is,
and
keep
the
first
argument.
Positional
argument.
Workbook,
as
is
you,
can
add
additional
arguments
for
more
advanced
scenarios,
but
for
all
of
the
scripts.
The
main
function
has
to
contain
the
workbook.
As
the
first
argument
now-
and
I
mentioned
the
arguments
that
it
can
receive
so
essentially
think
of
the
main
function
arguments
and
what
it
returns
as
a
gateway
to
interact
with
the
actual
script.
A
So
here
this
function,
this
script
rather
receives
a
set
of
customer
ids
and
then
does
a
lookup
on
a
table
and
then
it
for
each
of
the
customer
id
that
you
can
find
a
match
on.
It
sends
back
the
id
and
the
region
in
the
form
of
an
object
array.
It's
a
customer
region
that
you
see
in
the
output
type
on
the
first
line.
It's
just
telling
you
that
the
main
function
returns
an
array
of
customer
region
object
which
is
defined
all
the
way
at
the
bottom
as
an
interface.
A
It
contains
id
of
the
customer
that
it
received
one
per
customer
and
then
the
region
that,
if
it
could
find
the
match
and
the
output
itself,
is
returned,
as
you
can
see
towards
the
end
where
I'm
returning
an
output
and
that
is
off
the
type
customer
region.
So
essentially
the
point
I'm
trying
to
make
is
that
main
function
allows
script
to
be
connected
to
other
parts
of
your
organization.
A
Now,
power
automation
allows
sending
and
receiving
data
to
and
from
script,
and
if
you're
running
the
script
right
within
excel
app,
you
will
have
to
manage
what
comes
in
into
the
script
yourself,
but
in
the
case
of
power,
automation,
which
is
what
it
is
designed
for.
You
can
feed
in
data
like
in
the
case
here,
I'm
sending
customer
ids
in
the
form
of
a
string
and
that
can
be
consumed
within
the
script
and
then
the
output
goes
out
and
then
the
power
automation
can
receive
that
and
send
to
another
flow
action.
A
A
Now
I
mentioned
the
main
function,
but
you
can
also
organize
your
code
by
writing
different
functions
so
that
you
can
write
ones
and
use
it
across
many
other
parts
of
the
the
same
script.
So
you
can
use
additional
functions
to
organize
your
script
and
the
key
thing
to
notice.
You
can
only
call
functions
that
are
written
within
your
own
script.
You
cannot
call
into
any
function.
That's
written
outside
of
it.
A
So
here
the
main
function
calls
in
another
function
called
add
row
at
end,
which
receives
the
the
worksheet
where
the
row
needs
to
be
added
in
the
form
of
a
sheet
argument.
The
second
argument
called
data
receives
the
actual
data
to
be
added
and
it
does
the
processing
and
adds
a
row
at
the
end
of
the
worksheet
all
right.
So
let's
look
at
the
object
model.
A
A
A
A
Properties
are
can
be
scalar
like
strings
or
numbers
or
booleans,
or
it
can
also
be
of
type
objects.
So,
in
this
case,
worksheets
is
a
collection
of
worksheet
objects
sitting
inside
the
workbook
and
an
example
of
another
object
can
also
be
something
like
a
hyperlink
object.
So
range
object.
A
Has
a
method
called
get
hyperlink,
which
returns
a
hyperlink
object
which
in
itself
can
contain
other
properties
like
address
and
text
now,
scalar
property
tends
to
be
of
you,
know
simple
types
like
strings
and
numbers,
and
usually
it
represents
something
such
as
like
an
address
of
a
hyperlink
or
a
name
of
a
worksheet
or
a
position
of
a
worksheet
in
the
form
of
a
number.
For
instance,
you
can
also
have
something
like
hey.
Does
this
header?
A
Does
this
table
have
a
header
or
not,
which
tends
to
be
a
boolean
property?
Now
methods
mainly
perform
three
types
of
things.
One
is
the
the
getters,
which
means
it
gets
some
property
or
another
object.
So
here
examples
are
get
name
get
active
cell
which,
which
returns
a
range
object.
Git
get
me
a
table,
get
a
list
of
worksheets
that
returns
a
collection
of
worksheet
objects
or
an
array
of
worksheet
objects,
and
then
there
are
setters.
So
these
actually
sets
some
scalar
property.
A
Like
in
set
name
or
set
position,
and
then
there
are
methods
that
are
of
type
actions
which
performs
some
action
on
the
workbook,
such
as
deletion
of
an
object
or
calculate
or
to
resize
a
chart,
for
instance,
or
clear,
a
range
or
position
a
chart
to
a
certain
cell.
So
these
are
all
different
types
of
methods
that
you
can
get
as
part
of
an
object
and
there's
also
another
special
type
of
a
getter
method,
which
is
git
collection.
A
A
All
right
now,
let's
look
at
some
of
the
concepts
concepts
that
we
just
talked
about
in
practice,
so
here
I'm
in
excel
for
online,
and
I
see
the
automate
tab,
which
is
the
place
where
all
the
office
scripts
features
are
surfaced
and
it
comes
with
the
record
actions
which
is
a
feature
through
which
you
can
record
your
actions
that
converts
into
a
script
using
which
you
can
get
a
base
script
to
start
what
start
with
or
you
can
access
the
all
scripts
task,
pane
that
shows
list
of
all
the
scripts
that
I
currently
have,
and
it
also
has
scripts
that
are
shared
with
this
workbook,
which
is
a
way
to
pin
scripts
to
a
workbook
and
other
samples
to
help
you
get
started
out
with
now.
A
As
I
mentioned
before,
there
are
three
ways
to
start
out:
you
could
record
and
get
a
script
or
you
could
edit
existing
one
or
you
can
simply
create
a
new
script,
which
is
what
I'm
going
to
do
right
now
now,
once
you
have
the
script,
the
familiar
main
function
is
going
to
be
present,
so
you
get
that
out
of
the
box
and
you'll
see
that
it
has
the
workbook
parameter.
A
So
workbook
is
just
the
name
of
a
variable.
It
is
of
type
excel
script.
Workbook
now
excel
script
is
the
top
level
namespace
under
which
all
of
the
apis
or
the
types
of
the
apis
that
we
offer
is
going
to
be
grouped
under
so
workbook
is
one
such
and
you
also
find
other
things
like
worksheets
and
range,
and
so
on
as
we'll
see
further
down
now
the
the
cool
thing
about
the
editor
is
using
the
the
variable
name
and
the
dot
notation
you
get
to
discover
all
the
apis
that
are
available.
A
So
this
is
a
nice
handy
way
to
figure
out
what
apis
that
you're
looking
after
and
it
also
filters
based
on
the
typing.
You
do
so.
Let's
say
I'm
interested
in
knowing
the
name
of
the
workbook,
so
I
can
just
simply
type
name
and
then
it
shortlists
all
the
apis
that
contains
the
word
name
and
it
also
searches
in
the
middle
of
the
the
name
it
just
doesn't
have
to
be
at
the
beginning.
A
So
so
here's
a
good
example
of
demonstrating
the
types
of
methods
that
are
available
beginning
with
the
getter
api.
So
the
workbook,
it
name
returns
a
string
which
contains
the
name
of
the
workbook,
and
you
know
that
by
just
simply
hovering
over
the
api
name,
and
you
know
that
this
is
a
method
and
it
is
returning
value
of
type
string.
So
this
is
a
what
is
known
as
a
scalar
variable,
which
means
it's
just
of
type
string
basic
type.
Now
there
are
other
more
interesting
apis
that
you
can
also
find.
A
So
let's
say
I
want
to
read
the
data
of
the
current
cell,
so
I
can
do
that
by
using
another
type
of
a
data
method
which
returns
an
actual
object.
So
I
can
say
cell,
give
me
I'll
just
look
forward
cell,
so
that
is
the
get
active
cell
and
remember
to
open
and
close
parenthesis
for
method
names,
because
it
is
essential
that
you
execute
the
method.
A
Otherwise
it
will
simply
assign
that
function,
and
it
is
not
useful
that
way.
So
now
I
execute
the
method
and
the
value
that
I
get
back
is
assigned
to
this
constant
variable
called
cell.
Now
constant
is
a
typescript
keyword
that
just
simply
says
that
hey
I'm
going
to
assign
this
to
once
to
this
variable
name
cell
once
and
I'm
not
going
to
reassign
it.
A
If
you
wish
to
reassign
it
to
another
to
another
object
later
on,
you
could
use
the
let
keyword
right
so
now
that
I
have
that.
I
can
now
begin
to
explore
the
cell
object.
Furthermore,
to
see
what
else
does
that
offer?
So
I'm
interested
in
getting
the
let's
say
the
text
value
that
is
displayed
here,
I
can
use
the
dot
notation
again
and
simply
just
type
in
text.
I
know
that
it
has
the
text
get
text,
so
there
are
usually
for
range
api.
A
A
A
A
So
what
you
saw
are
two
different
type
of
getter
apis,
one
that
returns
a
scalar
value,
another
one
that
returns
an
object,
in
this
case,
a
cell
which
is
really
of
type
excel
script
range
and
then
using
which
you
can
get
access
the
methods
that
the
cell
itself
offers.
Now
I
could
have
done
this
all
in
a
single
line
using
what
is
known
as
a
dot
notation.
A
So,
for
instance,
I
could
do
get
cell
and
dot
get
text,
and
it
is
useful
to
do
this
when
you
know
that
the
value
that
you're
fetching
out
of
the
api
that
precedes
the
dot
in
this
case
is
this
active
cell
is
going
to
be
present.
A
There
are
cases
where
the
dot
notation
may
not
work
really
well.
So
I'll
show
that
you
know
in
a
second
so
yeah,
so
using
the
dot
notation,
you
can
go
down
as
many
levels
as
possible
as
long
as
the
the
dot
notation
after
that
makes
sense
to
you,
for
instance,
here,
because
get
text
returns
the
string
that
is
really
the
leaf
node
that
I'm
looking
for.
A
But
if
I
had
say
you
know
get
off
of
the
the
cell,
I
could
do
something
else
like
let's
say
get
column,
and
then
I
could
do
you
know
dot
further
down
and
go
further
down
like
that.
So
in
this
case,
all
I'm
looking
for
is
just
the
the
text
value.
So
I'm
gonna
stop
at
that
now.
The
methods
that
you've
seen
so
far
with
open
and
close
paranthesis
it
doesn't
none
of
these
accepts
any
arguments,
but
some
apis.
Some
method
calls
do,
require
arguments
right.
A
So
let's
say
now:
I
want
to
display
the
position
of
a
sheet
and
display
the
number
or
the
position
where
it
occurs
in
the
workbook.
So
to
do
that,
I
first
need
to
get
the
actual
worksheet
object
itself
and
then
display
its
position.
So
I
can
do
that
by
first
getting
the
the
position
using
the
dot
notation
that
I
was
talking
about
so
workbook.
A
A
So
when
I
run
this
code,
it
display
the
position
that
I'm
in
so
this
is
zero
index.
It's
saying
that
I
am
in
position
position
first
position.
This
is
zeroth
position
so
that
works
out
fine.
So,
as
you
can
see,
the
dot
notation
was
convenient,
but
there
are
cases
where,
especially
when
you
supply
an
argument
and
the
resulting
value
may
not
return
an
actual
object
that
you
are
anticipating.
A
So
in
this
case
let's
say
I
do
sheet
3,
so
there
is
no
sheet
3
and
when
I
try
to
get
this
and
run
this,
it
says
that
hey
there
is
no
such
thing
as
get
position
of
undefined
on
line
4..
So
the
problem
here
is
that
I
was
a
little
bit
ambitious
in
trying
to
use
the
dot
notation
in
cases
where
I
know
that
the
resulting
value
coming
out
of
the
git
worksheet
api
may
or
may
not
be
an
actual
worksheet,
whereas
in
line
three
the
get
active
cell.
A
So
I
know
there
is
always
an
active
cell
in
a
workbook,
so
it
is
safe
to
use
the
dot
notation
and
carry
on.
But
in
this
case
I
will
have
to
use
a
little
bit
more
logic
to
handle
this
correctly.
A
So
to
do
that,
first,
you
need
to
know
what
undefined
is
undefined
is
a
a
native
typescript
type,
and
it
essentially
means
that
that
the
a
variable
is
not
assigned
with
an
actual
object
or
a
actual
value.
So
in
this
case
the
get
worksheet
could
not
return
any
meaningful
result,
so
it
assigned
by
default
undefined.
A
A
And
else
I
can
handle
the
condition.
So
let's
say
I
just
want
to
say:
hey
this
sheet
sheet
is
not
present,
so
this
is
one
way
of
handling
the
conditions
where
you
know
that
the
api
may
or
may
not
result
in
something
that
you're
expecting
so
the
sheet
3
doesn't
exist
so
sheet
4.
I
should
get
the
value
of
1
as
expected.
A
So
what
I
showcased
so
far
is
the
ability
to
use
the
the
methods
off
of
an
object,
get
scalar
properties,
things
like
name
and
position
and
also
use
the
same
getter
methods
to
get
another
object
and
using
which
you
can
continue
to
chain,
but
do
take
precaution
on
apis.
That
accepts
arguments
because
those
apis
may
not
return
the
result
that
you
are
anticipating.
So
in
this
case,
get
worksheet.
A
Some
apis
requires
arguments
and
arguments
may
be
required
or
optional,
and
when
you
hover
over
any
method,
you
will
see
that
it
will
display
all
the
things
that
it
needs
from
an
argument.
Standpoint
like
all
the
essential
argument
it
needs
in
some
cases
you
don't
you
don't
need
an
argument
all
right.
So
we
looked
at
certain
types
of
data
methods,
so
there
is
one
other
sort
of
special
type
of
data
method.
A
Those
don't
result,
don't
return
a
scalar
or
an
object,
but
rather
it
returns
an
array
of
objects
or
a
collection
of
objects
and
those
methods
usually
end
with
the
the
plural
notation.
So
in
this
case
let's
say
I
want
to
get
all
the
worksheets,
so
I
could
say
sheets
from
the
workbook
get
worksheets,
so
the
difference
here
is
that
it's
not
returning
a
single
sheet,
but
you
know
we
saw
active
worksheet
earlier,
but
this
is
the
the
the
worksheets
collection
and
when
I
hover
over
you'll,
see
the
notation
of
the
open,
close
parenthesis.
A
A
Now,
once
I
have
the
collection,
if
I
wish
to
get
to
the
individual
elements
of
it,
so
each
individual
element
of
this
array
is
an
individual.
You
know
object
so
in
this
case
worksheet.
So
let's
say
I
want
to
display
all
the
names
of
the
worksheets
that
are
associated
here,
so
I
could
simply
collect,
let's
say
sheet
names,
and
so
let's
say.
A
I'll
assign
an
a
blank
array,
and
I'm
going
to
simply
iterate
over
using
a
for
loop
so
for
loop,
is
something
that
javascript
provides
to
iterate
over
the
collections,
so
let
sheet
of
sheets.
So
this
is
one
of
the
many
different
ways
you
could
iterate
over
a
collection
and
then
I'm
going
to
push
the
actual
sheet
name,
one
at
a
time
using
the
the
get.
A
So
let's
say
I
want
to
order
this
in
ascending
or
descending
order,
so
I
can
do
that
by
you
know
once
one
once
that
I
have
the
all
the
sheet
names
collected,
I
can
order
the
sheet
names,
and
this
is
processing.
That's
happening
on
your
on.
Your
typescripts
are
on
your
script
site,
so
I
can
now
sort
so
sort
is
again
a
method
native
array
method
that
the
typescript
offers.
A
So
once
I
sort
this,
I
can
do
a
for
each
so,
which
is
again
a
native,
a
typescript
method
that
accepts
a
callback
function,
which
means
whatever
you
supply
in
here.
It's
going
to
perform
that
once
per
instance
of
that
array.
So
here
I
can
get
the
sheet
and
the
index,
so
this
is
supplied
to
me
as
part
of
the
for
each
function,
and
so
once
I
have
the
sheet
name,
I
can
go
back
and
get
the
sheet
name
get
the
worksheet,
so
remember,
get
worksheet
requires
a
parameter
of
sheet
name
so
here.
A
And
then
I
could
do
the
set
position
so
set
position
takes
in
an
index
and
a
number,
so
I
can
do
the
index.
So
where
did
the
index
come
from,
so
the
for
each
accepts
a
function
and
that
function
automatically
gets
the
instance
of
the
array
that
it
is
iterating
over
and
then
also
the
index
that
it
is
on
and
the
argument
was
supplied
by
typescript.
So
I
don't
have
to
worry
about
it
all
I
need
to
worry
about.
It
is
how
do
I
process
that
within
the
the
function?
A
So
when
I
run
this
it,
it
is
going
to
order.
As
you
can
see
now,
you
know.
Let's
say
I
want
to
reverse
the
order,
so
I
could
sort
sort
it
and
then
reverse
it
and
reverse
is
again
a
javascript
or
a
typescript
function,
and
when
I
run
this,
it
will
reverse
the
order
in
which
it
is
sorting.
So
this
is
quite
powerful
in
a
way
that
you
can
use
collections,
and
it
is
also
quite
easy
to
manage
that
now.
A
The
one
other
concept
that
I
talked
about
was
arranging
your
code
in
a
way
that
makes
it
easy
to
reuse.
So,
let's
suppose
the
the
cool
sorting
functionality
that
we
saw
here
is
going
to
be
called
multiple
times
during
your
script.
So,
instead
of
repeating
this
lines
over
and
over,
I
can
extract
the
logic
into
a
separate
function.
So
I'm
going
to
call
that
function,
sort
sheets.
A
A
And
it
doesn't
return
anything
it
simply
sorts
the
function
starts
the
worksheet,
so
I
can
simply
copy
all
of
the
code
here
into
this
function.
I
need
to
account
for
the
fact
that
the
reverse
could
be
you
know
true
or
false.
So
so
let
me
collect.
A
A
And
if
not,
I
will
simply
assign
it
without
the
reverse,
and
then
I
can
keep
the
rest
of
the
code,
as
is
by
simply
using
the
new
variable
that
I
created
so
now
now
that
I've
defined
this
function,
I
can
call
this
function
from
many
other
places,
so
to
call
I
will
need.
A
I
will
need
to
invoke
it
so
sort
sheets.
So
remember,
anytime,
you
call
a
method
or
a
function.
You
need
to
execute
by
open,
close
parenthesis
and
typescript
autocompletion
is
saying
is
that
it
requires
two
arguments
of
one
workbook,
another
one
of
type.
You
know
whether
should
I
reverse
or
not
so,
let's
say
right
now
I'll
say
no.
A
So
when
I
run
this
code,
it
is
going
to
simply
call
the
sort
sheets.
It
is
not
returning
anything
it's
directly
acting
on
the
on
the
workbook
and
it
sorted
in
the
order.
So
let's
say
I
want
to
reverse
the
order.
I
can
simply
change
the
argument
and
have
it
sort
in
the
ascending
order
now
the
the
argument.
So
these
are
the
two
arguments
that
I
provided
now.
The
reverse
is,
you
know
both
are
required
arguments,
which
means
the
function
cannot
operate
unless
both
arguments
are
provided.
A
Now,
if
I
do
not
supply,
one
of
the
argument
type
skip
will
complain
that
hey
look.
It
is
expecting
two
arguments,
but
you're
only
supplying
one
now,
let's
say
by
default.
I
only
want
to
sort
this
in
the
ascending
order
and
only
in
cases
where
I
want
to
sort
in
descending
order.
I
want
to
provide
the
the
variable,
so
in
that
case
I
can
make
the
reverse.
A
A
A
A
A
Now,
let's
look
at
another
method,
another
type
of
method
that
sets
the
value
which
these
are
called
setter
methods.
So
here
I
want
to
change
the
the
active
cell
value,
so
I
will
simply
do
that
by
getting
workbook
get
active
cell.
A
A
And
I'm
going
to
run
this
code,
so
it
changed
the
value
to
new
sample
data.
So
this
is
the
setters
allows.
You
allow
you
to
change
some
content
within
excel,
whether
it's
you
know,
values
of
a
range
or
a
name
of
a
chart
or
position
of
a
sheet.
So
these
are
all
sort
of
setter
values
set
of
methods,
and
then
there
are
other
type
of
methods
that
you
know
does
some
unique
actions.
A
Now
I
can
take
the
active
cell
and
instead
of
setting
its
value.
Let's
say
I
want
to
you,
know
clear
it
now
clear
accepts
an
optional
parameter
called
apply
to
and
it
is,
it
is
of
type
enum
or
enumeration
and
enumerations
are
a
way
to
ensure
that
you
don't
supply
invalid
arguments,
so
clear,
apply
to
and
then
dot
seems
like.
There
are
three
different
options
or
four,
or
rather
five
different
options.
A
The
first
one
removes
all,
let's
say,
contents
and
formats.
So
let's
say
I
want
to
only
clear
content.
So
I
can
run
this
api
and
it'll
only
clear
the
the
content
and
leave
the
formatting
as
is,
and
I
can
come
back
and
you
know
change
this
to
formats.
It'll
now
change
the
format
as
well.
A
So
this
is
not
a
setter
method,
but
it
is
a
type
of
method
that
makes
some
sort
of
update
on
your
workbook.
The
other
types
of
such
methods
are
things
like
deleting
a
table
or
a
worksheet,
so
they
actually
cause
some
right
action
on
your
on
your
workbook
all
right.
So
the
last
thing
I'm
going
to
talk
about
is
the
importance
of
typing.
A
A
So
any
is
a
type
where
if
typescript
is
unable
to
infer
the
type,
it
is
going
to
complain
that
hey
look,
I
don't
know
what
type
you
are
using,
so
I
cannot
function
correctly.
So
it
is
important
that
you,
when
any
time
you
declare
a
variable,
you
assign
it
immediately
or
at
the
minimum,
declare
its
variable
name.
Sorry,
it's
its
type.
So
here
using
this,
I
can
you
know
somewhere
else
in
the
chord
the
the
variable
can
be.
A
Assigned
an
actual
value
and
that
meets
the
criteria
defined
here.
If
I
define
something
else
taps
it
is
going
to
complain
that
you
are
defining
something
else,
so
it
is
essential
that
when
you
define
a
variable
that
you
assign
the
value
immediately,
if
you
are
unable
to
assign
value
as
in
the
case
here,
I'm
just
defining
a
variable,
but
you
have
to
also
define
the
types.
If
you
do
not
do
it,
the
result
can
be
unpredictable.
In
some
cases
it
will
simply
throw
an
error.
A
The
one
other
error
that
you
might
see
is
the
we
don't
allow
explicit
any
type,
because
if
you,
when
you
define
a
type,
let's
say
some
variable
of
type
any,
so
you
will
immediately
get
an
error
that
says
that
see
the
red
squiggly
line.
It
says
explicit.
Any
is
not
allowed
and
typescript
works
best
when
you
supply,
when
you
define
the
type
of
variables
or
the
arguments
in
in
this
case,
office
script
simply
doesn't
know
how
to
handle
this
in
what
context
to
handle
this
so
make
sure
that
you
don't
define
of
type
any.