Fix XLSX reading when shared strings is missing the uniqueCount attribute (#255)
Use "count" attribute as a fallback
This commit is contained in:
parent
a43c13a36f
commit
1891c0b053
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
*/
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user