DS2XL Class Library  

DS2XL.Export Method (DataView, String(), String, xpOutputFormat, Boolean, Boolean)

Saves information from the specified columns in a DataView into the file on disk using one of the available export formats.

[Visual Basic]
Overloads Public Sub Export( _
   ByVal sourceDataView As DataView, _
   ByVal columns() As String, _
   ByVal fileName As String, _
   ByVal fileFormat As xpOutputFormat, _
   ByVal override As Boolean, _
   ByVal includeHeaders As Boolean)
[C#]
public void Export( _
   dataView sourceDataView,
   string columns[],
   string fileName,
   xpOutputFormat fileFormat,
   bool override,
   bool includeHeaders);

Parameters

sourceDataView
Source DataView , containing data to export into the file.
columns()
Array of DataColumn names, required to export.
fileName
Output file name of exported data.
fileFormat
One of the xpOutputFormat enumerated values, which specifies output format of the exported data.
override
Specifies if method may override file on a disk, if file with the same name already exists.
includeHeaders
Specifies if the output result file will contain columns names as headers for the exported columns.

Exceptions

Exception Type Condition
ColumnOutOfRangeException Raises if number of columns to export in a Columns() parameter exceeds maximum allowed number of columns. For Microsoft® Excel there is a limit of 256 columns. There is no limit for the number of columns in a CSV or HTML file formats.
FileAlreadyExistsException Raises if specified output Microsoft® Excel file already exists and Override parameter of the Export method is set to False.
InvalidColumnListException Raises if application specified invalid list of column names in a Columns() parameter.
InvalidColumnNameException Raises if DataView does not contain specified column name in a Columns() array of columns.
InvalidDataSourceException Raises if source DataView is Null (Nothing in Visual Basic) .
InvalidFileFormatException Raises if FileFormat parameter contains incorrect value of the output file format.
InvalidTableNameException Raises if DataView does not contain any table name in a TableName property of the underlying DataTable or table name is longer than maximum allowed length. Export method uses TableName property of DataTable to name Excel spreadsheets. Microsoft® Excel has limit on a spreadsheet name, which is a 31 character.
RowOutOfRangeException Raises if DataView contains number of rows, which exceeds maximum number of rows allowed in a Microsoft® Excel spreadsheet. Microsoft® Excel has a limit of 65536 rows in a one spreadsheet. There is no limit for the number of rows in a CSV or HTML file formats.
TableOutOfRangeException Occurred if DataView produces output that exceeds maximum number of allowed spreadsheets in an Excel workbook. DataView could produce multiple spreadsheets in a case of exporting data using ChunkSize and SplitIntoChunks properties that allow to export DataView into multiple spreadsheets. Microsoft® Excel has a limit of 255 spreadsheets in a workbook.
xPortApplicationException Base exception class for all the exceptions, declared in an xPort.

Remarks

Export method of DS2XL class allows to save DataView into native Microsoft® Excel binary file format or other supported file formats. Specifying list of the DataColumn names as an array of Columns() parameter, Export method saves only specified columns into output file. Using one of the enumerated values of the xpOutputFormat developer could specify which output format to use to store the data. If Override parameter set to True and specified output file name already exists on a disk, then Export method overrides existing file without any prompt.

Example

[Visual Basic, C#] The following example exports DataView to different Microsoft® Excel formats.

[C#] 
private void ExportDataTable(DataView dataViewToExport, 
    xpOutputFormat outputFormat, 
    string[] columnsToExport) {

    VM.xPort.DS2XL xporter;

    xporter = new VM.xPort.DS2XL();

    //Export data 
    xporter.Export(dataViewToExport, columnsToExport, "DataTableExport", outputFormat, true, true);

    MessageBox.Show("Export completed.");
}

[Visual Basic] 
Private Sub ExportDataTable(ByVal dataViewToExport As DataView, _
    ByVal outputFormat As xpOutputFormat, _
    ByVal columnsToExport() As String)

    Dim xporter As VM.xPort.DS2XL

    xporter = New VM.xPort.DS2XL()

    'Export data 
    xporter.Export(dataViewToExport, columnsToExport, "DataTableExportXls", outputFormat, True, True)

    MessageBox.Show("Export completed.")

End Sub

Requirements

Platforms: Windows Server 2008 family, Windows Server 2003 family, Windows 2000 family, Windows Vista family, Windows XP family

See Also

DS2XL Class | DS2XL.Export Method | DS2XL Members | VM.xPort Namespace