Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xlsx Writer Rich Text and TYPE_STRING #4094

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
oleibman committed Jul 12, 2024
commit 6ab27d2931c3a996e481cb7a226b56a72c670301
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ private function writeCell(XMLWriter $objWriter, PhpspreadsheetWorksheet $worksh

break;
case 's': // String
$this->writeCellString($objWriter, $mappedType, $cellValueString, $flippedStringTable);
$this->writeCellString($objWriter, $mappedType, ($cellValue instanceof RichText) ? $cellValue : $cellValueString, $flippedStringTable);

break;
case 'f': // Formula
Expand Down
30 changes: 30 additions & 0 deletions tests/PhpSpreadsheetTests/Writer/Xlsx/Issue476Test.php
Original file line number Diff line number Diff line change
@@ -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 added tests/data/Writer/XLSX/issue.476.xlsx
Binary file not shown.
Loading