Initial implementation of memory-efficient Excel writing for large documents#481
Initial implementation of memory-efficient Excel writing for large documents#481gamerover98 wants to merge 1 commit intodhatim:masterfrom
Conversation
|
Hi @gamerover98 , how can I test with multiple different values per row? This replicates the same value in all the columns: How can I append to that row different values? |
|
in 9adf2ae#diff-70d50d3cdef0a64c1a61b46213e78789bfd3f304132a741dcc93bb87afde5627R128 If I remember correctly, the So, to answer your question: for (int rowIndex = 0; rowIndex < ROWS; rowIndex++) {
worksheet.appendRow(column -> {
return switch (column) {
case 0 -> "first column";
case 1 -> "second column";
...
case n-th-column: -> "latest column";
default: ...
}
});
} |
|
Thank you.. we already tested with some lambda functions and it works! Did you tried to apply some styles? Merging cells? |
Nope, this pull request is only meant to demonstrate that it is possible to do better than what Fastexcel currently offers. However, if I remember correctly, I left comments in the source to point out the lack of decorative features for the cells. |
|
We migrate to another library (poi-streaming) for writing, that works well for our purpose. |
|
This is already supported in the writer for some time now, as demonstrated in this e2e test: fastexcel/e2e/src/test/java/org/dhatim/fastexcel/MemoryUsageE2E.java Lines 43 to 57 in 4a1a60c Though I get that the API (need to call |
I have implemented an initial version that does not use memory to write a document. This solution is useful in cases where it’s necessary to create large Excel documents sequentially, meaning there’s no need for a second manipulation of the cells already added to the document.
The issue is described here: #480
Currently, this code only allows text to be written into a cell, and there is no functionality yet for changing its style. I would also like to point out that, due to the rush in which this modification was made, you should see this pull request not as a final change but as a way to demonstrate that even more can be achieved with Fastexcel!
You can compare the memory usage difference using VisualVM with the images from the issue:
Memory usage:

Memory Profiling:

The difference is remarkable, isn’t it? You can now create huge files without wasting memory!
Here’s the code used for the tests:
Lastly, I’d like to mention that test cases haven’t been added due to the nature of this pull request. If this approach moves forward, they will be included.
Thank you all <3