...
Whenever
...
you
...
change
...
the
...
Cell.Style
...
property,
...
that
...
Cell
...
gets
...
its
...
own
...
Style
...
object.
...
However,
...
if
...
you
...
create
...
a
...
new
...
Style
...
object
...
and
...
then
...
call
...
SetStyle
...
or
...
ApplyStyle
...
on
...
the
...
area
...
or
...
range
...
you
...
want
...
to
...
affect,
...
ExcelApplication
...
will
...
not
...
have
...
to
...
create
...
a
...
seperate
...
Style
...
object
...
for
...
each
...
cell,
...
reducing
...
the
...
amount
...
of
...
memory
...
that
...
is
...
needed.
...
For
...
example,
...
if
...
you
...
are
...
applying
...
the
...
same
...
style
...
to
...
more
...
than
...
one
...
or
...
two
...
cells,
...
you
...
should
...
say:
...
Csharp | ||||
---|---|---|---|---|
| ||||
//Create a global style
GlobalStyle style = wb.CreateStyle();
//Set a cell's style to the new global style
ws.Cells[0,0].Style = style;
//Set an area's style to the new global style
ws.CreateArea(1,1,5,5).SetStyle(style);
//Set a range's style to the new global style
ws.CreateRange("D5:E6").SetStyle(style);
'Create a global style
Dim style As GlobalStyle = wb.CreateStyle()
{chsarp}
{vbnet:1}
'Set a |
Vbnet | ||||
---|---|---|---|---|
| ||||
'Set a cell's style to the new global style
0).Style = style 'Set an area's style to the new global style
1, 5, 5).SetStyle(style) 'Set a range's style to the new global style
|
Alternatively,
...
if
...
you
...
want
...
to
...
apply
...
a
...
single
...
style
...
to
...
all
...
the
...
cells
...
in
...
a
...
column,
...
you
...
can
...
get
...
the
...
ColumnProperties
...
object
...
for
...
that
...
column
...
and
...
call
...
its
...
SetStyle
...
method:
...
//Get
...
the
...
properties
...
for
...
the
...
column
...
you
...
want
...
to
...
alter
...
ColumnProperties
...
properties
...
=
...
ws.GetColumnProperties(0);
...
//Apply
...
a
...
style
...
to
...
that
...
column
...
properties.ApplyStyle(style);
...
'Get
...
the
...
properties
...
for
...
the
...
column
...
you
...
want
...
to
...
alter
...
Dim
...
properties
...
As
...
ColumnProperties
...
=
...
ws.GetColumnProperties(0)
...
'Apply
...
a
...
style
...
to
...
that
...
column
...
properties.ApplyStyle(style)
...
Using
...
one
...
of
...
these
...
two
...
techniques
...
to
...
apply
...
styles
...
will
...
use
...
less
...
memory
...
than
...
creating
...
a
...
new
...
style
...
for
...
each
...
cell
...
or
...
modifying
...
the
...
Cell.Style
...
property
...
directly.
...