[英]How to increase Excel file reading speed if we use ExcelDataReader package?
I'm using ExcelDataReader for reading excel files (*.xlsx, *.xlsb, *.xls) and i'm trying to speed up the process of it.我正在使用 ExcelDataReader 来读取 excel 文件(*.xlsx、*.xlsb、*.xls),我正在尝试加快它的进程。
It works perfectly fine, but it takes time to display rows.它工作得很好,但显示行需要时间。 To note : I'm using a big excel file (14000 rows) and I just want to display the first five.
注意:我正在使用一个大的 excel 文件(14000 行),我只想显示前五个。
Here my progress :这是我的进步:
FileInfo fileInfo = new FileInfo(filePath);
if (fileInfo.Extension.ToLower().Contains(".xls"))
{
using (FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read))
{
using (var excelReader = ExcelReaderFactory.CreateReader(stream))
{
DataTable result = excelReader.AsDataSet().Tables[0];
for (int i = 0; i < 6; i++)
{
resultList.Add(string.Join(",", result.Rows[i].ItemArray).Split(',').ToArray());
}
excelReader.Close();
}
}
}
return resultList;
Don't use reader.AsDataSet()
- that will load the whole file into memory which has a big overhead.不要使用
reader.AsDataSet()
- 这会将整个文件加载到内存中,这会带来很大的开销。 Instead use the reader APIs like reader.Read()
to read one row at a time, and reader.GetValue()
to get the values on the current row.而是使用
reader.Read()
等读取器 API reader.Read()
读取一行,并使用reader.GetValue()
获取当前行上的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.