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))


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM