Skip to content

Commit f366749

Browse files
committed
Polishing Up
1 parent bee8916 commit f366749

File tree

5 files changed

+76
-6
lines changed

5 files changed

+76
-6
lines changed

src/PhpSpreadsheet/Reader/Xlsx/Styles.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ public function readAlignmentStyle(Alignment $alignment, SimpleXMLElement $align
266266
$alignment->setHorizontal($horizontal);
267267
}
268268
$justifyLastLine = (string) $this->getAttribute($alignmentXml, 'justifyLastLine');
269-
$alignment->setJustifyLastLine(self::boolean($justifyLastLine));
269+
if ($justifyLastLine !== '') {
270+
$alignment->setJustifyLastLine(
271+
self::boolean($justifyLastLine)
272+
);
273+
}
270274
$vertical = (string) $this->getAttribute($alignmentXml, 'vertical');
271275
if ($vertical !== '') {
272276
$alignment->setVertical($vertical);

src/PhpSpreadsheet/Style/Alignment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ public function getHashCode(): string
512512

513513
return md5(
514514
$this->horizontal
515-
. $this->justifyLastLine
515+
. (($this->justifyLastLine === null) ? 'null' : ($this->justifyLastLine ? 't' : 'f'))
516516
. $this->vertical
517517
. $this->textRotation
518518
. ($this->wrapText ? 't' : 'f')

src/PhpSpreadsheet/Writer/Xlsx/Style.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,9 @@ private function writeCellStyleXf(XMLWriter $objWriter, \PhpOffice\PhpSpreadshee
457457
if ($vertical !== '') {
458458
$objWriter->writeAttribute('vertical', $vertical);
459459
}
460-
if ($style->getAlignment()->getJustifyLastLine()) {
461-
$objWriter->writeAttribute('justifyLastLine', '1');
460+
$justifyLastLine = $style->getAlignment()->getJustifyLastLine();
461+
if (is_bool($justifyLastLine)) {
462+
$objWriter->writeAttribute('justifyLastLine', (string) (int) $justifyLastLine);
462463
}
463464

464465
if ($style->getAlignment()->getTextRotation() >= 0) {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
6+
7+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
8+
use PhpOffice\PhpSpreadsheet\Style\Alignment;
9+
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
10+
11+
class AlignmentTest extends AbstractFunctional
12+
{
13+
private ?Spreadsheet $spreadsheet = null;
14+
15+
private ?Spreadsheet $reloadedSpreadsheet = null;
16+
17+
protected function tearDown(): void
18+
{
19+
if ($this->spreadsheet !== null) {
20+
$this->spreadsheet->disconnectWorksheets();
21+
$this->spreadsheet = null;
22+
}
23+
if ($this->reloadedSpreadsheet !== null) {
24+
$this->reloadedSpreadsheet->disconnectWorksheets();
25+
$this->reloadedSpreadsheet = null;
26+
}
27+
}
28+
29+
public function testJustifyLastLine(): void
30+
{
31+
$this->spreadsheet = new Spreadsheet();
32+
$sheet = $this->spreadsheet->getActiveSheet();
33+
$sheet->setCellValue('A1', 'ABC');
34+
$sheet->setCellValue('A2', 'DEF');
35+
$sheet->setCellValue('A3', 'GHI');
36+
$sheet->getStyle('A1')
37+
->getAlignment()
38+
->setHorizontal(Alignment::HORIZONTAL_DISTRIBUTED)
39+
->setJustifyLastLine(true);
40+
$sheet->getStyle('A2')
41+
->getAlignment()
42+
->setHorizontal(Alignment::HORIZONTAL_DISTRIBUTED)
43+
->setJustifyLastLine(false);
44+
$sheet->getStyle('A3')
45+
->getAlignment()
46+
->setHorizontal(Alignment::HORIZONTAL_DISTRIBUTED);
47+
$this->reloadedSpreadsheet = $this->writeAndReload($this->spreadsheet, 'Xlsx');
48+
$rsheet = $this->reloadedSpreadsheet->getActiveSheet();
49+
self::assertTrue(
50+
$rsheet->getStyle('A1')
51+
->getAlignment()
52+
->getJustifyLastLine()
53+
);
54+
self::assertFalse(
55+
$rsheet->getStyle('A2')
56+
->getAlignment()
57+
->getJustifyLastLine()
58+
);
59+
self::assertNull(
60+
$rsheet->getStyle('A3')
61+
->getAlignment()
62+
->getJustifyLastLine()
63+
);
64+
}
65+
}

tests/PhpSpreadsheetTests/Writer/Xlsx/Issue3443Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testNonDefaultAlign(): void
3737
$rsheet = $reloadedSpreadsheet->getActiveSheet();
3838
$expected1 = [
3939
'horizontal' => 'center',
40-
'justifyLastLine' => false,
40+
'justifyLastLine' => null,
4141
'indent' => 0,
4242
'readOrder' => 0,
4343
'shrinkToFit' => false,
@@ -79,7 +79,7 @@ public function testDefaultAlign(): void
7979
$rsheet = $reloadedSpreadsheet->getActiveSheet();
8080
$expected1 = [
8181
'horizontal' => 'general',
82-
'justifyLastLine' => false,
82+
'justifyLastLine' => null,
8383
'indent' => 0,
8484
'readOrder' => 0,
8585
'shrinkToFit' => false,

0 commit comments

Comments
 (0)