[英]Is it possible to read part of worksheet of very large excel file (>500000 records) via closedXml?
Problem with opening a large EXCEL file. 打开大型EXCEL文件时出现问题。 For example, when I declare XLWorkbook, it's going to load ALL data to this object.
例如,当我声明XLWorkbook时,它会将所有数据加载到此对象。 I decided to read it partly, because, it's returned an error: outOfMemory.
我决定部分阅读它,因为它返回了一个错误:outOfMemory。 Is it possible to read part with range?
是否可以读取范围的部分? Is there any more methods?
还有其他方法吗?
Sample: 样品:
using ClosedXML.Excel;
public void FileOpen(string path)
{
var workBook = new XLWorkbook(path);
// . . .
}
You can use a good ole' OleDbAdapter
to select a given range of rows. 您可以使用好的
OleDbAdapter
来选择给定的行范围。 See an example below where I select the first 10,000 rows (from the sheet "Sheet1") and then later another set of 10,000 rows from an excel file : 请参阅下面的示例,其中我选择前10,000行(来自工作表“Sheet1”),然后选择另一组来自excel文件的10,000行:
DataSet excelDataSet = new DataSet();
using (OleDbConnection connection = new System.Data.OleDb.OleDbConnection(connectionString))
{
connection.Open();
OleDbDataAdapter cmd = new OleDbDataAdapter("select * from [Sheet1$1:10000]", connection);
cmd.Fill(excelDataSet);
...
OleDbDataAdapter cmd = new OleDbDataAdapter("select * from [Sheet1$10000:20000]", connection);
connection.Close();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.