我正在尝试构建一个将读取 excel 文件(.xlsx、.xls)的应用程序。不幸的是,OleDbDataAdapter.Fill() 的性能非常糟糕。我最多需要 2 分钟才能从文件中读取一条记录。
有关该文件的更多信息:
- 大小 - 257MB
- 列 - 104
- 行 - 1 000 000
我目前用来读取文件的代码:
string conStr = string.Empty;
string strQuery = string.Empty;
switch (extension)
{
case ".xls": //Excel 97-03
conStr = @"Provider=Microsoft.Jet.OleDb.12.0;Data Source=" + file_source + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1;';";
strQuery = "SELECT " + col_no + " * FROM [" + workbook + "] ";
break;
case ".xlsx": //Excel 07
//connection string to connect to the xlsx file
conStr = @"Provider=Microsoft.Ace.OleDb.12.0;Data Source=" + file_source + ";Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1;';";
strQuery = "SELECT " + col_no + " * FROM [" + workbook + "] ";
break;
}
DataTable tbl = new DataTable();
OleDbDataAdapter ada = new OleDbDataAdapter(strQuery, conStr);
ada.Fill(tbl);
ada.Dispose();
return tbl;
您的帮助将不胜感激!
谢谢!