我想将一个大文件从excel文件加载到vb.net datagridview,但是当我运行该程序时,要花很长时间将所有数据加载到datagridview中,这是我导入excel文件的一些代码。
Public Sub sheetArray2(ByVal filePath As TextBox, ByVal dtg As DataGridView)
conn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & filePath.Text & ";Extended Properties=Excel 12.0;")
conn.Open()
dt = New DataTable
dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
listSheet = New List(Of String)
For Each drSheet In dt.Rows
listSheet.Add(drSheet("TABLE_NAME").ToString)
Next
dt1 = New DataTable
For i As Integer = 0 To listSheet.Count - 1
da = New OleDb.OleDbDataAdapter("select *from [" & listSheet.Item(i) & "]", conn)
da.Fill(dt1)
Dim ar(dt1.Columns.Count, dt1.Rows.Count)
For x As Integer = 0 To dt1.Rows.Count - 1
dtg.DataSource = dt1
For y As Integer = 0 To dt1.Columns.Count - 1
ar.SetValue(dt1.Rows(x).Item(y), y, x)
dtg.Item(y, x).Value = ar(y, x)
Next
Next
Next
conn.Close()
End Sub