Xlsx Writer Rich Text and TYPE_STRING

Fix #476. Another in the "better late than never" series, closed as stale in June 2018. Xlsx Writer expects cells containing RichText to have DataType `TYPE_INLINE`; but the spreadsheet associated with the issue has the cell defined as `TYPE_STRING`. Change Writer to handle RichText TYPE_STRING appropriately.
This commit is contained in:
oleibman
2024-07-11 20:05:16 -07:00
parent 1b68270f80
commit 6ab27d2931
3 changed files with 31 additions and 1 deletions
+1 -1
View File
@@ -1528,7 +1528,7 @@ class Worksheet extends WriterPart
break;
case 's': // String
$this->writeCellString($objWriter, $mappedType, $cellValueString, $flippedStringTable);
$this->writeCellString($objWriter, $mappedType, ($cellValue instanceof RichText) ? $cellValue : $cellValueString, $flippedStringTable);
break;
case 'f': // Formula
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class Issue476Test extends AbstractFunctional
{
public function testIssue476(): void
{
// RichText written in a way usually used only by strings.
$reader = new XlsxReader();
$spreadsheet = $reader->load('tests/data/Writer/XLSX/issue.476.xlsx');
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
$spreadsheet->disconnectWorksheets();
$sheet = $reloadedSpreadsheet->getActiveSheet();
$richText = $sheet->getCell('A1')->getValue();
self::assertInstanceOf(RichText::class, $richText);
$plainText = $richText->getPlainText();
self::assertSame("Art. 1A of the Geneva Refugee Convention and Protocol or other international or national instruments.\n", $plainText);
$reloadedSpreadsheet->disconnectWorksheets();
}
}
Binary file not shown.