I wish to read from a closed excel file, a few years ago I found a website using ADO and it worked
but now I cannot find this website I have tried over 100 with no success

please help
Ernest

Recommended Answers

All 2 Replies

Question: What do you mean by "closed"?

There are so many vb.net "read an excel file" examples on the web now that I have to guess why you added this word.

Are you going to read a password protected Excel file?

If yes, you can try Free Spire.XLS for .NET (available on NuGet) to load an encrypted document and then export data from a specified worksheet to datatable. The following is the code snippet for your reference.

Imports System.Data
Imports Spire.Xls

Namespace ExportDataToDatatable
    Class Program
        Shared  Sub Main(ByVal args() As String)
            Dim workbook As Workbook =  New Workbook() 
            workbook.OpenPassword = "your password"
            workbook.LoadFromFile("‪C:\Users\Administrator\Desktop\DataSource.xlsx")
            Dim sheet As Worksheet =  workbook.Worksheets(0) 
            Dim dataTable As DataTable =  sheet.ExportDataTable() 
        End Sub
    End Class
End Namespace

Or, you can read the value of a specific cell using the following code snippet:

Imports Spire.Xls

Namespace ReadCellValue
    Class Program
        Shared  Sub Main(ByVal args() As String)
            Dim workbook As Workbook =  New Workbook() 
            workbook.OpenPassword = "your password"
            workbook.LoadFromFile("‪C:\Users\Administrator\Desktop\DataSource.xlsx")
            Dim sheet As Worksheet =  workbook.Worksheets(0) 
            Dim cellValue As String =  sheet.Range("A1").Value 
        End Sub
    End Class
End Namespace
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.