first changes
This commit is contained in:
parent
97cdd0c627
commit
46c8e77cea
@ -26,7 +26,7 @@ class Row
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Row constructor.
|
* Row constructor.
|
||||||
* @param array $cells
|
* @param Cell[] $cells
|
||||||
* @param Style|null $style
|
* @param Style|null $style
|
||||||
*/
|
*/
|
||||||
public function __construct(array $cells = [], Style $style = null)
|
public function __construct(array $cells = [], Style $style = null)
|
||||||
@ -39,7 +39,7 @@ class Row
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return Cell[] $cells
|
||||||
*/
|
*/
|
||||||
public function getCells()
|
public function getCells()
|
||||||
{
|
{
|
||||||
@ -48,9 +48,9 @@ class Row
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $cells
|
* @param array $cells
|
||||||
* @return Row
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setCells($cells)
|
public function setCells(array $cells)
|
||||||
{
|
{
|
||||||
$this->cells = [];
|
$this->cells = [];
|
||||||
foreach ($cells as $cell) {
|
foreach ($cells as $cell) {
|
||||||
@ -82,7 +82,7 @@ class Row
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Style $style|null
|
* @param Style $style|null
|
||||||
* @return $this
|
* @return Row
|
||||||
*/
|
*/
|
||||||
public function applyStyle(Style $style = null)
|
public function applyStyle(Style $style = null)
|
||||||
{
|
{
|
||||||
|
37
src/Spout/Writer/Common/Manager/CellManager.php
Normal file
37
src/Spout/Writer/Common/Manager/CellManager.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Box\Spout\Writer\Common\Manager;
|
||||||
|
|
||||||
|
use Box\Spout\Writer\Common\Entity\Cell;
|
||||||
|
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||||
|
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
|
||||||
|
|
||||||
|
class CellManager
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var StyleMerger
|
||||||
|
*/
|
||||||
|
protected $styleMerger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CellManager constructor.
|
||||||
|
* @param StyleMerger $styleMerger
|
||||||
|
*/
|
||||||
|
public function __construct(StyleMerger $styleMerger)
|
||||||
|
{
|
||||||
|
$this->styleMerger = $styleMerger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merges a Style into a cells Style.
|
||||||
|
*
|
||||||
|
* @param Cell $cell
|
||||||
|
* @param Style $style
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function applyStyle(Cell $cell, Style $style)
|
||||||
|
{
|
||||||
|
$mergedStyle = $this->styleMerger->merge($cell->getStyle(), $style);
|
||||||
|
$cell->setStyle($mergedStyle);
|
||||||
|
}
|
||||||
|
}
|
34
src/Spout/Writer/Common/Manager/RowManager.php
Normal file
34
src/Spout/Writer/Common/Manager/RowManager.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Box\Spout\Writer\Common\Manager;
|
||||||
|
|
||||||
|
use Box\Spout\Writer\Common\Entity\Row;
|
||||||
|
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||||
|
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
|
||||||
|
|
||||||
|
class RowManager
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var StyleMerger
|
||||||
|
*/
|
||||||
|
protected $styleMerger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RowManager constructor.
|
||||||
|
* @param StyleMerger $styleMerger
|
||||||
|
*/
|
||||||
|
public function __construct(StyleMerger $styleMerger)
|
||||||
|
{
|
||||||
|
$this->styleMerger = $styleMerger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Style $style
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function applyStyle(Row $row, Style $style)
|
||||||
|
{
|
||||||
|
$mergedStyle = $this->styleMerger->merge($row->getStyle(), $style);
|
||||||
|
$row->setStyle($mergedStyle);
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ use Box\Spout\Common\Exception\IOException;
|
|||||||
use Box\Spout\Writer\Common\Helper\FileSystemWithRootFolderHelperInterface;
|
use Box\Spout\Writer\Common\Helper\FileSystemWithRootFolderHelperInterface;
|
||||||
use Box\Spout\Writer\Common\Entity\Options;
|
use Box\Spout\Writer\Common\Entity\Options;
|
||||||
use Box\Spout\Writer\Common\Manager\Style\StyleManagerInterface;
|
use Box\Spout\Writer\Common\Manager\Style\StyleManagerInterface;
|
||||||
|
use Box\Spout\Writer\Common\Entity\Row;
|
||||||
use Box\Spout\Writer\Common\Entity\Sheet;
|
use Box\Spout\Writer\Common\Entity\Sheet;
|
||||||
use Box\Spout\Writer\Common\Entity\Workbook;
|
use Box\Spout\Writer\Common\Entity\Workbook;
|
||||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||||
|
@ -7,7 +7,6 @@ use Box\Spout\Writer\Common\Entity\Sheet;
|
|||||||
use Box\Spout\Writer\Common\Entity\Row;
|
use Box\Spout\Writer\Common\Entity\Row;
|
||||||
use Box\Spout\Writer\Common\Entity\Workbook;
|
use Box\Spout\Writer\Common\Entity\Workbook;
|
||||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||||
use Box\Spout\Writer\Common\Sheet;
|
|
||||||
use Box\Spout\Writer\Exception\SheetNotFoundException;
|
use Box\Spout\Writer\Exception\SheetNotFoundException;
|
||||||
use Box\Spout\Writer\Exception\WriterException;
|
use Box\Spout\Writer\Exception\WriterException;
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class WorksheetManager implements WorksheetManagerInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* WorksheetManager constructor.
|
* WorksheetManager constructor.
|
||||||
*
|
* @param StyleManager $styleManager
|
||||||
* @param \Box\Spout\Common\Escaper\ODS $stringsEscaper
|
* @param \Box\Spout\Common\Escaper\ODS $stringsEscaper
|
||||||
* @param StringHelper $stringHelper
|
* @param StringHelper $stringHelper
|
||||||
*/
|
*/
|
||||||
@ -91,7 +91,6 @@ class WorksheetManager implements WorksheetManagerInterface
|
|||||||
return $tableElement;
|
return $tableElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
/**
|
/**
|
||||||
* Adds a row to the worksheet.
|
* Adds a row to the worksheet.
|
||||||
*
|
*
|
||||||
@ -116,7 +115,7 @@ class WorksheetManager implements WorksheetManagerInterface
|
|||||||
for ($i = 0; $i < $cellsCount; $i++) {
|
for ($i = 0; $i < $cellsCount; $i++) {
|
||||||
|
|
||||||
/** @var Cell $cell */
|
/** @var Cell $cell */
|
||||||
$cell = $row->getCells()[$currentCellIndex];
|
$cell = $cells[$currentCellIndex];
|
||||||
/** @var Cell|null $nextCell */
|
/** @var Cell|null $nextCell */
|
||||||
$nextCell = isset($cells[$nextCellIndex]) ? $cells[$nextCellIndex] : null;
|
$nextCell = isset($cells[$nextCellIndex]) ? $cells[$nextCellIndex] : null;
|
||||||
|
|
||||||
|
@ -344,20 +344,25 @@ abstract class WriterAbstract implements WriterInterface
|
|||||||
throw new InvalidArgumentException('The "$style" argument must be a Style instance and cannot be NULL.');
|
throw new InvalidArgumentException('The "$style" argument must be a Style instance and cannot be NULL.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addRows(array_map(function ($row) use ($style) {
|
foreach($dataRows as $row) {
|
||||||
|
|
||||||
if (is_array($row)) {
|
if (is_array($row)) {
|
||||||
return $this->createRowFromArray($row, $style);
|
$row = $this->createRowFromArray($row, $style);
|
||||||
} elseif ($row instanceof Row) {
|
} elseif ($row instanceof Row) {
|
||||||
return $row;
|
$row->setStyle($style);
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidArgumentException();
|
throw new InvalidArgumentException();
|
||||||
}
|
}
|
||||||
}, $dataRows));
|
|
||||||
|
$this->addRow($row);
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @TODO: Move this into styleMerger
|
||||||
|
*
|
||||||
* @param Row $row
|
* @param Row $row
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
@ -367,9 +372,8 @@ abstract class WriterAbstract implements WriterInterface
|
|||||||
if (null === $defaultRowStyle) {
|
if (null === $defaultRowStyle) {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
$merged = $this->styleMerger->merge($row->getStyle(), $defaultRowStyle);
|
$mergedStyle = $this->styleMerger->merge($row->getStyle(), $defaultRowStyle);
|
||||||
$row->setStyle($merged);
|
$row->setStyle($mergedStyle);
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user