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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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
Method 2
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0