Fixed handling of inline strings in XLSX (#2569)

* Fixed handling of inline strings

* Added an example for the "inline string" datatype for which the generated XML was fixed in the previous commit.

* Handle inline strings exactly the same way as regular strings in the XLS writer, because this is only relevant in the XLSX format.
This commit is contained in:
mweimerskirch 2022-02-12 15:55:48 +01:00 committed by GitHub
parent 5bf0656e92
commit 90e9ea9505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View File

@ -1,5 +1,6 @@
<?php
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -144,6 +145,11 @@ $spreadsheet->getActiveSheet()
$spreadsheet->getActiveSheet()
->setCellValue('C18', '=HYPERLINK("mailto:abc@def.com","abc@def.com")');
$spreadsheet->getActiveSheet()
->setCellValue('A20', 'String')
->setCellValue('B20', 'inline')
->setCellValueExplicit('C20', 'This will not be added to sharedStrings.xml', DataType::TYPE_INLINE);
$spreadsheet->getActiveSheet()
->getColumnDimension('B')
->setAutoSize(true);

View File

@ -433,6 +433,7 @@ class Worksheet extends BIFFwriter
} else {
switch ($cell->getDatatype()) {
case DataType::TYPE_STRING:
case DataType::TYPE_INLINE:
case DataType::TYPE_NULL:
if ($cVal === '' || $cVal === null) {
$this->writeBlank($row, $column, $xfIndex);

View File

@ -1189,10 +1189,12 @@ class Worksheet extends WriterPart
{
$objWriter->writeAttribute('t', $mappedType);
if (!$cellValue instanceof RichText) {
$objWriter->startElement('is');
$objWriter->writeElement(
't',
StringHelper::controlCharacterPHP2OOXML(htmlspecialchars($cellValue, Settings::htmlEntityFlags()))
);
$objWriter->endElement();
} elseif ($cellValue instanceof RichText) {
$objWriter->startElement('is');
$this->getParentWriter()->getWriterPartstringtable()->writeRichText($objWriter, $cellValue);