How to prevent GetOleDbSchemaTable from returning duplicate sheet names from Excel workbook

Posted by Richard Bysouth on Stack Overflow See other posts from Stack Overflow or by Richard Bysouth
Published on 2010-05-05T11:45:44Z Indexed on 2010/05/05 11:48 UTC
Read the original article Hit count: 379

Filed under:
|
|

Hi

I have a function to return a DataView containing info on sheets in an Excel Workbook, as follows:

    Public Function GetSchemaInfo() As DataView

        Using connection As New OleDbConnection(GetConnectionString())
            connection.Open()

            Dim schemaTable As DataTable = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)

            connection.Close()

            Return New DataView(schemaTable)
        End Using

    End Function

This works fine except that if the workbook has linked data (i.e. pulls its data from another workbook), duplicate sheet names are returned.

For example, Workbook1 has a single worksheet, Sheet1. I get 2 rows in the DataView, with the TABLE_NAME field being "Sheet1$" and "Sheet1$_".

OK, I could use a RowFilter, but wondered whether there was a better way or why this extra row is returned?

thanks

Richard

© Stack Overflow or respective owner

Related posts about .NET

Related posts about excel