mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-05 06:58:15 +00:00
Polishing Up
This commit is contained in:
@@ -266,7 +266,11 @@ class Styles extends BaseParserClass
|
||||
$alignment->setHorizontal($horizontal);
|
||||
}
|
||||
$justifyLastLine = (string) $this->getAttribute($alignmentXml, 'justifyLastLine');
|
||||
$alignment->setJustifyLastLine(self::boolean($justifyLastLine));
|
||||
if ($justifyLastLine !== '') {
|
||||
$alignment->setJustifyLastLine(
|
||||
self::boolean($justifyLastLine)
|
||||
);
|
||||
}
|
||||
$vertical = (string) $this->getAttribute($alignmentXml, 'vertical');
|
||||
if ($vertical !== '') {
|
||||
$alignment->setVertical($vertical);
|
||||
|
||||
@@ -512,7 +512,7 @@ class Alignment extends Supervisor
|
||||
|
||||
return md5(
|
||||
$this->horizontal
|
||||
. $this->justifyLastLine
|
||||
. (($this->justifyLastLine === null) ? 'null' : ($this->justifyLastLine ? 't' : 'f'))
|
||||
. $this->vertical
|
||||
. $this->textRotation
|
||||
. ($this->wrapText ? 't' : 'f')
|
||||
|
||||
@@ -457,8 +457,9 @@ class Style extends WriterPart
|
||||
if ($vertical !== '') {
|
||||
$objWriter->writeAttribute('vertical', $vertical);
|
||||
}
|
||||
if ($style->getAlignment()->getJustifyLastLine()) {
|
||||
$objWriter->writeAttribute('justifyLastLine', '1');
|
||||
$justifyLastLine = $style->getAlignment()->getJustifyLastLine();
|
||||
if (is_bool($justifyLastLine)) {
|
||||
$objWriter->writeAttribute('justifyLastLine', (string) (int) $justifyLastLine);
|
||||
}
|
||||
|
||||
if ($style->getAlignment()->getTextRotation() >= 0) {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
|
||||
|
||||
class AlignmentTest extends AbstractFunctional
|
||||
{
|
||||
private ?Spreadsheet $spreadsheet = null;
|
||||
|
||||
private ?Spreadsheet $reloadedSpreadsheet = null;
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if ($this->spreadsheet !== null) {
|
||||
$this->spreadsheet->disconnectWorksheets();
|
||||
$this->spreadsheet = null;
|
||||
}
|
||||
if ($this->reloadedSpreadsheet !== null) {
|
||||
$this->reloadedSpreadsheet->disconnectWorksheets();
|
||||
$this->reloadedSpreadsheet = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function testJustifyLastLine(): void
|
||||
{
|
||||
$this->spreadsheet = new Spreadsheet();
|
||||
$sheet = $this->spreadsheet->getActiveSheet();
|
||||
$sheet->setCellValue('A1', 'ABC');
|
||||
$sheet->setCellValue('A2', 'DEF');
|
||||
$sheet->setCellValue('A3', 'GHI');
|
||||
$sheet->getStyle('A1')
|
||||
->getAlignment()
|
||||
->setHorizontal(Alignment::HORIZONTAL_DISTRIBUTED)
|
||||
->setJustifyLastLine(true);
|
||||
$sheet->getStyle('A2')
|
||||
->getAlignment()
|
||||
->setHorizontal(Alignment::HORIZONTAL_DISTRIBUTED)
|
||||
->setJustifyLastLine(false);
|
||||
$sheet->getStyle('A3')
|
||||
->getAlignment()
|
||||
->setHorizontal(Alignment::HORIZONTAL_DISTRIBUTED);
|
||||
$this->reloadedSpreadsheet = $this->writeAndReload($this->spreadsheet, 'Xlsx');
|
||||
$rsheet = $this->reloadedSpreadsheet->getActiveSheet();
|
||||
self::assertTrue(
|
||||
$rsheet->getStyle('A1')
|
||||
->getAlignment()
|
||||
->getJustifyLastLine()
|
||||
);
|
||||
self::assertFalse(
|
||||
$rsheet->getStyle('A2')
|
||||
->getAlignment()
|
||||
->getJustifyLastLine()
|
||||
);
|
||||
self::assertNull(
|
||||
$rsheet->getStyle('A3')
|
||||
->getAlignment()
|
||||
->getJustifyLastLine()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class Issue3443Test extends AbstractFunctional
|
||||
$rsheet = $reloadedSpreadsheet->getActiveSheet();
|
||||
$expected1 = [
|
||||
'horizontal' => 'center',
|
||||
'justifyLastLine' => false,
|
||||
'justifyLastLine' => null,
|
||||
'indent' => 0,
|
||||
'readOrder' => 0,
|
||||
'shrinkToFit' => false,
|
||||
@@ -79,7 +79,7 @@ class Issue3443Test extends AbstractFunctional
|
||||
$rsheet = $reloadedSpreadsheet->getActiveSheet();
|
||||
$expected1 = [
|
||||
'horizontal' => 'general',
|
||||
'justifyLastLine' => false,
|
||||
'justifyLastLine' => null,
|
||||
'indent' => 0,
|
||||
'readOrder' => 0,
|
||||
'shrinkToFit' => false,
|
||||
|
||||
Reference in New Issue
Block a user