|
Programmer's Reference
> ExcelTemplate
> Save
Save(FileName)
C# Syntax:
VB.NET Syntax:
Description:
Saves the generated Excel file on the server. The ASPNET account (IIS5), NETWORK SERVICE account (IIS6), or the authenticated user
must have Write access to the destination directory specified by the
outputFileName parameter.
You can call Save more than once for a single instance of
ExcelTemplate. This allows you to save
more than one copy of a generated file, and/or both save the file on the server and stream
it to the client. Using multiple Process
and Save calls, you can generate multiple files from a single template and an
updated data source.
Parameters:
outputFileName
Specifies a complete 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.
Exceptions:
Example:
[C#]
xlTemplate.Save(@"C:\Reports\Orders.xls");
[VB.NET]
xlTemplate.Save("c:\Reports\Orders.xls")
Save(oStreamObj)
C# Syntax:
VB.NET Syntax:
Description:
Generates an Excel binary file and streams it to the specified
System.IO.Stream or, a class derived from
System.IO.Stream (for example, System.IO.FileStream).
If you pass Save a System.IO.FileStream, ExcelWriter will save
the generated file on the server. If you pass Save Response.OutputStream,
ExcelWriter will stream the the generated file to the client.
You can call Save more than once for a single instance of
ExcelTemplate. This allows you to
save more than one copy of a generated file, and/or both save the file on the server
and stream it to the client. Using multiple Process
and Save calls, you can generate multiple files from a single template and
an updated data source.
Parameters:
outputStream
A System.IO.Stream object (for example, Response.OutputStream)
or, a class derived from System.IO.Stream (for example,
System.IO.FileStream)
Exceptions:
Example:
[C#]
//--- FileStream and FileMode are in the System.IO namespace
FileStream fstream = new FileStream(@"C:\temp\outfile.xls", FileMode.Create);
//--- Pass the FileStream to ExcelTemplate
xlTemplate.Save(fstream);
//--- Close the FileStream (could be in a finally block)
fstream.Close();
[VB.NET]
'--- FileStream and FileMode are in the System.IO namespace
Dim fstream As New FileStream("C:\temp\outfile.xls", FileMode.Create)
'--- Pass the FileStream to ExcelTemplate
xlTemplate.Save(fstream)
'--- Close the FileStream (could be in a finally block)
fstream.Close()
Save(Response)
C# Syntax:
public void ExcelTemplate.Save(System.Web.HttpResponse response);
VB.NET Syntax:
Public Sub ExcelTemplate.Save(response As System.Web.HttpResponse)
Description:
If you pass Save an HttpResponse object
object, ExcelWriter will stream the generated file to the client. If the user
chooses to open (rather than save) the file, it will open in the browser window.
ExcelWriter will set a default name for the file. To set a different file name
and/or to open the file in Microsoft Excel, use the signature
Save(response, attachmentName, OpenInBrowser).
You can call Save more than once for a single instance of
ExcelTemplate. This allows you to save more
than one copy of a generated file, and/or both save the file on the server and stream it to
the client. Using multiple Process and Save
calls, you can generate multiple files from a single template and an updated data source.
Parameter:
response
A System.Http.Response object, usually Page.Response
Exceptions:
Example:
[C#]
xlTemplate.Save(Page.Response);
[VB.NET]
xlTemplate.Save(Page.Response)
Save(response, attachmentName, openInBrowser)
C# Syntax:
public void ExcelTemplate.Save(System.Web.HttpResponse response,
string attachmentName,
bool openInBrowser);
VB.NET Syntax:
Public Sub ExcelTemplate.Save(response As System.Web.HttpResponse,_
attachmentName As String,_
OpenInBrowser As Boolean)
Description:
If you pass Save an HttpResponse object, ExcelWriter will
stream the generated file to the client. This method allows you to specify a
default client-side file name, and whether the file should be opened in the browser
window or in Microsoft Excel.
You can call Save more than once for a single instance of
ExcelTemplate. This allows you to save more than one copy
of a generated file, and/or both save the file on the server and stream it to the client.
Using multiple Process and Save calls,
you can generate multiple files from a single template and an updated data source.
Parameters:
response
A System.Http.Response object, usually Page.Response
attachmentName
Specifies a name for the generated Excel file; this name will be displayed in the
download dialog when the file is streamed to the browser.
openInBrowser
If openInBrowser is set to true, and the
user chooses to open the file, the file will open in the browser
window. If openInBrowser is set to false, and the
user chooses to open the file, the file will open in Microsoft Excel.
By default, the file will open in the browser window. Note: not all
browsers can embed an Excel file in the browser window.
Exceptions:
Examples:
Stream to the client and open in Excel
When you pass an HttpResponse object to Save,
ExcelWriter will stream the generated Excel file to the client.
The browser will display a File Download dialog asking the user to open
or save the file. The method's second parameter specifies a file name
to display in the File Download dialog.
If the method's third parameter - OpenInBrowser -
is false and the user chooses to open the Excel file,
the file will open in Microsoft Excel.
[C#]
//--- Stream to the client
//--- "Output.xls" will appear in the Save As dialog
//--- The file will open in Excel
xlTemplate.Save(Page.Response, "Output.xls", false);
[VB.NET]
'--- Stream to the client
'--- "Output.xls" will appear in the Save As dialog
'--- The file will open in Excel
xlTemplate.Save(Page.Response, "Output.xls", False)
Stream to the client and open in the browser window
When you pass an HttpResponse object to Save,
ExcelWriter will stream the generated Excel file to the client.
The browser will display a File Download dialog asking the user to open
or save the file. The method's second parameter specifies a file name
to display in the File Download dialog.
If the method's third parameter - OpenInBrowser -
is True and the user chooses to open the Excel file,
the file will open in the browser window.
[C#]
//--- Stream to the client
//--- "Output.xls" will appear in the Save As dialog
//--- The file will open in the browser's Excel plug-in
xlTemplate.Save(Page.Response, "Output.xls", true);
[VB.NET]
'--- Stream to the client
'--- "Output.xls" will appear in the Save As dialog
'--- The file will open in the browser's Excel plug-in
xlTemplate.Save(Page.Response, "Output.xls", True)

Copyright 2007 © SoftArtisans, Inc. All Rights Reserved.
|