NativeExcel for .Net Developer's Reference

IWorkbook.SaveAsMethod(Stream, XlFileFormat)

Saves the workbook to the specified output stream.

[Visual Basic]
FunctionSaveAs(_
ByValoutputStreamAsStream,_
ByValFileFormatAsXlFileFormat_
)AsBoolean
[C#]
boolSaveAs(
StreamoutputStream,
XlFileFormatFileFormat
);
[C++]
boolSaveAs(
Stream*outputStream,
XlFileFormatFileFormat
);
[JScript]
functionSaveAs(
StreamoutputStream,
XlFileFormatFileFormat
):bool;

Parameters

outputStream
The output stream.
FileFormat
XlFileFormat enumeration. A value that indicates format of the workbook to be saved.

Return Value

Returns true if it succeeded, false otherwise.

Example

This example demonstrates how to stream workbook from a web server to a browser (ASP.NET).

[C#]
//Create workbook
IWorkbook book = NativeExcel.Factory.CreateWorkbook();
IWorksheet sheet = book.Worksheets.Add();

sheet.Cells["B2"].Value = "Hello World!!!";
sheet.Cells["B2"].Font.Size = 20;
sheet.Cells["B2"].ColumnWidth = 50;

//Stream workbook  
Response.Clear(); 
Response.ContentType = "application/vnd.ms-excel"; 
Response.AddHeader("Content-Type",        "application/vnd.ms-excel");
Response.AddHeader("Content-Disposition", "attachment;filename=book.xls"); 

book.SaveAs(Response.OutputStream, XlFileFormat.xlExcel97);

Response.End();
[VisualBasic]
'Create workbook
Dim book As IWorkbook = NativeExcel.Factory.CreateWorkbook()
Dim sheet As IWorksheet = book.Worksheets.Add()

sheet.Cells("B2").Value = "Hello World!!!"
sheet.Cells("B2").Font.Size = 20
sheet.Cells("B2").ColumnWidth = 50

'Stream workbook  
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Type", "application/vnd.ms-excel")
Response.AddHeader("Content-Disposition", "attachment;filename=book.xls")

book.SaveAs(Response.OutputStream, XlFileFormat.xlExcel97)

Response.End()

See Also

IWorkbook Interface | NativeExcel Namespace | IWorkbook.SaveAs Overload List | Factory Class