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.
This commit is contained in:
oleibman
2025-04-03 19:55:33 -07:00
parent 74dca30c89
commit 5b799dbbed
3 changed files with 32 additions and 1 deletions
+1 -1
View File
@@ -617,7 +617,7 @@ class Ods extends BaseReader
if ($cellDataType === 'array') {
$cell->setFormulaAttributes(['t' => 'array', 'ref' => $cellDataRef]);
}
} else {
} elseif ($type !== '' || $dataValue !== null) {
$cell->setValueExplicit($dataValue, $type);
}
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Reader\Ods as OdsReader;
use PHPUnit\Framework\TestCase;
class Issue4435Test extends TestCase
{
private string $file = 'tests/data/Reader/Ods/issue.4435b.ods';
public function testNoHeaderFooterStyle(): void
{
// had been throwing exception when cell didn't have value-type
$zipFile = 'zip://' . $this->file . '#content.xml';
$contents = (string) file_get_contents($zipFile);
self::assertStringContainsString(
'<table:table-cell table:style-name="ce1">' . "\n"
. '<text:p/>' . "\n"
. '</table:table-cell>',
$contents
);
$reader = new OdsReader();
$spreadsheet = $reader->load($this->file);
$sheet = $spreadsheet->getActiveSheet();
self::assertNull($sheet->getCell('B1')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
Binary file not shown.