Modify toArray() method to use highest data row/column rather than highest row/column

This commit is contained in:
MarkBaker
2022-07-05 14:36:34 +02:00
parent fd4e256108
commit ccd9aba5fc
3 changed files with 509 additions and 178 deletions
Generated
+505 -173
View File
File diff suppressed because it is too large Load Diff
+2 -3
View File
@@ -3001,15 +3001,14 @@ class Worksheet implements IComparable
$this->garbageCollect();
// Identify the range that we need to extract from the worksheet
$maxCol = $this->getHighestColumn();
$maxRow = $this->getHighestRow();
$maxCell = $this->getHighestDataRowAndColumn();
if ($currentCellAddress !== null) {
$this->getCell($currentCellAddress);
}
// Return
return $this->rangeToArray('A1:' . $maxCol . $maxRow, $nullValue, $calculateFormulas, $formatData, $returnCellRef);
return $this->rangeToArray('A1:' . $maxCell, $nullValue, $calculateFormulas, $formatData, $returnCellRef);
}
/**
@@ -218,10 +218,10 @@ class XlsxTest extends TestCase
$reader = new Xlsx();
$reader->setReadFilter(new OddColumnReadFilter());
$data = $reader->load($filename)->getActiveSheet()->toArray();
$ref = [1.0, null, 3.0, null, 5.0, null, 7.0, null, 9.0, null];
$ref = [1, null, 3, null, 5, null, 7, null, 9];
for ($i = 0; $i < 10; ++$i) {
self::assertEquals($ref, \array_slice($data[$i], 0, 10, true));
self::assertEquals($ref, \array_slice($data[$i], 0, 9, true));
}
}