Update README for iterators

This commit is contained in:
Adrien Loison 2015-07-20 23:24:43 -07:00
parent 15aab7902a
commit 2345a80784

View File

@ -64,9 +64,10 @@ use Box\Spout\Common\Type;
$reader = ReaderFactory::create(Type::CSV); $reader = ReaderFactory::create(Type::CSV);
$reader->open($filePath); $reader->open($filePath);
while ($reader->hasNextRow()) { foreach ($reader->getSheetIterator() as $sheet) {
$row = $reader->nextRow(); foreach ($reader->getRowIterator() as $row) {
// do stuff // do stuff
}
} }
$reader->close(); $reader->close();
@ -81,11 +82,8 @@ use Box\Spout\Common\Type;
$reader = ReaderFactory::create(Type::XLSX); $reader = ReaderFactory::create(Type::XLSX);
$reader->open($filePath); $reader->open($filePath);
while ($reader->hasNextSheet()) { foreach ($reader->getSheetIterator() as $sheet) {
$reader->nextSheet(); foreach ($reader->getRowIterator() as $row) {
while ($reader->hasNextRow()) {
$row = $reader->nextRow();
// do stuff // do stuff
} }
} }
@ -202,8 +200,7 @@ $sheets = $writer->getSheets();
If you rely on the sheet's name in your application, you can access it and customize it this way: If you rely on the sheet's name in your application, you can access it and customize it this way:
```php ```php
// Accessing the sheet name when reading // Accessing the sheet name when reading
while ($reader->hasNextSheet()) { foreach ($reader->getSheetIterator() as $sheet) {
$sheet = $reader->nextSheet();
$sheetName = $sheet->getName(); $sheetName = $sheet->getName();
} }
@ -253,7 +250,7 @@ For information, the performance tests take about one hour to run (processing 2
When writing data, Spout is streaming the data to files, one or few lines at a time. That means that it only keeps in memory the few rows that it needs to write. Once written, the memory is freed. When writing data, Spout is streaming the data to files, one or few lines at a time. That means that it only keeps in memory the few rows that it needs to write. Once written, the memory is freed.
Same goes with reading. Only one row at a time is stored in memory. A special technique is used to handle shared strings in XLSX, storing them into several small temporary files that allows fast access. Same goes with reading. Only one row at a time is stored in memory. A special technique is used to handle shared strings in XLSX, storing them - if needed - into several small temporary files that allows fast access.
#### How long does it take to generate a file with X rows? #### How long does it take to generate a file with X rows?