Skip to content

Commit

Permalink
Writer ODS : Write Border Style for cells (Replaced protected by priv…
Browse files Browse the repository at this point in the history
…ate && Added Unit Test)
  • Loading branch information
Progi1984 committed Sep 13, 2023
1 parent 73dc1d3 commit 53f8860
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Writer/Ods/Cell/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,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:
Expand All @@ -113,7 +113,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:
Expand Down
40 changes: 40 additions & 0 deletions tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

namespace PhpOffice\PhpSpreadsheetTests\Writer\Ods;

use DOMDocument;
use DOMXPath;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
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;
Expand Down Expand Up @@ -124,4 +127,41 @@ 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();

$xmlDoc = new DOMDocument();
$xmlDoc->loadXML($xml);
$xmlPath = new DOMXPath($xmlDoc);

foreach (['top', 'bottom'] as $keyRow => $row) {
foreach (['left', 'right'] as $keyCell => $cell) {
$styles = ['top' => '', 'bottom' => '', 'left' => '', 'right' => ''];
$styles[$row] = '2.5pt solid #22DD00';
$styles[$cell] = '2.5pt solid #22DD00';

$query = 'string(//office:document-content/office:body/office:spreadsheet/table:table/table:table-row[position()=' . ($keyRow + 1) . ']/table:table-cell[position()=' . ($keyCell + 1) . ']/@table:style-name)';
$idStyle = $xmlPath->evaluate($query);

foreach ($styles as $direction => $value) {
$query = 'string(//office:document-content/office:automatic-styles/style:style[@style:name="' . $idStyle . '"]/style:table-cell-properties/@fo:border-' . $direction . ')';
$style = $xmlPath->evaluate($query);
self::assertEquals($style, $value);
}
}
}
}
}

0 comments on commit 53f8860

Please sign in to comment.