tags:

views:

153

answers:

3

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.

+3  A: 

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 rows 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
CResults
A: 

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.

lee-m
A: 

Sorry can explain what does the rs stands for and how do u declare or reference adOpenDynamic ?

Jason