Skip to content

Commit 5b799db

Browse files
committed
Ods Reader No Datatype for Null Value
Issue #4435 was initially described incorrectly. While investigating the original description, I came upon this problem. Ods Reader is trying to set some cells to null without supplying a valid DataType to setValueExplicit, causing that method to throw an exception. Reader is changed to no longer call that method when value is null and DataType is null-string.
1 parent 74dca30 commit 5b799db

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/PhpSpreadsheet/Reader/Ods.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
617617
if ($cellDataType === 'array') {
618618
$cell->setFormulaAttributes(['t' => 'array', 'ref' => $cellDataRef]);
619619
}
620-
} else {
620+
} elseif ($type !== '' || $dataValue !== null) {
621621
$cell->setValueExplicit($dataValue, $type);
622622
}
623623

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
6+
7+
use PhpOffice\PhpSpreadsheet\Reader\Ods as OdsReader;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class Issue4435Test extends TestCase
11+
{
12+
private string $file = 'tests/data/Reader/Ods/issue.4435b.ods';
13+
14+
public function testNoHeaderFooterStyle(): void
15+
{
16+
// had been throwing exception when cell didn't have value-type
17+
$zipFile = 'zip://' . $this->file . '#content.xml';
18+
$contents = (string) file_get_contents($zipFile);
19+
self::assertStringContainsString(
20+
'<table:table-cell table:style-name="ce1">' . "\n"
21+
. '<text:p/>' . "\n"
22+
. '</table:table-cell>',
23+
$contents
24+
);
25+
$reader = new OdsReader();
26+
$spreadsheet = $reader->load($this->file);
27+
$sheet = $spreadsheet->getActiveSheet();
28+
self::assertNull($sheet->getCell('B1')->getValue());
29+
$spreadsheet->disconnectWorksheets();
30+
}
31+
}

tests/data/Reader/Ods/issue.4435b.ods

10.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)