Fix XLSX broken vertical align font style (#2619)

* Fix XLSX broken vertical align font style

* Add fix information to changelog

* Fix phpcs issues
This commit is contained in:
Thorsten Ho 2022-02-24 05:23:59 +01:00 committed by GitHub
parent 579145eb3c
commit 0cb60a5098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 1 deletions

View File

@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Fixed
- Fixed behaviour of XLSX font style vertical align settings
## 1.22.0 - 2022-02-18
### Added

View File

@ -119,7 +119,7 @@ class Styles extends BaseParserClass
}
if (isset($fontStyleXml->vertAlign)) {
$attr = $this->getStyleAttributes($fontStyleXml->vertAlign);
if (!isset($attr['val'])) {
if (isset($attr['val'])) {
$verticalAlign = strtolower((string) $attr['val']);
if ($verticalAlign === 'superscript') {
$fontStyle->setSuperscript(true);

View File

@ -0,0 +1,25 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PHPUnit\Framework\TestCase;
class VerticalAlignTest extends TestCase
{
public function testVerticalAlignStyle(): void
{
$filename = 'tests/data/Reader/XLSX/verticalAlignTest.xlsx';
$reader = IOFactory::createReader('Xlsx');
$sheet = $reader->load($filename)->getActiveSheet();
self::assertTrue($sheet->getCell('A1')->getStyle()->getFont()->getSuperscript());
self::assertFalse($sheet->getCell('A1')->getStyle()->getFont()->getSubscript());
self::assertTrue($sheet->getCell('B1')->getStyle()->getFont()->getSubscript());
self::assertFalse($sheet->getCell('B1')->getStyle()->getFont()->getSuperscript());
self::assertFalse($sheet->getCell('C1')->getStyle()->getFont()->getSubscript());
self::assertFalse($sheet->getCell('C1')->getStyle()->getFont()->getSuperscript());
}
}

Binary file not shown.