ExcelConnection Class Library  

ExcelConnection.GetExcelSchemaTable Method

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

Parameters

schema
One of the ExcelClientSchemaType values that specifies the schema table to return.

Return Value

A DataTable containing the requested schema information.

Exceptions

Exception Type Condition
InvalidOperationException The ExcelConnection is closed.

Remarks

The schema table is returned as a DataTable that has format as specified by the the schema parameter.

Example

[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.

.NET Framework

Supported in: 4.0, 3.5, 3.0, 2.0

Assembly: 

VM.xPort.ExcelClient (in VM.xPort.ExcelClient.dll)

See Also

ExcelConnection Class | ExcelConnection Members | VM.xPort.ExcelClient Namespace