Skip to content

Commit

Permalink
Fix column names if read filter calls in XLSX reader skip columns
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisBirkholz authored and guillaume-ro-fr committed Jun 12, 2019
1 parent 9aa01e4 commit 564b432
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Added

- Refactored Matrix Functions to use external Matrix library
- Possibility to specify custom colors of values for pie and donut charts (https://github.com/PHPOffice/PhpSpreadsheet/pull/768)
- Possibility to specify custom colors of values for pie and donut charts - [#768](https://github.com/PHPOffice/PhpSpreadsheet/pull/768)

### Fixed

- Improve XLSX parsing speed if no readFilter is applied - [#772](https://github.com/PHPOffice/PhpSpreadsheet/issues/772)
- Fix column names if read filter calls in XLSX reader skip columns - [#777](https://github.com/PHPOffice/PhpSpreadsheet/pull/777)

## [1.5.2] - 2018-11-25

Expand All @@ -40,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Fix print area parser for XLSX reader - [#734](https://github.com/PHPOffice/PhpSpreadsheet/pull/734)
- Support overriding `DefaultValueBinder::dataTypeForValue()` without overriding `DefaultValueBinder::bindValue()` - [#735](https://github.com/PHPOffice/PhpSpreadsheet/pull/735)
- Mpdf export can exceed pcre.backtrack_limit - [#637](https://github.com/PHPOffice/PhpSpreadsheet/issues/637)
- Fix index overflow on data values array - [#748](https://github.com/PHPOffice/PhpSpreadsheet/pull/748)

## [1.5.0] - 2018-10-21

Expand Down
2 changes: 2 additions & 0 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,8 @@ public function load($pFilename)
$coordinates = Coordinate::coordinateFromString($r);

if (!$this->getReadFilter()->readCell($coordinates[0], (int) $coordinates[1], $docSheet->getTitle())) {
$rowIndex += 1;

continue;
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/OddColumnReadFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader;

use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;

/**
* Show only cells from odd columns.
*/
class OddColumnReadFilter implements IReadFilter
{
public function readCell($column, $row, $worksheetName = '')
{
return (\ord(\substr($column, -1, 1)) % 2) === 1;
}
}
16 changes: 16 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/XlsxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,20 @@ public function testLoadXlsxWithoutCellReference()
$reader = new Xlsx();
$reader->load($filename);
}

/**
* Test load Xlsx file and use a read filter.
*/
public function testLoadWithReadFilter()
{
$filename = './data/Reader/XLSX/without_cell_reference.xlsx';
$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];

for ($i = 0; $i < 10; ++$i) {
$this->assertEquals($ref, \array_slice($data[$i], 0, 10, true));
}
}
}

0 comments on commit 564b432

Please sign in to comment.