问题
I am trying to load and parse a xls file which is of 11mb and I am using WorkbookFactory.create(myFile)) to load it.But I am not able to load this file and parse it.Can anyone help me out of this this the code I am using in my program ,
public class LargeExcelManager {
private Workbook wb ;
public Workbook getWb() {
return wb;
}
public void setWb(Workbook wb) {
this.wb = wb;
}
public LargeExcelManager(String fileName)throws Exception {
openWorkbook(fileName);
}
private void openWorkbook(String fileName)throws Exception {
try {
System.out.println("Can be added now");
File myFile = new File(fileName);
this.setWb(WorkbookFactory.create(myFile)); // Here i am trying to set the large file
} catch (Exception e) {
e.printStackTrace();
}
}
}
Here I am trying to get some information out of it ,
@Override
public List<String> start() {
ActivityLauncher.logConsoleMsg("Activity number " + activityId + " started");
List<String> result = new ArrayList<String>();
Workbook wb = excelManager.getWb();
for (int i=0; i<wb.getNumberOfSheets(); i++) {
if(wb.getSheetName(i).contains("Loan information")) {
//sheetNames.add( wb.getSheetName(i) );
result.addAll(processSheet(wb.getSheetAt(i)));
}
}
ActivityLauncher.logConsoleMsg("Activity number " + activityId + " completed");
return result;
}
But it is failing me every time I am trying to load it. Can anyone help me somehow?
I am getting this error using POI 3.16
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at
org.apache.xmlbeans.impl.store.Cur$CurLoadContext.attr(Cur.java:3044)
来源:https://stackoverflow.com/questions/48772021/how-to-solve-the-java-heap-space-error-while-loading-the-large-xls-file-using-po