Search code examples
asp.netexcelepplus

EPPlus 'System.OutOfMemoryException'


I am trying to open a 38MB Excel File using EPPlus v4.0, I am able to pass it to the ExcelPackage variable but when I'm trying to get the workbook from that variable, it causes me a 'System.OutOfMemoryException'.

Here's my code:

    Dim temppath = Path.GetTempPath()
    Dim filenamestr As String = Path.GetFileNameWithoutExtension(Path.GetRandomFileName())

    Dim tempfilename As String = Path.Combine(temppath, filenamestr + ".xlsx")

    fileUploadExcel.SaveAs(tempfilename) 

    Dim XLPack = New ExcelPackage(File.OpenRead(tempfilename))
    GC.Collect()
    If File.Exists(tempfilename) Then
        File.Delete(tempfilename)
    End If

    Dim xlWorkbook As ExcelWorkbook = XLPack.Workbook 'the error shows here

I'm stuck. Any help would really be appreciated. Thanks in advance.


Solution

  • You are probably hitting the ram limit as that is a big file. If you have the option to compile to 64 bit you might be able to solve the problem:

    https://stackoverflow.com/a/29912563/1324284

    But if you can only compile to x86 there is not a whole lot you can do with epplus. You will have to either use a different library or build the XML files for excel yourself:

    https://stackoverflow.com/a/26802061/1324284