我有一个带有两个选项卡的 Excel 表。
一个约为 700 k,另一个约为 25k。问题是当我加载文件时,我的内存被耗尽并且崩溃了!如何处理大文件,因为有些文件甚至可能超过一百万行。
这是我正在使用的当前代码:
OleDbConnection cnn = new OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + fileName + "';Extended Properties=Excel 12.0;");
cnn.Open();
string qry = "SELECT * FROM [Detail$]";
OleDbDataAdapter odp = new OleDbDataAdapter(qry, cnn);
odp.Fill(detailTable);
DataSet tmp = new DataSet();
if (detailTable.Rows.Count > 0)
{
Console.WriteLine("Total " + detailTable.Rows.Count + " Detail rows Loaded");
// MessageBox.Show("Input Sheet UPLOADED !");
}
qry = "SELECT * FROM [Gallery$]";
OleDbDataAdapter odp1 = new OleDbDataAdapter(qry, cnn);
odp1.Fill(galleryTable);
if (galleryTable.Rows.Count > 0)
{
Console.WriteLine("Total " + galleryTable.Rows.Count + " Gallery Numbers Loaded");
// MessageBox.Show("Input Sheet UPLOADED !");
}