Use worksheet->getHighestColumn/Row for isFiltered

There may very well be a good reason the row/col attributes are loaded
first. This is passing the test suite though and I think makes more
sense than iterating over the Row/Col attrs to get the Col/Row
isFiltered bool.
This commit is contained in:
Alex Wright 2020-12-13 16:00:06 +01:00
parent f366c0f257
commit e1018e2330
2 changed files with 21 additions and 28 deletions

View File

@ -630,19 +630,6 @@ class Xlsx extends BaseReader
$docSheet->setSheetState((string) $eleSheet['state']);
}
if ($xmlSheet) {
if (isset($xmlSheet->sheetViews, $xmlSheet->sheetViews->sheetView)) {
$sheetViews = new SheetViews($xmlSheet->sheetViews->sheetView, $docSheet);
$sheetViews->load();
}
$sheetViewOptions = new SheetViewOptions($docSheet, $xmlSheet);
$sheetViewOptions->load($this->getReadDataOnly());
(new ColumnAndRowAttributes($docSheet, $xmlSheet))
->load($this->getReadFilter(), $this->getReadDataOnly());
}
if ($xmlSheet && $xmlSheet->sheetData && $xmlSheet->sheetData->row) {
$cIndex = 1; // Cell Start from 1
foreach ($xmlSheet->sheetData->row as $row) {
@ -756,6 +743,19 @@ class Xlsx extends BaseReader
}
}
if ($xmlSheet) {
if (isset($xmlSheet->sheetViews, $xmlSheet->sheetViews->sheetView)) {
$sheetViews = new SheetViews($xmlSheet->sheetViews->sheetView, $docSheet);
$sheetViews->load();
}
$sheetViewOptions = new SheetViewOptions($docSheet, $xmlSheet);
$sheetViewOptions->load($this->getReadDataOnly());
(new ColumnAndRowAttributes($docSheet, $xmlSheet))
->load($this->getReadFilter(), $this->getReadDataOnly());
}
if (!$this->readDataOnly && $xmlSheet && $xmlSheet->conditionalFormatting) {
(new ConditionalStyles($docSheet, $xmlSheet, $dxfs))->load();
}

View File

@ -96,7 +96,7 @@ class ColumnAndRowAttributes extends BaseParserClass
foreach ($columnsAttributes as $columnCoordinate => $columnAttributes) {
if (
$readFilter === null ||
!$this->isFilteredColumn($readFilter, $columnCoordinate, $rowsAttributes)
!$this->isFilteredColumn($readFilter, $columnCoordinate)
) {
if (!isset($columnsAttributesAreSet[$columnCoordinate])) {
$this->setColumnAttributes($columnCoordinate, $columnAttributes);
@ -109,7 +109,7 @@ class ColumnAndRowAttributes extends BaseParserClass
foreach ($rowsAttributes as $rowCoordinate => $rowAttributes) {
if (
$readFilter === null ||
!$this->isFilteredRow($readFilter, $rowCoordinate, $columnsAttributes)
!$this->isFilteredRow($readFilter, $rowCoordinate)
) {
if (!isset($rowsAttributesAreSet[$rowCoordinate])) {
$this->setRowAttributes($rowCoordinate, $rowAttributes);
@ -119,17 +119,13 @@ class ColumnAndRowAttributes extends BaseParserClass
}
}
private function isFilteredColumn(IReadFilter $readFilter, $columnCoordinate, array $rowsAttributes)
private function isFilteredColumn(IReadFilter $readFilter, $columnCoordinate)
{
if (empty($rowAttributes)) {
return false;
}
foreach ($rowsAttributes as $rowCoordinate => $rowAttributes) {
for ($rowCoordinate = 1; $rowCoordinate <= $this->worksheet->getHighestRow(); $rowCoordinate++) {
if ($readFilter->readCell($columnCoordinate, $rowCoordinate, $this->worksheet->getTitle())) {
return false;
}
}
return true;
}
@ -174,17 +170,14 @@ class ColumnAndRowAttributes extends BaseParserClass
return $columnAttributes;
}
private function isFilteredRow(IReadFilter $readFilter, $rowCoordinate, array $columnsAttributes)
private function isFilteredRow(IReadFilter $readFilter, $rowCoordinate)
{
if (empty($columnAttributes)) {
return false;
}
foreach ($columnsAttributes as $columnCoordinate => $columnAttributes) {
if ($readFilter->readCell($columnCoordinate, $rowCoordinate, $this->worksheet->getTitle())) {
$lastColumnIndex = Coordinate::columnIndexFromString($this->worksheet->getHighestColumn());
for ($columnIndex = 1; $columnIndex <= $lastColumnIndex; $columnIndex++) {
if ($readFilter->readCell(Coordinate::stringFromColumnIndex($columnIndex), $rowCoordinate)) {
return false;
}
}
return true;
}