0

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.

Aethan
  • 1,986
  • 2
  • 18
  • 25

2 Answers2

2

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

Community
  • 1
  • 1
Ernie S
  • 13,902
  • 4
  • 52
  • 79
  • Sadly, I can only compile to x86... Good thing I already started with a workaround. Thanks anyway! – Aethan Jan 18 '16 at 00:46
  • For future usage, can you suggest any libraries that I can use for large files? Tried ClosedXML, still no luck. I used EPPlus because it is recommended by many and is user-friendly, but most of my work involves manipulating large Excel files. Thanks again! – Aethan Jan 19 '16 at 01:33
  • @Aethlen The free all have their issues (even the paid ones do too). See if this helps (I cannot recommend anything specific to your situation I am afraid): http://stackoverflow.com/questions/444522/import-and-export-excel-what-is-the-best-library?rq=1 – Ernie S Jan 19 '16 at 02:14
  • I guess I'll have to install Excel on our server then. Thanks anyways! – Aethan Jan 19 '16 at 02:31
  • What about if my data hit 64-bit RAM limit? – Moshi Aug 28 '18 at 05:59
0

Essential XlsIO is an option for loading large Excel files using .NET.

The whole suite of controls is available for free (commercial applications also) through the community license program if you qualify (less than 1 million US Dollars in revenue). The community license is the full product with no limitations or watermarks.

Note: I work for Syncfusion.

Davis Jebaraj
  • 403
  • 6
  • 10