Skip to content

Commit 1c06890

Browse files
authored
Merge pull request #4064 from oleibman/issue4063
Handle Empty String in SharedStrings
2 parents fc74f00 + 7c1ff62 commit 1c06890

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
3333
- Xls Conditional Format Improvements. [PR #4030](https://github.com/PHPOffice/PhpSpreadsheet/pull/4030) [PR #4033](https://github.com/PHPOffice/PhpSpreadsheet/pull/4033)
3434
- Conditional Range Unions and Intersections [Issue #4039](https://github.com/PHPOffice/PhpSpreadsheet/issues/4039) [PR #4042](https://github.com/PHPOffice/PhpSpreadsheet/pull/4042)
3535
- Csv Reader allow use of html mimetype. [Issue #4036](https://github.com/PHPOffice/PhpSpreadsheet/issues/4036) [PR #4049](https://github.com/PHPOffice/PhpSpreadsheet/pull/4040)
36+
- Empty String in sharedStrings. [Issue #4063](https://github.com/PHPOffice/PhpSpreadsheet/issues/4063) [PR #4064](https://github.com/PHPOffice/PhpSpreadsheet/pull/4064)
3637

3738
## 2024-05-11 - 2.1.0
3839

src/PhpSpreadsheet/Reader/Xlsx.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
700700
$sharedStrings[] = StringHelper::controlCharacterOOXML2PHP((string) $val->t);
701701
} elseif (isset($val->r)) {
702702
$sharedStrings[] = $this->parseRichText($val);
703+
} else {
704+
$sharedStrings[] = '';
703705
}
704706
}
705707
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
6+
7+
use PhpOffice\PhpSpreadsheet\IOFactory;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class Issue4063Test extends TestCase
11+
{
12+
private static string $testbook = 'tests/data/Reader/XLSX/issue.4063.xlsx';
13+
14+
public function testSharedStringsWithEmptyString(): void
15+
{
16+
$spreadsheet = IOFactory::load(self::$testbook);
17+
$sheet = $spreadsheet->getActiveSheet();
18+
$data = $sheet->toArray(null, true, true, true);
19+
$nbsp = "\u{00a0}";
20+
self::assertSame(['A' => '226', 'B' => '', 'C' => $nbsp], $data[17]);
21+
self::assertSame(['A' => '38873', 'B' => 'gg', 'C' => ' '], $data[22]);
22+
$spreadsheet->disconnectWorksheets();
23+
}
24+
}
6.76 KB
Binary file not shown.

0 commit comments

Comments
 (0)