Fix column names if read filter calls in XLSX reader skip columns
Fixes #777 Closes #778
This commit is contained in:
		
							parent
							
								
									dfa808a955
								
							
						
					
					
						commit
						e56fbe2745
					
				| @ -10,11 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org). | |||||||
| ### Added | ### Added | ||||||
| 
 | 
 | ||||||
| - Refactored Matrix Functions to use external Matrix library | - 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 | ### Fixed | ||||||
| 
 | 
 | ||||||
| - Improve XLSX parsing speed if no readFilter is applied - [#772](https://github.com/PHPOffice/PhpSpreadsheet/issues/772) | - 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 | ## [1.5.2] - 2018-11-25 | ||||||
| 
 | 
 | ||||||
| @ -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) | - 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) | - 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) | - 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 | ## [1.5.0] - 2018-10-21 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -911,6 +911,8 @@ class Xlsx extends BaseReader | |||||||
|                                             $coordinates = Coordinate::coordinateFromString($r); |                                             $coordinates = Coordinate::coordinateFromString($r); | ||||||
| 
 | 
 | ||||||
|                                             if (!$this->getReadFilter()->readCell($coordinates[0], (int) $coordinates[1], $docSheet->getTitle())) { |                                             if (!$this->getReadFilter()->readCell($coordinates[0], (int) $coordinates[1], $docSheet->getTitle())) { | ||||||
|  |                                                 $rowIndex += 1; | ||||||
|  | 
 | ||||||
|                                                 continue; |                                                 continue; | ||||||
|                                             } |                                             } | ||||||
|                                         } |                                         } | ||||||
|  | |||||||
							
								
								
									
										16
									
								
								tests/PhpSpreadsheetTests/Reader/OddColumnReadFilter.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								tests/PhpSpreadsheetTests/Reader/OddColumnReadFilter.php
									
									
									
									
									
										Normal file
									
								
							| @ -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,4 +16,20 @@ class XlsxTest extends TestCase | |||||||
|         $reader = new Xlsx(); |         $reader = new Xlsx(); | ||||||
|         $reader->load($filename); |         $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)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Dennis Birkholz
						Dennis Birkholz