使用OLEDB读取Excel文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用OLEDB读取Excel文件相关的知识,希望对你有一定的参考价值。
Doesn't do any validation, you would want to check if a
Dim ofD As New OpenFileDialog ofD.ShowDialog() If ofD.FileName.Length = 0 Then Exit Sub Dim cS As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & ofD.FileName & ";" & _ "Extended Properties=Excel 8.0;" Dim cN As New OleDb.OleDbConnection(cS) cN.Open() Dim dA As New OleDb.OleDbDataAdapter("SELECT * FROM [Sheet1$]", cN) Dim dSet As New DataSet dA.Fill (dSet) tvDB.Nodes.Clear() Dim dT As DataTable = dSet.Tables(0) Dim nParent As TreeNode For iCol As Integer = 0 To dT.Columns.Count - 1 nParent = tvDB.Nodes.Add(dT.Columns(iCol).ColumnName) For iRow As Integer = 0 To dT.Rows.Count - 1 nParent.Nodes.Add (dT.Rows(iRow).Item(iCol)) Next nParent.Expand() Next dA.Dispose() dSet.Dispose() cN.Dispose()
以上是关于使用OLEDB读取Excel文件的主要内容,如果未能解决你的问题,请参考以下文章
使用 OleDB 读取 Excel 文件返回格式错误的 UPC 编号