简体   繁体   中英

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.

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM