我正在使用 Grails 2.4.4 并尝试使用“apache poi”插件上传 .xlsx 文件,但是当文件大小约为 8 MB 时,我收到 JAVA 堆大小异常。
我的 Controller 具有以下操作和方法:-
def uploadForm() {
String fileName = "D:\\File.xlsx"
Map excelSheetMap = process(fileName)
}
Map process(String fileName) {
ExcelBuilder excelBuilder = new ExcelBuilder(fileName)
//Getting JAVA Heap Size exception here when I am trying to create an object
//of ExcelBuilder with the file
}
ExcelBuilder.groovy 类文件看起来像这样
class ExcelBuilder {
Workbook workbook
ExcelBuilder(String fileName) {
new File(fileName).withInputStream { is ->
workbook = new XSSFWorkbook(is)
}
}
}
我也尝试过使用 grails-excel-import 插件,但我遇到了同样的异常。
有人可以建议如何在 grails 中导入大尺寸的 excel 文件。提前致谢。
最佳答案
Poi 确实有很高的内存占用。请参见:
http://poi.apache.org/spreadsheet/index.html
你可以试试 SXSSF。 SXSSF 是 XSSF 的 API 兼容流扩展,可在必须生成非常大的电子表格且堆空间有限时使用。
关于grails - OutOfMemoryError : Java heap space to upload 8 MB size file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31069185/