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 7, 2023
1 parent bdecce2 commit 16144f8
Show file tree
Hide file tree
Showing 3 changed files with 106 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 @@ -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:
Expand All @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
85 changes: 85 additions & 0 deletions tests/data/Writer/Ods/content-table-with-style.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
xmlns:math="http://www.w3.org/1998/Math/MathML"
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
xmlns:ooo="http://openoffice.org/2004/office"
xmlns:ooow="http://openoffice.org/2004/writer"
xmlns:oooc="http://openoffice.org/2004/calc"
xmlns:dom="http://www.w3.org/2001/xml-events"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rpt="http://openoffice.org/2005/report"
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:grddl="http://www.w3.org/2003/g/data-view#"
xmlns:tableooo="http://openoffice.org/2009/table"
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
<office:scripts/>
<office:font-face-decls/>
<office:automatic-styles>
<style:style style:family="table" style:name="ta1">
<style:table-properties table:display="true"/>
</style:style>
<style:style style:name="ce0" style:family="table-cell" style:parent-style-name="Default">
<style:table-cell-properties style:vertical-align="bottom" style:rotation-align="none"/>
<style:paragraph-properties fo:text-align="start"/>
<style:text-properties fo:color="#000000" fo:font-family="Calibri" fo:font-size="11.0pt"/>
</style:style>
<style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default">
<style:table-cell-properties style:vertical-align="bottom" style:rotation-align="none" fo:border-left="2.5pt solid #22DD00" fo:border-top="2.5pt solid #22DD00"/>
<style:paragraph-properties fo:text-align="start"/>
<style:text-properties fo:color="#000000" fo:font-family="Calibri" fo:font-size="11.0pt"/>
</style:style>
<style:style style:name="ce2" style:family="table-cell" style:parent-style-name="Default">
<style:table-cell-properties style:vertical-align="bottom" style:rotation-align="none" fo:border-bottom="2.5pt solid #22DD00" fo:border-left="2.5pt solid #22DD00"/>
<style:paragraph-properties fo:text-align="start"/>
<style:text-properties fo:color="#000000" fo:font-family="Calibri" fo:font-size="11.0pt"/>
</style:style>
<style:style style:name="ce3" style:family="table-cell" style:parent-style-name="Default">
<style:table-cell-properties style:vertical-align="bottom" style:rotation-align="none" fo:border-right="2.5pt solid #22DD00" fo:border-top="2.5pt solid #22DD00"/>
<style:paragraph-properties fo:text-align="start"/>
<style:text-properties fo:color="#000000" fo:font-family="Calibri" fo:font-size="11.0pt"/>
</style:style>
<style:style style:name="ce4" style:family="table-cell" style:parent-style-name="Default">
<style:table-cell-properties style:vertical-align="bottom" style:rotation-align="none" fo:border-bottom="2.5pt solid #22DD00" fo:border-right="2.5pt solid #22DD00"/>
<style:paragraph-properties fo:text-align="start"/>
<style:text-properties fo:color="#000000" fo:font-family="Calibri" fo:font-size="11.0pt"/>
</style:style>
</office:automatic-styles>
<office:body>
<office:spreadsheet>
<table:calculation-settings/>
<table:table table:name="Worksheet" table:style-name="ta1">
<office:forms/>
<table:table-row>
<table:table-cell table:style-name="ce1"/>
<table:table-cell table:style-name="ce3"/>
<table:table-cell table:number-columns-repeated="1022"/>
</table:table-row>
<table:table-row>
<table:table-cell table:style-name="ce2"/>
<table:table-cell table:style-name="ce4"/>
<table:table-cell table:number-columns-repeated="1022"/>
</table:table-row>
</table:table>
<table:named-expressions/>
</office:spreadsheet>
</office:body>
</office:document-content>

0 comments on commit 16144f8

Please sign in to comment.