Fix XLSX reading when shared strings is missing the uniqueCount attribute

Use "count" attribute as a fallback
This commit is contained in:
Adrien Loison 2016-06-16 09:37:36 -07:00
parent a43c13a36f
commit 107ef5e5a6
3 changed files with 23 additions and 1 deletions

View File

@ -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);
}
/**

View File

@ -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
*/