NativeExcel for .Net Developer's Reference

IWorkbook.SaveAsMethod(Stream)

Saves the workbook to the specified output stream.

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

Parameters

outputStream
The output stream.

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);

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)

Response.End()

See Also

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