Returns schema information from Microsoft® Excel source as indicated by ExcelClientSchemaType value.
[Visual Basic] Public Function GetExcelSchemaTable( _ ByVal schema As ExcelClientSchemaType ) As DataTable [C#] public DataTable GetExcelSchemaTable( ExcelClientSchemaType schema);
A DataTable containing the requested schema information.
Exception Type | Condition |
---|---|
InvalidOperationException | The ExcelConnection is closed. |
The schema table is returned as a DataTable that has format as specified by the the schema parameter.
[C#, Visual Basic] The following sample returns a list of spreadsheets inside of the Microsoft® Excel workbook.
[C#]
using VM.xPort.ExcelClient;
private void GetSpreadsheetNames()
{
ExcelConnection connection;
DataTable spreadsheets;
//Open connection to Excel file
connection = GetConnection("AuthorsInfo.xlsx", "xlsx", false);
//Query schema information about available spreadsheets inside of Excel file
spreadsheets = connection.GetExcelSchemaTable(ExcelConnection.ExcelClientSchemaType.Tables);
//Do something with the DataTable here
dgvXLS.DataSource = spreadsheets;
//Release all the opened resources
connection.Close();
connection.Dispose();
connection = null;
}
[Visual Basic]
Imports VM.xPort.ExcelClient
Private Sub GetSpreadsheetNames()
Dim connection As ExcelConnection
Dim spreadsheets As DataTable
'Open connection to Excel file
connection = GetConnection("AuthorsInfo.xlsx", "xlsx", False)
'Query schema information about available spreadsheets inside of Excel file
spreadsheets = connection.GetExcelSchemaTable(ExcelConnection.ExcelClientSchemaType.Tables)
'Do something with the DataTable here
dgvXLS.DataSource = spreadsheets
'Release all the opened resources
connection.Close()
connection.Dispose()
connection = Nothing
End Sub
Private Function GetConnection(ByVal filePath As String, ByVal format As String, ByVal hasHeader As Boolean) As ExcelConnection
'Sample code creates and opens connection to workbook file
Dim connection As ExcelConnection
'Open connection to the Excel file using provided connection values
connection = New ExcelConnection("Data Source=" & filePath & ";Format=" & format & ";HDR=" & hasHeader.ToString() & ";")
connection.Open()
Return connection
End Function
[C++, JScript] No example is available for C++ or JScript.
Supported in: 4.0, 3.5, 3.0, 2.0
VM.xPort.ExcelClient (in VM.xPort.ExcelClient.dll)
ExcelConnection Class | ExcelConnection Members | VM.xPort.ExcelClient Namespace