Fix XLSX reading when shared strings is missing the uniqueCount attribute (#255)

Use "count" attribute as a fallback
This commit is contained in:
Adrien Loison authored and GitHub committed 2016-06-16 10:06:11 -07:00
1 parent a43c13a36f
commit 1891c0b053
3 files changed
+23 -1

No files matched your search

@@ -159,7 +159,15 @@ class SharedStringsHelper
$xmlReader->read(); $xmlReader->read();
} }
return intval($xmlReader->getAttribute('uniqueCount')); $uniqueCount = $xmlReader->getAttribute('uniqueCount');
// some software do not add the "uniqueCount" attribute but only use the "count" one
// @see https://github.com/box/spout/issues/254
if ($uniqueCount === null) {
$uniqueCount = $xmlReader->getAttribute('count');
}
return intval($uniqueCount);
} }
/** /**
+14
View File
@@ -112,6 +112,20 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expectedRows, $allRows); $this->assertEquals($expectedRows, $allRows);
} }
/**
* @return void
*/
public function testReadShouldSupportSheetWithSharedStringsMissingUniqueCountAttribute()
{
$allRows = $this->getAllRowsForFile('one_sheet_with_shared_strings_missing_unique_count.xlsx');
$expectedRows = [
['s1--A1', 's1--B1'],
['s1--A2', 's1--B2'],
];
$this->assertEquals($expectedRows, $allRows);
}
/** /**
* @return void * @return void
*/ */