Skip to content

Commit 4561f41

Browse files
committed
support justifyLastLine
1 parent 87ddd21 commit 4561f41

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/PhpSpreadsheet/Reader/Xlsx/Styles.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ public function readAlignmentStyle(Alignment $alignment, SimpleXMLElement $align
241241
if ($horizontal !== '') {
242242
$alignment->setHorizontal($horizontal);
243243
}
244+
$justifyLastLine = (string) $this->getAttribute($alignmentXml, 'justifyLastLine');
245+
$alignment->setJustifyLastLine(self::boolean($justifyLastLine));
244246
$vertical = (string) $this->getAttribute($alignmentXml, 'vertical');
245247
if ($vertical !== '') {
246248
$alignment->setVertical($vertical);

src/PhpSpreadsheet/Style/Alignment.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ class Alignment extends Supervisor
9797
*/
9898
protected ?string $horizontal = self::HORIZONTAL_GENERAL;
9999

100+
/**
101+
* Justify Last Line alignment.
102+
*/
103+
protected ?string $justifyLastLine = null;
104+
100105
/**
101106
* Vertical alignment.
102107
*/
@@ -196,6 +201,9 @@ public function applyFromArray(array $styleArray): static
196201
if (isset($styleArray['horizontal'])) {
197202
$this->setHorizontal($styleArray['horizontal']);
198203
}
204+
if (isset($styleArray['justifyLastLine'])) {
205+
$this->setJustifyLastLine($styleArray['justifyLastLine']);
206+
}
199207
if (isset($styleArray['vertical'])) {
200208
$this->setVertical($styleArray['vertical']);
201209
}
@@ -255,6 +263,37 @@ public function setHorizontal(string $horizontalAlignment): static
255263
return $this;
256264
}
257265

266+
/**
267+
* Get Justify Last Line.
268+
*/
269+
public function getJustifyLastLine(): null|string
270+
{
271+
if ($this->isSupervisor) {
272+
return $this->getSharedComponent()->getJustifyLastLine();
273+
}
274+
275+
return $this->justifyLastLine;
276+
}
277+
278+
/**
279+
* Set Justify Last Line.
280+
*
281+
* @param string $justifyLastLine see self::HORIZONTAL_*
282+
*
283+
* @return $this
284+
*/
285+
public function setJustifyLastLine(string $justifyLastLine): static
286+
{
287+
if ($this->isSupervisor) {
288+
$styleArray = $this->getStyleArray(['justifyLastLine' => $justifyLastLine]);
289+
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
290+
} else {
291+
$this->justifyLastLine = $justifyLastLine;
292+
}
293+
294+
return $this;
295+
}
296+
258297
/**
259298
* Get Vertical.
260299
*/
@@ -489,6 +528,7 @@ protected function exportArray1(): array
489528
{
490529
$exportedArray = [];
491530
$this->exportArray2($exportedArray, 'horizontal', $this->getHorizontal());
531+
$this->exportArray2($exportedArray, 'justifyLastLine', $this->getJustifyLastLine());
492532
$this->exportArray2($exportedArray, 'indent', $this->getIndent());
493533
$this->exportArray2($exportedArray, 'readOrder', $this->getReadOrder());
494534
$this->exportArray2($exportedArray, 'shrinkToFit', $this->getShrinkToFit());

src/PhpSpreadsheet/Writer/Xlsx/Style.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ private function writeCellStyleXf(XMLWriter $objWriter, \PhpOffice\PhpSpreadshee
454454
if ($vertical !== '') {
455455
$objWriter->writeAttribute('vertical', $vertical);
456456
}
457+
if ($style->getAlignment()->getJustifyLastLine()) {
458+
$objWriter->writeAttribute('justifyLastLine', '1');
459+
}
457460

458461
if ($style->getAlignment()->getTextRotation() >= 0) {
459462
$textRotation = $style->getAlignment()->getTextRotation();

0 commit comments

Comments
 (0)