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