Support XLSX with prefixed XML files (#237)
While the standard is not to have prefixes, some XLSX files have XML files containing a prefix. Microsoft has a tool that generates such files: https://msdn.microsoft.com/en-us/library/office/gg278316.aspx
This commit is contained in:
1 parent
2ed30321b4
commit
03866a6604
5 files changed
+119
-86
No files matched your search
@@ -198,4 +198,37 @@ class XMLReaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
unlink($tempFolder . '/test.xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataProviderForTestIsPositionedOnStartingAndEndingNode()
|
||||
{
|
||||
return [
|
||||
['<test></test>'], // not prefixed
|
||||
['<x:test xmlns:x="foo"></x:test>'], // prefixed
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderForTestIsPositionedOnStartingAndEndingNode
|
||||
*
|
||||
* @param string $testXML
|
||||
* @return void
|
||||
*/
|
||||
public function testIsPositionedOnStartingAndEndingNode($testXML)
|
||||
{
|
||||
$xmlReader = new XMLReader();
|
||||
$xmlReader->XML($testXML);
|
||||
|
||||
// the first read moves the pointer to "<test>"
|
||||
$xmlReader->read();
|
||||
$this->assertTrue($xmlReader->isPositionedOnStartingNode('test'));
|
||||
$this->assertFalse($xmlReader->isPositionedOnEndingNode('test'));
|
||||
|
||||
// the seconds read moves the pointer to "</test>"
|
||||
$xmlReader->read();
|
||||
$this->assertFalse($xmlReader->isPositionedOnStartingNode('test'));
|
||||
$this->assertTrue($xmlReader->isPositionedOnEndingNode('test'));
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,23 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($expectedRows, $allRows);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testReadShouldSupportPrefixedXMLFiles()
|
||||
{
|
||||
// The XML files of this spreadsheet are prefixed.
|
||||
// For instance, they use "<x:sheet>" instead of "<sheet>", etc.
|
||||
$allRows = $this->getAllRowsForFile('sheet_with_prefixed_xml_files.xlsx');
|
||||
|
||||
$expectedRows = [
|
||||
['s1 - A1', 's1 - B1', 's1 - C1'],
|
||||
['s1 - A2', 's1 - B2', 's1 - C2'],
|
||||
['s1 - A3', 's1 - B3', 's1 - C3'],
|
||||
];
|
||||
$this->assertEquals($expectedRows, $allRows);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user