I’m trying to read an excel file that’s more thank 500k rows and 100 columns
as below
try {
Workbook book = new Workbook(xlsxFile.getAbsolutePath());
long st = System.currentTimeMillis();
book.getWorksheets().forEach(sheet -> {
File f = new File(“C:\Users\Aspose\” + ((Worksheet) sheet).getName() + “.txt”);
LOGGER.info(" FILE ->"+f.getAbsolutePath());
LOGGER.info(" SHEET ->"+((Worksheet) sheet).getName());
OutputStream os;
try {
os = (OutputStream) new FileOutputStream(f);
String encoding = “UTF8”;
OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
BufferedWriter bw = new BufferedWriter(osw);
Cells cells = ((Worksheet) sheet).getCells();
for (int row = 1; row <= cells.getMaxDataRow(); row++) {
StringBuilder strb = new StringBuilder();
for (int col = 0; col <= cells.getMaxDataColumn(); col++) {
strb.append((cells.get(row, col)).getValue());
strb.append("|");
}
bw.write(strb.toString());
bw.newLine();
}
bw.flush();
bw.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
});
long et = System.currentTimeMillis();
System.out.println(“Time Taken =” + (et - st));
} catch (Exception e) {
e.printStackTrace();
}
But its taking a lot of time to write a single row. a hell lot of time any other means or ways toread cell values and write to txt as pipeline seperated of an excel of500k+ rows.
The way its said in documents of xlsx to csv conversion it throws error as below as below,
14:17:20.132 [main] INFO AppMain - Loaded File -->C:\Users\Documents\300kexcel\sample.xlsx
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at com.aspose.cells.b.a.d.zh.b(Unknown Source)
at com.aspose.cells.b.a.d.zh.c(Unknown Source)
at com.aspose.cells.b.a.d.zh.b(Unknown Source)
at com.aspose.cells.b.a.d.zo.a(Unknown Source)
at com.aspose.cells.b.a.d.zo.a(Unknown Source)
at com.aspose.cells.zun.a(Unknown Source)
at com.aspose.cells.zun.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)