mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-12 02:56:44 +00:00
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:
@@ -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.
Reference in New Issue
Block a user