diff --git a/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php b/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php index 750c53e..350024a 100644 --- a/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php +++ b/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php @@ -159,7 +159,15 @@ class SharedStringsHelper $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); } /** diff --git a/tests/Spout/Reader/XLSX/ReaderTest.php b/tests/Spout/Reader/XLSX/ReaderTest.php index 2703799..c705f2f 100644 --- a/tests/Spout/Reader/XLSX/ReaderTest.php +++ b/tests/Spout/Reader/XLSX/ReaderTest.php @@ -112,6 +112,20 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $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 */ diff --git a/tests/resources/xlsx/one_sheet_with_shared_strings_missing_unique_count.xlsx b/tests/resources/xlsx/one_sheet_with_shared_strings_missing_unique_count.xlsx new file mode 100644 index 0000000..8001e4b Binary files /dev/null and b/tests/resources/xlsx/one_sheet_with_shared_strings_missing_unique_count.xlsx differ