Skip to content

Commit 4eb3f39

Browse files
authored
Merge pull request #186 from dododedodonl/change
Rewind iterator after use
2 parents 65e6717 + 27e0c20 commit 4eb3f39

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/SimpleExcelReader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ public function getRows(): LazyCollection
244244

245245
$this->rowIterator->next();
246246
}
247+
$this->rowIterator->rewind();
248+
249+
if ($this->processHeader) {
250+
$this->getHeaders();
251+
$this->rowIterator->next();
252+
}
247253
});
248254
}
249255

tests/SimpleExcelReaderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,18 @@ function () {
643643
expect($reader->getRows()->count())->toBe(2);
644644
expect($reader->preserveEmptyRows()->getRows()->count())->toBe(3);
645645
});
646+
647+
it('can count and take rows', function () {
648+
$reader = SimpleExcelReader::create(getStubPath('header-and-rows.csv'));
649+
650+
$lazyCollection = $reader->getRows();
651+
652+
expect($lazyCollection->count())->toBe(2);
653+
expect($lazyCollection->take(1)->all())->toEqual([
654+
[
655+
'email' => '[email protected]',
656+
'first_name' => 'john',
657+
'last_name' => 'doe',
658+
],
659+
]);
660+
});

0 commit comments

Comments
 (0)