Skip to content

Commit 0cb60a5

Browse files
authored
Fix XLSX broken vertical align font style (#2619)
* Fix XLSX broken vertical align font style * Add fix information to changelog * Fix phpcs issues
1 parent 579145e commit 0cb60a5

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2525

2626
### Fixed
2727

28+
- Fixed behaviour of XLSX font style vertical align settings
29+
2830
## 1.22.0 - 2022-02-18
2931

3032
### Added

src/PhpSpreadsheet/Reader/Xlsx/Styles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function readFontStyle(Font $fontStyle, SimpleXMLElement $fontStyleXml):
119119
}
120120
if (isset($fontStyleXml->vertAlign)) {
121121
$attr = $this->getStyleAttributes($fontStyleXml->vertAlign);
122-
if (!isset($attr['val'])) {
122+
if (isset($attr['val'])) {
123123
$verticalAlign = strtolower((string) $attr['val']);
124124
if ($verticalAlign === 'superscript') {
125125
$fontStyle->setSuperscript(true);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
4+
5+
use PhpOffice\PhpSpreadsheet\IOFactory;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class VerticalAlignTest extends TestCase
9+
{
10+
public function testVerticalAlignStyle(): void
11+
{
12+
$filename = 'tests/data/Reader/XLSX/verticalAlignTest.xlsx';
13+
$reader = IOFactory::createReader('Xlsx');
14+
$sheet = $reader->load($filename)->getActiveSheet();
15+
16+
self::assertTrue($sheet->getCell('A1')->getStyle()->getFont()->getSuperscript());
17+
self::assertFalse($sheet->getCell('A1')->getStyle()->getFont()->getSubscript());
18+
19+
self::assertTrue($sheet->getCell('B1')->getStyle()->getFont()->getSubscript());
20+
self::assertFalse($sheet->getCell('B1')->getStyle()->getFont()->getSuperscript());
21+
22+
self::assertFalse($sheet->getCell('C1')->getStyle()->getFont()->getSubscript());
23+
self::assertFalse($sheet->getCell('C1')->getStyle()->getFont()->getSuperscript());
24+
}
25+
}
9.51 KB
Binary file not shown.

0 commit comments

Comments
 (0)