Fix prefixed shared strings XML file
A prefixed sharedStrings.xml file was not properly read, as we were comparing the un-prefixed name with the possible prefixed name. Also, this commit contains a fix for sheets with rows not starting at column A.
This commit is contained in:
parent
99816b0b8e
commit
6c648cf370
@ -164,4 +164,12 @@ class XMLReader extends \XMLReader
|
|||||||
|
|
||||||
return ($this->nodeType === $nodeType && $currentNodeName === $nodeName);
|
return ($this->nodeType === $nodeType && $currentNodeName === $nodeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string The name of the current node, un-prefixed
|
||||||
|
*/
|
||||||
|
public function getCurrentNodeName()
|
||||||
|
{
|
||||||
|
return $this->localName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ class SharedStringsHelper
|
|||||||
|
|
||||||
$xmlReader->readUntilNodeFound(self::XML_NODE_SI);
|
$xmlReader->readUntilNodeFound(self::XML_NODE_SI);
|
||||||
|
|
||||||
while ($xmlReader->name === self::XML_NODE_SI) {
|
while ($xmlReader->getCurrentNodeName() === self::XML_NODE_SI) {
|
||||||
$this->processSharedStringsItem($xmlReader, $sharedStringIndex);
|
$this->processSharedStringsItem($xmlReader, $sharedStringIndex);
|
||||||
$sharedStringIndex++;
|
$sharedStringIndex++;
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ class SharedStringsHelper
|
|||||||
$xmlReader->next(self::XML_NODE_SST);
|
$xmlReader->next(self::XML_NODE_SST);
|
||||||
|
|
||||||
// Iterate over the "sst" elements to get the actual "sst ELEMENT" (skips any DOCTYPE)
|
// Iterate over the "sst" elements to get the actual "sst ELEMENT" (skips any DOCTYPE)
|
||||||
while ($xmlReader->name === self::XML_NODE_SST && $xmlReader->nodeType !== XMLReader::ELEMENT) {
|
while ($xmlReader->getCurrentNodeName() === self::XML_NODE_SST && $xmlReader->nodeType !== XMLReader::ELEMENT) {
|
||||||
$xmlReader->read();
|
$xmlReader->read();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +348,7 @@ class RowIterator implements IteratorInterface
|
|||||||
*/
|
*/
|
||||||
protected function isEmptyRow($rowData)
|
protected function isEmptyRow($rowData)
|
||||||
{
|
{
|
||||||
return (count($rowData) === 1 && $rowData[0] === '');
|
return (count($rowData) === 1 && key($rowData) === '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,6 +112,22 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expectedRows, $allRows);
|
$this->assertEquals($expectedRows, $allRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testReadShouldSupportPrefixedSharedStringsXML()
|
||||||
|
{
|
||||||
|
// The sharedStrings.xml file of this spreadsheet is prefixed.
|
||||||
|
// For instance, they use "<x:sst>" instead of "<sst>", etc.
|
||||||
|
$allRows = $this->getAllRowsForFile('sheet_with_prefixed_shared_strings_xml.xlsx');
|
||||||
|
|
||||||
|
$expectedRows = [
|
||||||
|
['s1--A1', 's1--B1', 's1--C1', 's1--D1', 's1--E1'],
|
||||||
|
['s1--A2', 's1--B2', 's1--C2', 's1--D2', 's1--E2'],
|
||||||
|
];
|
||||||
|
$this->assertEquals($expectedRows, $allRows);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -169,6 +185,21 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expectedRows, $allRows);
|
$this->assertEquals($expectedRows, $allRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testReadShouldSupportFilesWithRowsNotStartingAtColumnA()
|
||||||
|
{
|
||||||
|
// file where the row starts at column C:
|
||||||
|
// <row r="1"><c r="C1" s="0" t="s"><v>0</v></c>...
|
||||||
|
$allRows = $this->getAllRowsForFile('sheet_with_row_not_starting_at_column_a.xlsx');
|
||||||
|
|
||||||
|
$expectedRows = [
|
||||||
|
['', '', 's1--C1', 's1--D1', 's1--E1'],
|
||||||
|
];
|
||||||
|
$this->assertEquals($expectedRows, $allRows);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
BIN
tests/resources/xlsx/sheet_with_prefixed_shared_strings_xml.xlsx
Normal file
BIN
tests/resources/xlsx/sheet_with_prefixed_shared_strings_xml.xlsx
Normal file
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user