mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-10-22 20:09:39 +00:00
ecbd702628
Phpstan hasn't identified any errors in Samples in a long time. But, as it turns out, one particular error is suppressed: ``` Variable $helper might not be defined. ``` This error would be generated by almost all samples, and the errors that it suppresses will become problematic if we move to Level 10. We are not yet committed to doing that, but it is pretty easy to write a script to change the samples so that error no longer happens, and there isn't really any reason to delay doing so. The results of that script constitute this PR.
26 lines
662 B
PHP
26 lines
662 B
PHP
<?php
|
|
|
|
/**
|
|
* Use rangeToArrayYieldRows() to efficiently iterate over all rows.
|
|
*/
|
|
|
|
require __DIR__ . '/../Header.php';
|
|
/** @var PhpOffice\PhpSpreadsheet\Helper\Sample $helper */
|
|
$inputFileName = __DIR__ . '/../Reader/sampleData/example1.xls';
|
|
|
|
$spreadsheet = PhpOffice\PhpSpreadsheet\IOFactory::load(
|
|
$inputFileName,
|
|
PhpOffice\PhpSpreadsheet\Reader\IReader::READ_DATA_ONLY
|
|
);
|
|
$sheet = $spreadsheet->getSheet(0);
|
|
|
|
$rowGenerator = $sheet->rangeToArrayYieldRows(
|
|
$spreadsheet->getActiveSheet()->calculateWorksheetDataDimension(),
|
|
null,
|
|
false,
|
|
false
|
|
);
|
|
foreach ($rowGenerator as $row) {
|
|
echo '| ' . $row[0] . ' | ' . $row[1] . "|\n";
|
|
}
|