fix: Load tables when flag IReader::READ_DATA_ONLY is used (#3726)

* fix: Load tables when flag IReader::READ_DATA_ONLY is used

* Add test for table read when IReader:::READ_DATA_ONLY is used

---------

Co-authored-by: Kevin Verschaeve <kevin.verschaeve@exotec.com>
This commit is contained in:
Kevin Verschaeve
2023-09-14 14:58:52 +02:00
committed by GitHub
parent 1b01b7d1ec
commit 6fbf474642
3 changed files with 29 additions and 1 deletions
+2 -1
View File
@@ -972,9 +972,10 @@ class Xlsx extends BaseReader
if ($this->readDataOnly === false) {
$this->readAutoFilter($xmlSheetNS, $docSheet);
$this->readTables($xmlSheetNS, $docSheet, $dir, $fileWorksheet, $zip, $mainNS);
}
$this->readTables($xmlSheetNS, $docSheet, $dir, $fileWorksheet, $zip, $mainNS);
if ($xmlSheetNS && $xmlSheetNS->mergeCells && $xmlSheetNS->mergeCells->mergeCell && !$this->readDataOnly) {
foreach ($xmlSheetNS->mergeCells->mergeCell as $mergeCellx) {
/** @scrutinizer ignore-call */
@@ -6,6 +6,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReader;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
@@ -245,4 +246,30 @@ height:13.5pt;z-index:5;mso-wrap-style:tight'],
height:13.5pt;z-index:5;mso-wrap-style:tight'],
];
}
public function testLoadDataOnlyLoadsAlsoTables(): void
{
$filename = 'tests/data/Reader/XLSX/data_with_tables.xlsx';
$reader = new Xlsx();
$excel = $reader->load($filename, IReader::READ_DATA_ONLY);
self::assertEquals(['First', 'Second'], $excel->getSheetNames());
$table = $excel->getTableByName('Tableau1');
$firstSheet = $excel->getSheetByName('First');
$secondSheet = $excel->getSheetByName('Second');
if (!$table || !$firstSheet || !$secondSheet) {
self::fail('Table or Sheet not found.');
}
self::assertEquals('A1:B5', $table->getRange());
self::assertEquals([['1', '2', '3']], $firstSheet->toArray());
self::assertEquals([
['Colonne1', 'Colonne2'],
['a', 'b'],
['c', 'd'],
['e', 'f'],
['g', 'h'],
], $secondSheet->toArray());
}
}
Binary file not shown.