Hi,
To generate an xlsx file of only 70MB memory usage is more than 1.5GB of RAM memory.
And each time the operation is performed, this memory usage increases.
To be able to perform the operation again, it is necessary to close the application and open it again. Otherwise performance drops dramatically.
If the writing lines of the sheet (sheet1.PutString / sheet1.PutNumber) are commented out the app always uses about 270MB of RAM memory.
I'm using a computer with a few GB of RAM, but this app won't work on a computer with low RAM.
I thought about saving the file a few times instead of saving it just once. But it doesn't seem that even after saving the memory is not freed.
Every time the PUT functions (sheet1.PutString / sheet1.PutNumber) access the sheet, the RAM usage increases. ?
Source: https://user.poi.apache.narkive.com...it-uses-too-ram-is-it-a-limit-of-your-library
Source: https://stackoverflow.com/questions/7274076/writing-a-large-resultset-to-an-excel-file-using-poi
Is there any example of generating the xlsx file using the streaming API?
To generate an xlsx file of only 70MB memory usage is more than 1.5GB of RAM memory.
And each time the operation is performed, this memory usage increases.
To be able to perform the operation again, it is necessary to close the application and open it again. Otherwise performance drops dramatically.
If the writing lines of the sheet (sheet1.PutString / sheet1.PutNumber) are commented out the app always uses about 270MB of RAM memory.
I'm using a computer with a few GB of RAM, but this app won't work on a computer with low RAM.
I thought about saving the file a few times instead of saving it just once. But it doesn't seem that even after saving the memory is not freed.
Every time the PUT functions (sheet1.PutString / sheet1.PutNumber) access the sheet, the RAM usage increases. ?
XSSF does use a lot of memory to construct an in memory representation of the
Excel worksheet. This question has been asked a number of times on the list
and there is a solution available. If you are limited for memory, then may I
suggest that you take a look at the streaming api - SXSSF.
Source: https://user.poi.apache.narkive.com...it-uses-too-ram-is-it-a-limit-of-your-library
Using SXSSF poi 3.8
B4X:
package example;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class SXSSFexample {
public static void main(String[] args) throws Throwable {
FileInputStream inputStream = new FileInputStream("mytemplate.xlsx");
XSSFWorkbook wb_template = new XSSFWorkbook(inputStream);
inputStream.close();
SXSSFWorkbook wb = new SXSSFWorkbook(wb_template);
wb.setCompressTempFiles(true);
SXSSFSheet sh = (SXSSFSheet) wb.getSheetAt(0);
sh.setRandomAccessWindowSize(100);// keep 100 rows in memory, exceeding rows will be flushed to disk
for(int rownum = 4; rownum < 100000; rownum++){
Row row = sh.createRow(rownum);
for(int cellnum = 0; cellnum < 10; cellnum++){
Cell cell = row.createCell(cellnum);
String address = new CellReference(cell).formatAsString();
cell.setCellValue(address);
}
}
FileOutputStream out = new FileOutputStream("tempsxssf.xlsx");
wb.write(out);
out.close();
}
}
Source: https://stackoverflow.com/questions/7274076/writing-a-large-resultset-to-an-excel-file-using-poi
Is there any example of generating the xlsx file using the streaming API?