我目前正在处理 Excel 中的大量数据,并且我想将混合数据类型上传到 VB.Net 中的 DataTable(每 30 列 70,000 行)。
我正在使用下一个代码来导入信息:
Public Function mc_ExcelTableToDataTable(ByRef ExcelApp As Excel.Application, _
ByVal SheetName As String, _
ByVal TableName As String, _
Optional ByVal FilePath As String = "", _
Optional ByVal SQLsentence As String = "") As DataTable
Dim vPath As String
Dim vCloseExcelWorkbook As Boolean = False
If ExcelApp.ActiveWorkbook IsNot Nothing Then
vPath = IIf(FilePath = "", ExcelApp.ActiveWorkbook.FullName, FilePath)
Else
vPath = FilePath
End If
If SQLsentence = "" And ExcelApp.ActiveWorkbook Is Nothing Then
vCloseExcelWorkbook = True
ExcelApp.Workbooks.Open(vPath)
End If
Dim vRange As String = ExcelApp.Sheets(SheetName).ListObjects(TableName).Range.AddressLocal
vRange = vRange.Replace("$", "")
Dim vCNNstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source= " & vPath & ";" & _
"Extended Properties=""Excel 8.0;HDR=YES;IMEX=1"""
Dim ExcelCNN As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(vCNNstring)
Dim vSQL As String = IIf(SQLsentence = "", _
"SELECT * FROM [" + SheetName + "$" & vRange & "]", _
SQLsentence)
Dim ExcelCMD As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(vSQL, ExcelCNN)
ExcelCNN.Open()
Dim ExcelDS As System.Data.DataSet = New DataSet
ExcelCMD.Fill(ExcelDS)
mc_ExcelTableToDataTable = ExcelDS.Tables(0).Copy
ExcelCMD = Nothing
ExcelCNN.Close()
ExcelDS.mc_Dispose()
If vCloseExcelWorkbook Then ExcelApp.ActiveWorkbook.Close(False)
GCcleaner()
End Function
但是,VB.Net 给我以下错误:
有人知道提供者ACE.OLEDB.12.0 的最大容量是多少?或者如何解决这个问题?
仅供参考,这是 SQL 选择语句:
SELECT * FROM [Workflow data$A1:AC70276]
值得一提的是,如果我将行数限制为 20000(SELECT * FROM [Workflow data$A1:AC20000]),则该过程可以正常工作!