excel-streaming-reader
excel-streaming-reader copied to clipboard
Same sheet iterator not moving to first row
Hi,
In my requirement i'm processing same sheet twice in a function second the iterator starting from last position where it ends in first iteration. how can i reset that. please help me out
From documentation: You may access cells randomly within a row, as the entire row is cached. However, there is no way to randomly access rows. As this is a streaming implementation, only a small number of rows are kept in memory at any given time.
@alusbars actually the problem for the sheet is its starting iteration from where we left in previous function. But i want to iterate from the starting row again
No other way than you need to initialize workbook again.
@alusbars then it will take lot of memory bro...
Streaming approach is not memory consumable by definition in terms of RAM. You won't have OutOfMemoryError what is more important, but of course you should consider your hard disk storage. But actually apache poi should manage temporary file under the hood.
Yeah, this isn't explicitly possible with this library. The stream is consumed in one direction and there is no way to reverse it. This is due to the nature of the underlying XML streaming parser that POI uses.
If you need this kind of behavior, you'll need to do your own caching of rows. For instance, you can read a set of rows into a List and pass that around your functions. However, if you need to go to arbitrary rows in the sheet, you'll have to use vanilla POI.
Any possibility to reset the iterator explicitly? clearing the row cache etc
@monitorjbl
Yeah, this isn't explicitly possible with this library. The stream is consumed in one direction and there is no way to reverse it. This is due to the nature of the underlying XML streaming parser that POI uses.
If you need this kind of behavior, you'll need to do your own caching of rows. For instance, you can read a set of rows into a List and pass that around your functions. However, if you need to go to arbitrary rows in the sheet, you'll have to use vanilla POI.
Is this still true? I am looking for a way to go through the sheets again.
This project seems to be inactive. I've fixed/implemented this in pjfanning/excel-streaming-reader (#109), the most active fork that is maintained by a maintainer of Apache POI