Mark
Mark

Reputation: 227

How to read excel file in vb.net 2003

Can anyone help me on how can I read the excel file using vb.net 2003?

The first thing to do is to browse the excel file in my vb.net program then read the content of excel file and display the value of excel content in listview.

Upvotes: 1

Views: 2139

Answers (2)

CResults
CResults

Reputation: 5105

The quickest and easiest way to read an Excel file in vb.net is to use the Jet database driver.

Set cnExcel = New ADODB.Connection
cnExcel.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
   "Data Source=" & MyFilename & ";" & _
   "Extended Properties=""Excel 8.0;IMEX=1;HDR=NO"""

Then read through it. Here I display columns 0 and 1

rs.Open "select * from " & MySheetName, cnExcel, adOpenDynamic, adLockOptimistic
While Not rs.EOF
        debug.print rs(0) 
        debug.print rs(1) 
        rs.MoveNext
Wend

Upvotes: 4

lee-m
lee-m

Reputation: 2267

An alternate way to query for data inside an Excel spreadshet is to use the interop assemblies Microsoft has released for interacting with Office apps from .NET (2003 versions here).

Using these interops is a bit more involved and you need to be careful about properly releasing the Excel objects you create to avoid leaks, but does give you more access to all the information contained with the workbook you're opening - you can see a short intro for using these assemblies here.

Upvotes: 0

Related Questions