diff --git a/CHANGELOG.md b/CHANGELOG.md index f1b8789656..96cb58d8c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Phase 1 of better namespace handling for Xlsx, resolving many open issues. [PR #2173](https://github.com/PHPOffice/PhpSpreadsheet/pull/2173) [PR #2204](https://github.com/PHPOffice/PhpSpreadsheet/pull/2204) +[PR #2303](https://github.com/PHPOffice/PhpSpreadsheet/pull/2303) - Add ability to extract images if source is a URL. [Issue #1997](https://github.com/PHPOffice/PhpSpreadsheet/issues/1997) [PR #2072](https://github.com/PHPOffice/PhpSpreadsheet/pull/2072) - Support for passing flags in the Reader `load()` and Writer `save()`methods, and through the IOFactory, to set behaviours. [PR #2136](https://github.com/PHPOffice/PhpSpreadsheet/pull/2136) - See [documentation](https://phpspreadsheet.readthedocs.io/en/latest/topics/reading-and-writing-to-file/) for details diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 2bff7e1ed5..245c27d2d5 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -1675,46 +1675,63 @@ private function parseRichText(?SimpleXMLElement $is) } else { $objText = $value->createTextRun(StringHelper::controlCharacterOOXML2PHP((string) $run->t)); - if (isset($run->rPr->rFont['val'])) { - $objText->getFont()->setName((string) $run->rPr->rFont['val']); + $attr = $run->rPr->rFont->attributes(); + if (isset($attr['val'])) { + $objText->getFont()->setName((string) $attr['val']); } - if (isset($run->rPr->sz['val'])) { - $objText->getFont()->setSize((float) $run->rPr->sz['val']); + $attr = $run->rPr->sz->attributes(); + if (isset($attr['val'])) { + $objText->getFont()->setSize((float) $attr['val']); } if (isset($run->rPr->color)) { $objText->getFont()->setColor(new Color(Styles::readColor($run->rPr->color))); } - if ( - (isset($run->rPr->b['val']) && self::boolean((string) $run->rPr->b['val'])) || - (isset($run->rPr->b) && !isset($run->rPr->b['val'])) - ) { - $objText->getFont()->setBold(true); - } - if ( - (isset($run->rPr->i['val']) && self::boolean((string) $run->rPr->i['val'])) || - (isset($run->rPr->i) && !isset($run->rPr->i['val'])) - ) { - $objText->getFont()->setItalic(true); + if (isset($run->rPr->b)) { + $attr = $run->rPr->b->attributes(); + if ( + (isset($attr['val']) && self::boolean((string) $attr['val'])) || + (!isset($attr['val'])) + ) { + $objText->getFont()->setBold(true); + } } - if (isset($run->rPr->vertAlign, $run->rPr->vertAlign['val'])) { - $vertAlign = strtolower((string) $run->rPr->vertAlign['val']); - if ($vertAlign == 'superscript') { - $objText->getFont()->setSuperscript(true); + if (isset($run->rPr->i)) { + $attr = $run->rPr->i->attributes(); + if ( + (isset($attr['val']) && self::boolean((string) $attr['val'])) || + (!isset($attr['val'])) + ) { + $objText->getFont()->setItalic(true); } - if ($vertAlign == 'subscript') { - $objText->getFont()->setSubscript(true); + } + if (isset($run->rPr->vertAlign)) { + $attr = $run->rPr->vertAlign->attributes(); + if (isset($attr['val'])) { + $vertAlign = strtolower((string) $attr['val']); + if ($vertAlign == 'superscript') { + $objText->getFont()->setSuperscript(true); + } + if ($vertAlign == 'subscript') { + $objText->getFont()->setSubscript(true); + } } } - if (isset($run->rPr->u) && !isset($run->rPr->u['val'])) { - $objText->getFont()->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLE); - } elseif (isset($run->rPr->u, $run->rPr->u['val'])) { - $objText->getFont()->setUnderline((string) $run->rPr->u['val']); + if (isset($run->rPr->u)) { + $attr = $run->rPr->u->attributes(); + if (!isset($attr['val'])) { + $objText->getFont()->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLE); + } else { + $objText->getFont()->setUnderline((string) $attr['val']); + } } - if ( - (isset($run->rPr->strike['val']) && self::boolean((string) $run->rPr->strike['val'])) || - (isset($run->rPr->strike) && !isset($run->rPr->strike['val'])) - ) { - $objText->getFont()->setStrikethrough(true); + if (isset($run->rPr->strike)) { + $attr = $run->rPr->strike->attributes(); + if ( + (isset($attr['val']) && self::boolean((string) $attr['val'])) || + (!isset($attr['val'])) + ) { + $objText->getFont()->setStrikethrough(true); + } } } } diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue2301Test.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue2301Test.php new file mode 100644 index 0000000000..4484b9e095 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue2301Test.php @@ -0,0 +1,28 @@ +getActiveSheet(); + $value = $sheet->getCell('B45')->getValue(); + self::assertInstanceOf(RichText::class, $value); + $richtext = $value->getRichTextElements(); + $font = $richtext[1]->getFont(); + self::assertNotNull($font); + self::assertSame('Arial CE', $font->getName()); + self::assertSame(9.0, $font->getSize()); + self::assertSame('protected', $sheet->getCell('BT10')->getStyle()->getProtection()->getHidden()); + } +} diff --git a/tests/data/Reader/XLSX/issue.2301.xlsx b/tests/data/Reader/XLSX/issue.2301.xlsx new file mode 100644 index 0000000000..befbe8fcc2 Binary files /dev/null and b/tests/data/Reader/XLSX/issue.2301.xlsx differ