我想將我的 Excel .xlsx 檔案匯入到 vb.net 中的資料表中,以便以后處理資料。我的名為 Data.xlsx 的 Excel 檔案如下所示:
| 參考 | 日期 | 相關數字 | 評論 |
|---|---|---|---|
| 2022-A34 | 24.01.2022 | 738/3784 | 已選中 |
| 2022-A36 | 28.01.2022 | 7/3, 8733/28373,938/24755 |
并嘗試在這里使用 Ciarán 給出的代碼:
我在這里遺漏了什么還是我的方法完全錯誤?
uj5u.com熱心網友回復:
這
While oleExcelReader.Read
End While
將讓您處理回圈內的每一行。如果您想單獨讀取和處理每一行的每個欄位,例如使用oleExcelReader.GetString(0)等,這很好。
如果您只想閱讀整個表格,一種方法是:
...
dtTablesList.Clear()
dtTablesList.Dispose()
Dim dt As DataTable
If sSheetName <> "" Then
oleExcelCommand = oleExcelConnection.CreateCommand()
oleExcelCommand.CommandText = "Select * From [" & sSheetName & "]"
oleExcelCommand.CommandType = CommandType.Text
Using da As New OleDb.OleDbDataAdapter(oleExcelCommand)
dt = New DataTable
da.Fill(dt)
End Using
End If
oleExcelConnection.Close()
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/463821.html
