Wiki Markup |
---|
Excerpt |
The ExcelApplication object has several options for saving your ExcelApplication generated file. |
Using the ExcelApplication object's
...
Save
...
methods,
...
you
...
can:
Table of Contents | ||
---|---|---|
|
Note |
---|
When ExcelWriter streams a file to the client, the output result will depend on the browser as well as the server-side script. |
Save to Disk
To save the generated file on the server, call one of the following methods:
Code Block |
---|
void Save(Workbook workbook, string fileName)
void Save(Workbook workbook, string fileName)
{code}
|
fileName
...
specifies
...
a
...
complete
...
physical
...
path
...
and
...
file
...
name
...
for
...
the
...
generated
...
file.
...
ExcelWriter
...
will
...
save
...
the
...
file
...
to
...
this
...
location.
...
If
...
a
...
file
...
with
...
the
...
same
...
name
...
exists,
...
it
...
will
...
be
...
overwritten
...
by
...
the
...
new
...
Excel
...
file.
...
Example
Code Block | ||
---|---|---|
| ||
ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Create();
xla.Save(wb, @"C:\Sales2003\June.xlsx");
{code}
{anchor:browser}
h2. Stream to Client
To stream the generated file to the client, call one of the following methods:
{code}
|
Stream to Client
To stream the generated file to the client, call one of the following methods:
Code Block |
---|
void Save(Workbook workbook, System.Web.HttpResponse response, string fileName)
void Save(Workbook workbook, System.IO.Stream stream)
void Save(Workbook workbook, System.Web.HttpResponse response, string fileName, bool openInBrowser)
void Save(Workbook workbook, System.Web.HttpResponse response, string fileName, bool openInBrowser, string contentType)
{code}
|
Browsers
...
other
...
than
...
Internet
...
Explorer
...
cannot
...
embed
...
an
...
Excel
...
file
...
in
...
the
...
browser
...
window.
...
When
...
the
...
generated
...
spreadsheet
...
is
...
streamed
...
to
...
a
...
browser
...
other
...
than
...
IE,
...
the
...
user
...
will
...
always
...
be
...
prompted
...
to
...
open
...
or
...
save
...
the
...
file.
...
If
...
the
...
user
...
chooses
...
to
...
open
...
the
...
file,
...
it
...
will
...
open
...
in
...
Microsoft
...
Excel
...
or
...
another
...
spreadsheet
...
application.
...
Internet
...
Explorer
...
can
...
display
...
an
...
Excel
...
file
...
in
...
the
...
browser
...
window.
...
When
...
the
...
generated
...
spreadsheet
...
is
...
streamed
...
to
...
Internet
...
Explorer,
...
the
...
browser's
...
settings
...
will
...
determine
...
whether
...
the
...
file
...
opens
...
automatically
...
or
...
the
...
user
...
is
...
asked
...
to
...
open
...
or
...
save
...
the
...
file.
...
The
...
parameter
...
openInBrowserdetermines
...
whether
...
the
...
file
...
will
...
open
...
in
...
IE
...
or
...
in
...
a
...
spreadsheet
...
application.
...
If
...
openInBrowser
...
is
...
set
...
to
...
true,
...
the
...
response
...
content-disposition
...
header
...
is
...
set
...
to
...
open
...
the
...
file
...
in
...
the
...
browser
...
window.
...
Example
Code Block | ||
---|---|---|
| ||
ExcelApplication xla = new ExcelApplication(); Workbook wb = xla.Create(ExcelApplication.FileFormat.Xlsx); xla.Save(wb, Page.Response, "workbook.xlsx", false); {code} {anchor:stream} h2. Write to Stream To write the generated spreadsheet to a |
Write to Stream
To write the generated spreadsheet to a System.IO.Stream,
...
call
...
the
...
following
...
method:
...
Code Block |
---|
void Save(Workbook workbook, System.IO.Stream stream){code}
h3. Example
{code:c#}
ExcelApplication |
Example
Code Block | ||
---|---|---|
| ||
ExcelApplication xla = new ExcelApplication(); Workbook wb = xla.Create(ExcelApplication.FileFormat.Xlsx); FileStream fstream = new FileStream(@"C:\temp\outfile.xlsx", FileMode.Create); xla.Save(wb, fstream); {code} {anchor:template} h2. Return a Template You can use ExcelApplication to create a spreadsheet with data markers |
Return a Template
You can use ExcelApplication to create a spreadsheet with data markers (i.e.,
...
a
...
template)
...
and
...
pass
...
the
...
spreadsheet
...
to
...
ExcelTemplate
...
to
...
populate
...
the
...
data
...
markers.
...
In
...
this
...
case,
...
do
...
not
...
call
...
Save.
...
Instead,
...
pass
...
your
...
Workbook
...
object
...
to
...
ExcelTemplate's
...
Open
...
method:
...
Code Block |
---|
void ExcelTemplate.Open(ExcelApplication excelApplication, Workbook workbook){code}
h3. Example
{code:c#}
ExcelApplication |
Example
Code Block | ||
---|---|---|
| ||
ExcelApplication xla = new ExcelApplication(); Workbook wb = xla.Create(ExcelApplication.FileFormat.Xlsx); ExcelTemplate xlt = new ExcelTemplate(); xlt.Open(xla, wb); {code} {scrollbar} |