excel-streaming-reader icon indicating copy to clipboard operation
excel-streaming-reader copied to clipboard

Same sheet iterator not moving to first row

Open ramesh586 opened this issue 7 years ago • 9 comments

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

ramesh586 avatar May 26 '17 11:05 ramesh586

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 avatar May 26 '17 11:05 alusbars

@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

ramesh586 avatar May 26 '17 11:05 ramesh586

No other way than you need to initialize workbook again.

alusbars avatar May 26 '17 11:05 alusbars

@alusbars then it will take lot of memory bro...

ramesh586 avatar May 26 '17 11:05 ramesh586

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.

alusbars avatar May 26 '17 12:05 alusbars

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.

monitorjbl avatar May 26 '17 15:05 monitorjbl

Any possibility to reset the iterator explicitly? clearing the row cache etc

ankurbajaj9 avatar Dec 12 '18 12:12 ankurbajaj9

@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.

psehrawa avatar Oct 14 '21 00:10 psehrawa

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

daniel-shuy avatar Apr 14 '22 14:04 daniel-shuy