使用oledb连接检索每个单元格的Excel数据 [英] retrieve excel data by each cell using oledb connection

查看:113
本文介绍了使用oledb连接检索每个单元格的Excel数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨....我有一个代码,用于从excel检索每个数据以更新dbf文件。我使用Microsoft.Office.Interop.Excel读取每个列范围的数据。

现在我想用oledb更改连接excel ..

如何检索每列的数据并将其设置为变量?

这是我的代码,用于Microsoft.Office.Interop.Excel。

hi.... i have a code for retrieve each data from excel to update dbf file. i use Microsoft.Office.Interop.Excel for read the data each range of column.
now i want to change the connection excel using oledb..
how can i retrieve data of each column and set it into a variable?
here is my code for Microsoft.Office.Interop.Excel.

xlApp = New Excel.Application

xlWorkBook = xlApp.Workbooks.Open(xlsName)
xlWorkSheet = xlWorkBook.Worksheets("sheet1")
xlRange = xlWorkSheet.UsedRange
endrow = xlRange.Rows.Count

For rCnt = 3 To endrow

    Empno = xlRange.Cells(rCnt, 1).Value
    totalhrs = xlRange.Cells(rCnt, 3).Value
    latehr = xlRange.Cells(rCnt, 4).Value

 Next

xlWorkBook.Close()
xlApp.Quit()



这是我的oledb连接。在连接之后,我真的不知道我该怎么做才能获得数据。请帮助我...我希望codeproject中有人可以帮助我。


this is my oledb connection. after the connection,i really dont have an idea what should i do to get the data. please help me...i hope someone in codeproject can help me.

  Dim xlsConnect As System.Data.OleDb.OleDbConnection
  Dim DtSet As System.Data.DataSet
  Dim MyCommand As System.Data.OleDb.OleDbDataAdapter

Try

      If (Path.GetExtension(xlsName) = ".xls") Then
          xlsConnect = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & xlsName & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=2""")
      ElseIf (Path.GetExtension(xlsName) = ".xlsx") Then
          xlsConnect = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & xlsName & ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';")
      End If
      MyCommand = New System.Data.OleDb.OleDbDataAdapter("Select * from [Sheet1$]", xlsConnect)
      'looping data should be here

      xlsConnect.Close()
  Catch ex As Exception
      MsgBox(ex.ToString)
  End Try

推荐答案

,xlsConnect)
' 循环数据应该在这里

xlsConnect.Close()
< span class =code-keyword> Catch ex As 异常
MsgBox(ex.ToString)
结束 尝试
", xlsConnect) 'looping data should be here xlsConnect.Close() Catch ex As Exception MsgBox(ex.ToString) End Try


看看在这里:

使用VB.NET中的OLEDB从Excel读取数据 [ ^ ]

使用OLEDB读取和编写Excel [< a href =http://www.codeproject.com/Articles/8500/Reading-and-Writing-Excel-using-OLEDB\"target =_ blanktitle =New Window> ^ ]

http://www.connectionstrings.com/excel/ [ ^ ]

使用MS Excel(xls / xlsx)使用MDAC和Oledb [ ^ ]
Have a look here:
Read Data from Excel using OLEDB in VB.NET[^]
Reading and Writing Excel using OLEDB[^]
http://www.connectionstrings.com/excel/[^]
Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^]


这篇关于使用oledb连接检索每个单元格的Excel数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆