EPPlus“ System.OutOfMemoryException” [英] EPPlus 'System.OutOfMemoryException'

查看:387
本文介绍了EPPlus“ System.OutOfMemoryException”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 EPPlus v4.0 打开38MB的Excel文件,我能够将其传递给 ExcelPackage 变量,但是当我尝试获取该变量的工作簿,它会导致我出现 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'.

这是我的代码:

    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.

推荐答案

您可能已经达到了内存限制,因为这是一个很大的文件。如果您可以选择编译为64位,则可以解决该问题:

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

但是如果只能编译到x86,就不会有很多东西您可以使用epplus。您将不得不使用其他库或为自己创建Excel的XML文件:

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

这篇关于EPPlus“ System.OutOfMemoryException”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆