VB.Net 读取Excel

 

1、Xlsx格式

Dim tmpdtb As DataTable

Dim connectionString As String ' Used to store the connection string
Dim customerList As New DataSet ' Used to store the temp records readed from the Excel file
Dim excelData As OleDb.OleDbDataAdapter

‘filestrB为文件位置
connectionString = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0;HDR=YES"";", filestrB)
excelData = New OleDb.OleDbDataAdapter("SELECT * FROM [" & tbname & "$]", connectionString)
excelData.TableMappings.Add("Sheet1", "ImportCustomer")
excelData.Fill(customerList)
' DataGridView1.DataSource = customerList.Tables.Item(0)
tmpdtb = customerList.Tables.Item(0)
sumrowcount = tmpdtb.Rows.Count
' MsgBox(dtb.Rows(3).Item(1))

上一篇:vb学习


下一篇:VB模拟键盘攻略