Skip to content

Commit

Permalink
Add check on null for stylesXMLFilePath property (#248)
Browse files Browse the repository at this point in the history
* Add check on null for stylesXMLFilePath property in getNumberFormatCode method of XLSX Reader StyleManager

* add test for xlsx without styles file

* fix code style

* fix code style #2
  • Loading branch information
reznikartem committed Jun 17, 2024
1 parent 9549d77 commit 24272c1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Reader/XLSX/Manager/StyleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public function shouldFormatNumericValueAsDate(int $styleId): bool

public function getNumberFormatCode(int $styleId): string
{
if (null === $this->stylesXMLFilePath) {
return '';
}

$stylesAttributes = $this->getStylesAttributes();
$styleAttributes = $stylesAttributes[$styleId];
$numFmtId = $styleAttributes[self::XML_ATTRIBUTE_NUM_FMT_ID];
Expand Down
25 changes: 25 additions & 0 deletions tests/Reader/XLSX/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,31 @@ public function testReadShouldSkipFormulas(): void
self::assertEquals($expectedRows, $allRows);
}

public function testReadXlsxWithoutStyles(): void
{
$allRows = [];
$resourcePath = TestUsingResource::getResourcePath('xlsx_without_styles_file.xlsx');

$options = new Options();
$options->setTempFolder((new TestUsingResource())->getTempFolderPath());
$reader = new Reader($options);
$reader->open($resourcePath);

foreach ($reader->getSheetIterator() as $sheet) {
foreach ($sheet->getRowIterator() as $row) {
$allRows[] = $row->toArray();
}
}

$reader->close();

$expectedRows = [
['data', 'data', 'data', 'data', 'data', 'data', 'data', 'data', 'data'],
[0, 0, 0, 'data', 'data', '', 12345],
];
self::assertSame($expectedRows, $allRows);
}

public function testReadMultipleTimesShouldRewindReader(): void
{
$allRows = [];
Expand Down
Binary file not shown.

0 comments on commit 24272c1

Please sign in to comment.