I'm using this groovy code for convert xlsx to csv, but I am receiving this error:
java.lang.OutOfMemoryError: GC overhead limit exceeded
I don't know how I could solve this. My code works for a small Excel file of 2mb, but for large excel of more than 20mb it doesn't work. I don't know how set a limit of heap size in groovy.
PLease help me
this is my code
@Grapes(
@Grab(group='org.apache.poi', module='poi-ooxml', version='3.9')
)
import org.apache.poi.xssf.usermodel.XSSFCell;
@Grapes(
@Grab(group='org.apache.poi', module='poi-ooxml', version='3.9')
)
@Grapes(
@Grab(group='org.apache.poi', module='poi', version='3.9')
)
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.PrintWriter;
import java.io.File;
public static void echoAsCSV(Sheet sheet) {
Row row = null;
for (int i = 0; i < sheet.getLastRowNum(); i++) {
row = sheet.getRow(i);
for (int j = 0; j < row.getLastCellNum(); j++) {
System.out.print("\"" + row.getCell(j) + "\";");
}
System.out.println();
}
}
def makeThumbnailx2() {
/**
* @param args the command line arguments
*/
InputStream inp = null;
try {
inp = new FileInputStream("venrx.xlsx");
Workbook wb = WorkbookFactory.create(inp);
for(int i=0;i<wb.getNumberOfSheets();i++) {
System.out.println(wb.getSheetAt(i).getSheetName());
echoAsCSV(wb.getSheetAt(i));
}
} catch (InvalidFormatException ex) {
Logger.getLogger(ExcelReading.class.getName()).log(Level.SEVERE, null, ex);
} catch (FileNotFoundException ex) {
Logger.getLogger(ExcelReading.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(ExcelReading.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
inp.close();
} catch (IOException ex) {
Logger.getLogger(ExcelReading.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
makeThumbnailx2()