From 16144f8381676a943821d8d0442cb6a76017cf69 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Wed, 30 Aug 2023 08:47:40 +0200 Subject: [PATCH] Writer ODS : Write Border Style for cells (Replaced protected by private && Added Unit Test) --- src/PhpSpreadsheet/Writer/Ods/Cell/Style.php | 4 +- .../Writer/Ods/ContentTest.php | 19 +++++ .../Writer/Ods/content-table-with-style.xml | 85 +++++++++++++++++++ 3 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 tests/data/Writer/Ods/content-table-with-style.xml diff --git a/src/PhpSpreadsheet/Writer/Ods/Cell/Style.php b/src/PhpSpreadsheet/Writer/Ods/Cell/Style.php index 2080c352ac..9a92beae87 100644 --- a/src/PhpSpreadsheet/Writer/Ods/Cell/Style.php +++ b/src/PhpSpreadsheet/Writer/Ods/Cell/Style.php @@ -102,7 +102,7 @@ private function writeBorderStyle(string $direction, Border $border): void )); } - protected function mapBorderWidth(Border $border): string + private function mapBorderWidth(Border $border): string { switch ($border->getBorderStyle()) { case Border::BORDER_THIN: @@ -126,7 +126,7 @@ protected function mapBorderWidth(Border $border): string return '1pt'; } - protected function mapBorderStyle(Border $border): string + private function mapBorderStyle(Border $border): string { switch ($border->getBorderStyle()) { case Border::BORDER_DOTTED: diff --git a/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php b/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php index 81c244a768..77f7ec6de9 100644 --- a/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php @@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Color; use PhpOffice\PhpSpreadsheet\Style\Fill; use PhpOffice\PhpSpreadsheet\Style\Font; @@ -129,4 +130,22 @@ public function testWriteWithHiddenWorksheet(): void self::assertXmlStringEqualsXmlFile($this->samplesPath . '/content-hidden-worksheet.xml', $xml); } + + public function testWriteBorderStyle(): void + { + $spreadsheet = new Spreadsheet(); + $spreadsheet->getActiveSheet()->getStyle('A1:B2')->applyFromArray([ + 'borders' => [ + 'outline' => [ + 'borderStyle' => Border::BORDER_THICK, + 'color' => ['argb' => 'AA22DD00'], + ], + ], + ]); + + $content = new Content(new Ods($spreadsheet)); + $xml = $content->write(); + + self::assertXmlStringEqualsXmlFile($this->samplesPath . '/content-table-with-style.xml', $xml); + } } diff --git a/tests/data/Writer/Ods/content-table-with-style.xml b/tests/data/Writer/Ods/content-table-with-style.xml new file mode 100644 index 0000000000..2855733065 --- /dev/null +++ b/tests/data/Writer/Ods/content-table-with-style.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file