Writer\Ods\Content: Fix CS

This commit is contained in:
Paolo Agostinetto 2017-03-04 16:35:53 +01:00
parent 4efda2a512
commit 93b5337bda
2 changed files with 24 additions and 31 deletions

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Writer\Ods; namespace PhpOffice\PhpSpreadsheet\Writer\Ods;
/** /*
* PhpSpreadsheet. * PhpSpreadsheet.
* *
* Copyright (c) 2006 - 2015 PhpSpreadsheet * Copyright (c) 2006 - 2015 PhpSpreadsheet
@ -28,18 +28,19 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Ods;
*/ */
use PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Cell;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Fill; use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Font; use PhpOffice\PhpSpreadsheet\Style\Font;
use PhpOffice\PhpSpreadsheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Writer\Exception; use PhpOffice\PhpSpreadsheet\Writer\Exception;
use PhpOffice\PhpSpreadsheet\Writer\Ods; use PhpOffice\PhpSpreadsheet\Writer\Ods;
use PhpOffice\PhpSpreadsheet\Writer\Ods\Cell\Comment; use PhpOffice\PhpSpreadsheet\Writer\Ods\Cell\Comment;
/** /**
* @category PhpSpreadsheet * @category PhpSpreadsheet
*
* @method Ods getParentWriter * @method Ods getParentWriter
* *
* @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
@ -200,7 +201,6 @@ class Content extends WriterPart
$prevColumn = -1; $prevColumn = -1;
$cells = $row->getCellIterator(); $cells = $row->getCellIterator();
while ($cells->valid()) { while ($cells->valid()) {
/** @var Cell $cell */ /** @var Cell $cell */
$cell = $cells->current(); $cell = $cells->current();
$column = Cell::columnIndexFromString($cell->getColumn()) - 1; $column = Cell::columnIndexFromString($cell->getColumn()) - 1;
@ -210,8 +210,8 @@ class Content extends WriterPart
// Style XF // Style XF
$style = $cell->getXfIndex(); $style = $cell->getXfIndex();
if($style !== null){ if ($style !== null) {
$objWriter->writeAttribute('table:style-name', self::CELL_STYLE_PREFIX.$style); $objWriter->writeAttribute('table:style-name', self::CELL_STYLE_PREFIX . $style);
} }
switch ($cell->getDataType()) { switch ($cell->getDataType()) {
@ -288,15 +288,14 @@ class Content extends WriterPart
} }
/** /**
* Write XF cell styles * Write XF cell styles.
* *
* @param XMLWriter $writer * @param XMLWriter $writer
* @param Spreadsheet $spreadsheet * @param Spreadsheet $spreadsheet
*/ */
private function writeXfStyles(XMLWriter $writer, Spreadsheet $spreadsheet) private function writeXfStyles(XMLWriter $writer, Spreadsheet $spreadsheet)
{ {
foreach($spreadsheet->getCellXfCollection() as $style) { foreach ($spreadsheet->getCellXfCollection() as $style) {
$writer->startElement('style:style'); $writer->startElement('style:style');
$writer->writeAttribute('style:name', self::CELL_STYLE_PREFIX . $style->getIndex()); $writer->writeAttribute('style:name', self::CELL_STYLE_PREFIX . $style->getIndex());
$writer->writeAttribute('style:family', 'table-cell'); $writer->writeAttribute('style:family', 'table-cell');
@ -311,40 +310,37 @@ class Content extends WriterPart
$font = $style->getFont(); $font = $style->getFont();
if($font->getBold()) { if ($font->getBold()) {
$writer->writeAttribute('fo:font-weight', 'bold'); $writer->writeAttribute('fo:font-weight', 'bold');
$writer->writeAttribute('style:font-weight-complex', 'bold'); $writer->writeAttribute('style:font-weight-complex', 'bold');
$writer->writeAttribute('style:font-weight-asian', 'bold'); $writer->writeAttribute('style:font-weight-asian', 'bold');
} }
if($font->getItalic()) { if ($font->getItalic()) {
$writer->writeAttribute('fo:font-style', 'italic'); $writer->writeAttribute('fo:font-style', 'italic');
} }
if($color = $font->getColor()) { if ($color = $font->getColor()) {
$writer->writeAttribute('fo:color', sprintf('#%s', $color->getRGB())); $writer->writeAttribute('fo:color', sprintf('#%s', $color->getRGB()));
} }
if($family = $font->getName()) { if ($family = $font->getName()) {
$writer->writeAttribute('fo:font-family', $family); $writer->writeAttribute('fo:font-family', $family);
} }
if($size = $font->getSize()) { if ($size = $font->getSize()) {
$writer->writeAttribute('fo:font-size', sprintf('%.1fpt', $size)); $writer->writeAttribute('fo:font-size', sprintf('%.1fpt', $size));
} }
if($font->getUnderline() && $font->getUnderline() != Font::UNDERLINE_NONE) { if ($font->getUnderline() && $font->getUnderline() != Font::UNDERLINE_NONE) {
$writer->writeAttribute('style:text-underline-style', 'solid'); $writer->writeAttribute('style:text-underline-style', 'solid');
$writer->writeAttribute('style:text-underline-width', 'auto'); $writer->writeAttribute('style:text-underline-width', 'auto');
$writer->writeAttribute('style:text-underline-color', 'font-color'); $writer->writeAttribute('style:text-underline-color', 'font-color');
switch($font->getUnderline()){ switch ($font->getUnderline()) {
case Font::UNDERLINE_DOUBLE: case Font::UNDERLINE_DOUBLE:
$writer->writeAttribute('style:text-underline-type', 'double'); $writer->writeAttribute('style:text-underline-type', 'double');
break; break;
case Font::UNDERLINE_SINGLE: case Font::UNDERLINE_SINGLE:
$writer->writeAttribute('style:text-underline-type', 'single'); $writer->writeAttribute('style:text-underline-type', 'single');
break; break;
@ -361,20 +357,18 @@ class Content extends WriterPart
$writer->writeAttribute('style:rotation-align', 'none'); $writer->writeAttribute('style:rotation-align', 'none');
// Fill // Fill
if($fill = $style->getFill()) { if ($fill = $style->getFill()) {
switch($fill->getFillType()) { switch ($fill->getFillType()) {
case Fill::FILL_SOLID: case Fill::FILL_SOLID:
$writer->writeAttribute('fo:background-color', sprintf('#%s', $writer->writeAttribute('fo:background-color', sprintf(
'#%s',
strtolower($fill->getStartColor()->getRGB()) strtolower($fill->getStartColor()->getRGB())
)); ));
break; break;
case Fill::FILL_GRADIENT_LINEAR: case Fill::FILL_GRADIENT_LINEAR:
case Fill::FILL_GRADIENT_PATH: case Fill::FILL_GRADIENT_PATH:
/// TODO :: To be implemented /// TODO :: To be implemented
break; break;
case Fill::FILL_NONE: case Fill::FILL_NONE:
default: default:
} }

View File

@ -11,7 +11,6 @@ use PhpOffice\PhpSpreadsheet\Style\Font;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Writer\Ods; use PhpOffice\PhpSpreadsheet\Writer\Ods;
use PhpOffice\PhpSpreadsheet\Writer\Ods\Content; use PhpOffice\PhpSpreadsheet\Writer\Ods\Content;
use PhpOffice\PhpSpreadsheetTests\Worksheet\WorksheetColumnTest;
class ContentTest extends \PHPUnit_Framework_TestCase class ContentTest extends \PHPUnit_Framework_TestCase
{ {
@ -24,7 +23,7 @@ class ContentTest extends \PHPUnit_Framework_TestCase
$xml = $content->write(); $xml = $content->write();
$this->assertXmlStringEqualsXmlFile($this->samplesPath . "/content-empty.xml", $xml); $this->assertXmlStringEqualsXmlFile($this->samplesPath . '/content-empty.xml', $xml);
} }
public function testWriteSpreadsheet() public function testWriteSpreadsheet()
@ -35,9 +34,9 @@ class ContentTest extends \PHPUnit_Framework_TestCase
$worksheet1 = $workbook->getActiveSheet(); $worksheet1 = $workbook->getActiveSheet();
$worksheet1->setCellValue('A1', 1); // Number $worksheet1->setCellValue('A1', 1); // Number
$worksheet1->setCellValue('B1', 12345.6789); // Number $worksheet1->setCellValue('B1', 12345.6789); // Number
$worksheet1->setCellValue('C1', "1"); // Number without cast $worksheet1->setCellValue('C1', '1'); // Number without cast
$worksheet1->setCellValueExplicit('D1', "01234", DataType::TYPE_STRING); // Number casted to string $worksheet1->setCellValueExplicit('D1', '01234', DataType::TYPE_STRING); // Number casted to string
$worksheet1->setCellValue('E1', "Lorem ipsum"); // String $worksheet1->setCellValue('E1', 'Lorem ipsum'); // String
$worksheet1->setCellValue('A2', true); // Boolean $worksheet1->setCellValue('A2', true); // Boolean
$worksheet1->setCellValue('B2', false); // Boolean $worksheet1->setCellValue('B2', false); // Boolean
@ -51,7 +50,7 @@ class ContentTest extends \PHPUnit_Framework_TestCase
// Styles // Styles
$worksheet1->getStyle('A1')->getFont()->setBold(true); $worksheet1->getStyle('A1')->getFont()->setBold(true);
$worksheet1->getStyle('B1')->getFont()->setItalic(true); $worksheet1->getStyle('B1')->getFont()->setItalic(true);
$worksheet1->getStyle('C1')->getFont()->setName("Courier"); $worksheet1->getStyle('C1')->getFont()->setName('Courier');
$worksheet1->getStyle('C1')->getFont()->setSize(14); $worksheet1->getStyle('C1')->getFont()->setSize(14);
$worksheet1->getStyle('C1')->getFont()->setColor(new Color(Color::COLOR_BLUE)); $worksheet1->getStyle('C1')->getFont()->setColor(new Color(Color::COLOR_BLUE));
@ -73,6 +72,6 @@ class ContentTest extends \PHPUnit_Framework_TestCase
$xml = $content->write(); $xml = $content->write();
$this->assertXmlStringEqualsXmlFile($this->samplesPath . "/content-with-data.xml", $xml); $this->assertXmlStringEqualsXmlFile($this->samplesPath . '/content-with-data.xml', $xml);
} }
} }