Fixed reading XSLS style alignments from XML (#1710)

The attribute `$alignmentXml` given to the private method `readAlignmentStyle` is the alignment XML tag that contains the alignment data itself. But inside that method all data are read from another `alignment` XML tag within that given tag. This redundant child-node access resulted in the following error- / notice-message: `PHP Notice:  Trying to access array offset on value of type null in /foo/bar/baz/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx/Styles.php on line 146`

These changes remove the redundant child-node access in the method `readAlignmentStyle`.
This commit is contained in:
Gerrit Addiks 2021-01-31 18:36:23 +01:00 committed by GitHub
parent fdc8e8d17a
commit cade11f668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 10 deletions

View File

@ -143,21 +143,21 @@ class Styles extends BaseParserClass
private static function readAlignmentStyle(Alignment $alignment, SimpleXMLElement $alignmentXml): void private static function readAlignmentStyle(Alignment $alignment, SimpleXMLElement $alignmentXml): void
{ {
$alignment->setHorizontal((string) $alignmentXml->alignment['horizontal']); $alignment->setHorizontal((string) $alignmentXml['horizontal']);
$alignment->setVertical((string) $alignmentXml->alignment['vertical']); $alignment->setVertical((string) $alignmentXml['vertical']);
$textRotation = 0; $textRotation = 0;
if ((int) $alignmentXml->alignment['textRotation'] <= 90) { if ((int) $alignmentXml['textRotation'] <= 90) {
$textRotation = (int) $alignmentXml->alignment['textRotation']; $textRotation = (int) $alignmentXml['textRotation'];
} elseif ((int) $alignmentXml->alignment['textRotation'] > 90) { } elseif ((int) $alignmentXml['textRotation'] > 90) {
$textRotation = 90 - (int) $alignmentXml->alignment['textRotation']; $textRotation = 90 - (int) $alignmentXml['textRotation'];
} }
$alignment->setTextRotation((int) $textRotation); $alignment->setTextRotation((int) $textRotation);
$alignment->setWrapText(self::boolean((string) $alignmentXml->alignment['wrapText'])); $alignment->setWrapText(self::boolean((string) $alignmentXml['wrapText']));
$alignment->setShrinkToFit(self::boolean((string) $alignmentXml->alignment['shrinkToFit'])); $alignment->setShrinkToFit(self::boolean((string) $alignmentXml['shrinkToFit']));
$alignment->setIndent((int) ((string) $alignmentXml->alignment['indent']) > 0 ? (int) ((string) $alignmentXml->alignment['indent']) : 0); $alignment->setIndent((int) ((string) $alignmentXml['indent']) > 0 ? (int) ((string) $alignmentXml['indent']) : 0);
$alignment->setReadOrder((int) ((string) $alignmentXml->alignment['readingOrder']) > 0 ? (int) ((string) $alignmentXml->alignment['readingOrder']) : 0); $alignment->setReadOrder((int) ((string) $alignmentXml['readingOrder']) > 0 ? (int) ((string) $alignmentXml['readingOrder']) : 0);
} }
private function readStyle(Style $docStyle, $style): void private function readStyle(Style $docStyle, $style): void