Files
oleibman e11a6afb5e Xls Writer and Empty RichText
Fix #918, which went stale in 2019 and is now reopened. Writing out a RichText object with no text to Xls creates a file which Excel considers corrupt. Treating such an object as a null string rather than a RichText object when writing eliminates the problem.
2026-01-02 12:46:24 -08:00

31 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xls;
use PhpOffice\PhpSpreadsheet\Helper\Html as HtmlHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class Issue918Test extends AbstractFunctional
{
public function testEmptyRichText(): void
{
// Issue 918 - Xls Writer creates corrupt file with empty RichText.
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$helper = new HtmlHelper();
$html = '<div></div>';
$richValue = $helper->toRichTextObject($html);
self::assertCount(0, $richValue->getRichTextElements());
$sheet->getCell('A1')->setValue($richValue);
$robj = $this->writeAndReload($spreadsheet, 'Xls');
$spreadsheet->disconnectWorksheets();
$sheet0 = $robj->getActiveSheet();
self::assertNull($sheet0->getCell('A1')->getValue(), 'empty text object has been changed to null');
$robj->disconnectWorksheets();
}
}