Xlsx Reader Warning When No sz Tag for RichText (#2550)
Fix #2542. Xlsx Reader is expecting a `sz` tag when reading RichText, but it is not required, and PhpSpreadsheet issues a warning message when it is missing.
This commit is contained in:
parent
b300e186fe
commit
5bf0656e92
|
|
@ -1691,13 +1691,17 @@ class Xlsx extends BaseReader
|
||||||
} else {
|
} else {
|
||||||
$objText = $value->createTextRun(StringHelper::controlCharacterOOXML2PHP((string) $run->t));
|
$objText = $value->createTextRun(StringHelper::controlCharacterOOXML2PHP((string) $run->t));
|
||||||
|
|
||||||
$attr = $run->rPr->rFont->attributes();
|
if (isset($run->rPr->rFont)) {
|
||||||
if (isset($attr['val'])) {
|
$attr = $run->rPr->rFont->attributes();
|
||||||
$objText->getFont()->setName((string) $attr['val']);
|
if (isset($attr['val'])) {
|
||||||
|
$objText->getFont()->setName((string) $attr['val']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$attr = $run->rPr->sz->attributes();
|
if (isset($run->rPr->sz)) {
|
||||||
if (isset($attr['val'])) {
|
$attr = $run->rPr->sz->attributes();
|
||||||
$objText->getFont()->setSize((float) $attr['val']);
|
if (isset($attr['val'])) {
|
||||||
|
$objText->getFont()->setSize((float) $attr['val']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isset($run->rPr->color)) {
|
if (isset($run->rPr->color)) {
|
||||||
$objText->getFont()->setColor(new Color($this->styleReader->readColor($run->rPr->color)));
|
$objText->getFont()->setColor(new Color($this->styleReader->readColor($run->rPr->color)));
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
||||||
|
use PhpOffice\PhpSpreadsheet\RichText\RichText;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class Issue2542Test extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $testbook = 'tests/data/Reader/XLSX/issue.2542.xlsx';
|
||||||
|
|
||||||
|
public function testPreliminaries(): void
|
||||||
|
{
|
||||||
|
// Rich text without 'sz' tag
|
||||||
|
$file = 'zip://';
|
||||||
|
$file .= self::$testbook;
|
||||||
|
$file .= '#xl/sharedStrings.xml';
|
||||||
|
$data = file_get_contents($file);
|
||||||
|
|
||||||
|
// confirm that file contains expected namespaced xml tag
|
||||||
|
if ($data === false) {
|
||||||
|
self::fail('Unable to read file sharedStrings.xml');
|
||||||
|
} else {
|
||||||
|
self::assertStringContainsString('<si><r><rPr><rFont val="Arial"/><b/><color theme="1"/></rPr><t xml:space="preserve">Factor group
|
||||||
|
</t></r><r><rPr><rFont val="Arial"/><b val="0"/><color theme="1"/></rPr><t>(for Rental items only)</t></r></si>', $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIssue2542(): void
|
||||||
|
{
|
||||||
|
$filename = self::$testbook;
|
||||||
|
$reader = new Xlsx();
|
||||||
|
$spreadsheet = $reader->load($filename);
|
||||||
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
|
$value = $sheet->getCell('P1')->getValue();
|
||||||
|
if ($value instanceof RichText) {
|
||||||
|
self::assertSame("Factor group\n(for Rental items only)", $value->getPlainText());
|
||||||
|
} else {
|
||||||
|
self::fail('Cell P1 is not RichText');
|
||||||
|
}
|
||||||
|
$spreadsheet->disconnectWorksheets();
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Loading…
Reference in New Issue