DS2XL Class Library  

DS2XL.ExportToStream Method

Exports DataSet,  DataTable or DataView into specified format and returns result as a System.IO.Stream.

Overload List

Exports DataSet  into the stream using specified xpOutputFormat format value.

[Visual Basic] Overloads Public Function ExportToStream(DataSet, xpOutputFormat, Boolean) As Stream 
[C#] public Stream ExportToStream(DataSet, xpOutputFormat, bool);

Exports DataTable into the stream using specified xpOutputFormat format value.

[Visual Basic] Overloads Public Function ExportToStream(DataTable, xpOutputFormat, Boolean) As Stream
[C#] public Stream ExportToStream(DataTable, xpOutputFormat, bool);

Exports DataTable into the stream using specified list of columns and xpOutputFormat format value.

[Visual Basic] Overloads Public Function ExportToStream(DataTable, String(), xpOutputFormat, Boolean) As Stream
[C#] public Stream ExportToStream(DataTable, string[], xpOutputFormat, bool);

Exports DataSet  into the stream using specified list of columns and xpOutputFormat format value.

[Visual Basic] Overloads Public Function ExportToStream(DataSet, String(), xpOutputFormat, Boolean) As Stream
[C#] public Stream ExportToStream(DataSet, string[], xpOutputFormat, bool);

Exports DataSet  into the stream using the specified list of tables with the columns and xpOutputFormat format value.

[Visual Basic] Overloads Public Function ExportToStream(DataSet, ExportTable(), xpOutputFormat, Boolean) As Stream
[C#] public Stream ExportToStream(DataSet, ExportTable[], xpOutputFormat, bool);

Exports DataView into the stream using specified xpOutputFormat format value.

[Visual Basic] Overloads Public Function ExportToStream(DataView, xpOutputFormat, Boolean) As Stream
[C#] public Stream ExportToStream(DataView, xpOutputFormat, bool);

Exports DataView  into the stream using specified list of columns and xpOutputFormat format value.

[Visual Basic] Overloads Public Function ExportToStream(DataView, String(), xpOutputFormat, Boolean) As Stream
[C#] public Stream ExportToStream(DataView, string[], xpOutputFormat, bool);

Remarks

ExportToStream method returns result Stream using UTF8 encoding for the XML, CSV and HTML formats and binary output for the native Microsoft® Excel format.

In a case of UTF8 format, instance of Stream is constructed such that the preamble of the encoding is added to a stream. This means any Stream you create using XML, CSV or HTML format will have three byte order marks at its beginning.

Example

[Visual Basic, C#] The following example exports data from ADO.NET DataTable to different Microsoft® Excel file formats.

[C#] 
private void ExportDataTable(DataTable dataTableToExport, xpOutputFormat outputFormat) {

    VM.xPort.DS2XL xporter;
    MemoryStream exportStream;
    
    xporter = new VM.xPort.DS2XL();

    //Export data into XLS file format
    xporter.Export(dataTableToExport, "DataTableExportXls", xpOutputFormat.Excel8, true, true);

    //Export data into Excel 2007 XLSX file format
    xporter.Export(dataTableToExport, "DataTableExportXlsx", xpOutputFormat.XLSX, true, true);

    //Export data into CSV file format
    xporter.Export(dataTableToExport, "DataTableExportCsv", xpOutputFormat.CSV, true, true);

    //Export data into memory stream, but it could be any type of stream. We also can export
    //different file formats, not only Excel8
    exportStream = (MemoryStream)xporter.ExportToStream(dataTableToExport, xpOutputFormat.Excel8, true);

    //Do something with memory stream here
    //.....

    MessageBox.Show("Export completed.");
}
        
[Visual Basic] 
Private Sub ExportDataTable(ByVal dataTableToExport As DataTable)

    Dim xporter As VM.xPort.DS2XL
    Dim exportStream As MemoryStream

    xporter = New VM.xPort.DS2XL()

    'Export data into XLS file format
    xporter.Export(dataTableToExport, "DataTableExportXls", xpOutputFormat.Excel8, True, True)

    'Export data into Excel 2007 XLSX file format
    xporter.Export(dataTableToExport, "DataTableExportXlsx", xpOutputFormat.XLSX, True, True)

    'Export data into CSV file format
    xporter.Export(dataTableToExport, "DataTableExportCsv", xpOutputFormat.CSV, True, True)

    'Export data into memory stream, but it could be any type of stream. We also can export
    'different file formats, not only Excel8
    exportStream = _xporter.ExportToStream(dataTableToExport, xpOutputFormat.Excel8, True)

    'Do something with memory stream here
    '.....

    MessageBox.Show("Export completed.")

End Sub

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DS2XL Class | DS2XL Members | VM.xPort Namespace