Fix for worksheet lookup for worksheets with spaces in the title

Sheet titles containing " " or "!" will be quoted in formulas. This commit
fixes the lookup of sheets with this kind of title by trimming the quotes
during the lookup.

Without this any defined range referencing a sheet with " " or "!" in the title
name will be lost when reading the workbook from file.

Fixes #928
Closes 930
This commit is contained in:
Dominik Businger 2019-03-13 11:32:22 +01:00 committed by Adrien Crivelli
parent f6f1ef2893
commit 98a1f0a8cf
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
5 changed files with 28 additions and 1 deletions

View File

@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Fix number format masks containing named colours that were being misinterpreted as date formats; and add support for masks that fully replace the value with a full text string [Issue #1009](https://github.com/PHPOffice/PhpSpreadsheet/issues/1009)
- Stricter-typed comparison testing in COUNTIF() and COUNTIFS() evaluation [Issue #1046](https://github.com/PHPOffice/PhpSpreadsheet/issues/1046)
- COUPNUM should not return zero when settlement is in the last period - [Issue #1020](https://github.com/PHPOffice/PhpSpreadsheet/issues/1020) and [PR #1021](https://github.com/PHPOffice/PhpSpreadsheet/pull/1021)
- Fix handling of named ranges referencing sheets with spaces or "!" in their title
## [1.8.2] - 2019-07-08

View File

@ -721,7 +721,7 @@ class Spreadsheet
{
$worksheetCount = count($this->workSheetCollection);
for ($i = 0; $i < $worksheetCount; ++$i) {
if ($this->workSheetCollection[$i]->getTitle() === $pName) {
if ($this->workSheetCollection[$i]->getTitle() === trim($pName, "'")) {
return $this->workSheetCollection[$i];
}
}

View File

@ -137,6 +137,7 @@ class WorksheetTest extends TestCase
['B2', '', '', 'B2'],
['testTitle!B2', 'testTitle', 'B2', 'B2'],
['test!Title!B2', 'test!Title', 'B2', 'B2'],
['test Title!B2', 'test Title', 'B2', 'B2'],
];
}

View File

@ -81,4 +81,14 @@ return [
'\'Worksheet1\'!A16',
'123',
],
[
true,
'A17',
'=\'Work sheet1\'!A1',
],
[
true,
'A18',
'=\'Work!sheet1\'!A1',
],
];

View File

@ -21,11 +21,26 @@ return [
'A4',
'=\'Worksheet1\'!A1',
],
[
'=\'Works heet1\'!A1',
'A4',
'=\'Works heet1\'!A1',
],
[
'="HELLO WORLD"',
'\'Worksheet1\'!A5',
'="HELLO WORLD"',
],
[
'="HELLO WORLD"',
'\'Work sheet1\'!A5',
'="HELLO WORLD"',
],
[
'="HELLO WORLD"',
'\'Work!sheet1\'!A5',
'="HELLO WORLD"',
],
[
'#N/A',
'\'Worksheet1\'!A6',