NativeExcel for .Net Developer's Reference

IRange.SaveAsMethod(Stream, XlFileFormat, ExportOptions)

Saves the range data to the specified output stream.

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

Parameters

outputStream
The output stream.
FileFormat
XlFileFormat enumeration. A value that indicates format of the data to be saved. This method supports the following file formats: XlFileFormat.xlHtml, XlFileFormat.xlCSV, XlFileFormat.xlText, XlFileFormat.xlUnicodeCSV, XlFileFormat.xlUnicodeText.
options
ExportOptions. An object which contains export options.

Return Value

Returns true if it succeeded, false otherwise.

Example

This example saves two ranges B12:H10 and B22:H30 into single CSV file.

[C#]
IWorkbook book = NativeExcel.Factory.OpenWorkbook("book.xls"); 
string FileName = "book.csv";
IWorksheet sheet = book.Worksheets[1];
using (FileStream fs = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.None)) 
{
    sheet.Range["B12:H10"].SaveAs(fs, XlFileFormat.xlCSV);
    sheet.Range["B22:H30"].SaveAs(fs, XlFileFormat.xlCSV);
}

See Also

IRange Interface | NativeExcel Namespace | IRange.SaveAs Overload List | Factory Class | IRange.SaveAs(System.String, NativeExcel.XlFileFormat) method | IWorksheet.SaveAs(System.IO.Stream, NativeExcel.XlFileFormat) method | IWorkbook.SaveAs(System.IO.Stream, NativeExcel.XlFileFormat) method