Add support for empty sheets
This commit is contained in:
parent
5e199009e6
commit
6bc9a18e9b
@ -190,9 +190,11 @@ class XLSX extends AbstractReader
|
|||||||
while ($this->xmlReader->read()) {
|
while ($this->xmlReader->read()) {
|
||||||
if ($this->xmlReader->nodeType == \XMLReader::ELEMENT && $this->xmlReader->name === 'dimension') {
|
if ($this->xmlReader->nodeType == \XMLReader::ELEMENT && $this->xmlReader->name === 'dimension') {
|
||||||
// Read dimensions of the worksheet
|
// Read dimensions of the worksheet
|
||||||
$dimensionRef = $this->xmlReader->getAttribute('ref'); // returns 'A1:M13' for instance
|
$dimensionRef = $this->xmlReader->getAttribute('ref'); // returns 'A1:M13' for instance (or 'A1' for empty sheet)
|
||||||
list(, $lastCellIndex) = explode(':', $dimensionRef);
|
if (preg_match('/[A-Z\d]+:([A-Z\d]+)/', $dimensionRef, $matches)) {
|
||||||
$this->numberOfColumns = CellHelper::getColumnIndexFromCellIndex($lastCellIndex) + 1;
|
$lastCellIndex = $matches[1];
|
||||||
|
$this->numberOfColumns = CellHelper::getColumnIndexFromCellIndex($lastCellIndex) + 1;
|
||||||
|
}
|
||||||
} else if ($this->xmlReader->nodeType == \XMLReader::ELEMENT && $this->xmlReader->name === 'row') {
|
} else if ($this->xmlReader->nodeType == \XMLReader::ELEMENT && $this->xmlReader->name === 'row') {
|
||||||
// Start of the row description
|
// Start of the row description
|
||||||
$isInsideRowTag = true;
|
$isInsideRowTag = true;
|
||||||
|
@ -165,6 +165,15 @@ class XLSXTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expectedFirstRow, $allRows[0], 'Entities should be ignored when reading XML files.');
|
$this->assertEquals($expectedFirstRow, $allRows[0], 'Entities should be ignored when reading XML files.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testReadShouldBeAbleToProcessEmptySheets()
|
||||||
|
{
|
||||||
|
$allRows = $this->getAllRowsForFile('sheet_with_no_cells.xlsx');
|
||||||
|
$this->assertEquals([], $allRows, 'Sheet with no cells should be correctly processed.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $fileName
|
* @param string $fileName
|
||||||
* @return array All the read rows the given file
|
* @return array All the read rows the given file
|
||||||
|
BIN
tests/resources/xlsx/sheet_with_no_cells.xlsx
Normal file
BIN
tests/resources/xlsx/sheet_with_no_cells.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user