System.OutofMemory Exception excel 1 GB数据

时间:2016-06-08 07:40:53

标签: c# excel

我在Server中有2个excel文件,每个文件大小为1GB。 我必须比较文件,并将结果发送到一个单独的表中。

我能够将一个excel文件读入数据表,当我即将读取另一个excel的数据时,我的内存异常。

file = new FileInfo(@"Remote Location" + strFileName);
bool hasHeader = true;

file.CopyTo(strPath, true);
file = null;
using (var pck = new OfficeOpenXml.ExcelPackage())
{
    using (FileStream stream = File.OpenRead(strPath))
    {
        pck.Load(stream);   //Getting issue out of memory for second excel file
        stream.Close();
        stream.Dispose();
    }
}

1 个答案:

答案 0 :(得分:4)

您处于32位进程可以处理的极限。确保您使用的是64位Windows,并确保以64位模式运行应用程序,右键单击Project-> Properties-> Build并从典型默认值“Any CPU”强制它到x64。

但是,对于您的问题可能有更好的解决方案,为什么不使用Excel ODBC driver将每个Excel工作表视为数据源?我的想法是效率会高得多。