我想构建一个应用程序,它将读取一个excel文件(.xlsx,.xls)。不幸的是,OleDbDataAdapter.Fill()的性能出奇的糟糕。我花了2分钟时间从文件中读取一条记录。 257MB 为什么OleDbDataAdapter.Fill()非常慢?
代码我目前使用的读取文件
- 尺寸:有关文件
更多信息
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;
您的帮助将会是不胜感激!
谢谢!
这里提供了一些替代方案:http://security.china.alibaba.com/questions/15828/reading-excel-files-from-c-sharp正如@ semao指出的那样,使用Excel作为数据库的巨大数据集并不是非常高效的解决方案。例如在XLSX文件的情况下,文件必须解压缩,加载到内存中,编入索引,然后才能查询它。它不适合快速随机访问的文件格式 – xmojmr