mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-12 11:06:28 +00:00
Tighten Up Writer Html Logic
Fix #434, which went stale in 2018 and is now reopened. User reported a fatal error in Writer/Html. Regrettably, there is no example code/spreadsheet to illustrate the error. However, the area of code where the error happened is identified. Studying that, it was clear that the error could be avoided through the use of the nullsafe operator `?->` without any performance hit, while making the resulting code a little clearer.
This commit is contained in:
@@ -1595,7 +1595,13 @@ class Html extends BaseWriter
|
||||
$origData2 = $cell->getValueString();
|
||||
}
|
||||
}
|
||||
$formatCode = $worksheet->getParentOrThrow()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode();
|
||||
$style = $worksheet->getParent()
|
||||
?->getCellXfByIndexOrNull(
|
||||
$cell->getXfIndex()
|
||||
);
|
||||
$formatCode = $style
|
||||
?->getNumberFormat()
|
||||
->getFormatCode();
|
||||
|
||||
$cellData = NumberFormat::toFormattedString(
|
||||
$origData2,
|
||||
@@ -1606,9 +1612,9 @@ class Html extends BaseWriter
|
||||
if ($cellData === $origData) {
|
||||
$cellData = htmlspecialchars($cellData, Settings::htmlEntityFlags());
|
||||
}
|
||||
if ($worksheet->getParentOrThrow()->getCellXfByIndex($cell->getXfIndex())->getFont()->getSuperscript()) {
|
||||
if (true === $style?->getFont()->getSuperscript()) {
|
||||
$cellData = '<sup>' . $cellData . '</sup>';
|
||||
} elseif ($worksheet->getParentOrThrow()->getCellXfByIndex($cell->getXfIndex())->getFont()->getSubscript()) {
|
||||
} elseif (true === $style?->getFont()->getSubscript()) {
|
||||
$cellData = '<sub>' . $cellData . '</sub>';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user