Adding row attributes.
This commit is contained in:
parent
cc42c1d29f
commit
0ecc7260eb
@ -6,6 +6,12 @@ use Box\Spout\Common\Entity\Style\Style;
|
|||||||
|
|
||||||
class Row
|
class Row
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The extended attributes in this row
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
protected $attributes = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The cells in this row
|
* The cells in this row
|
||||||
* @var Cell[]
|
* @var Cell[]
|
||||||
@ -30,6 +36,26 @@ class Row
|
|||||||
->setStyle($style);
|
->setStyle($style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAttributes()
|
||||||
|
{
|
||||||
|
return $this->attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param $value
|
||||||
|
* @return Row
|
||||||
|
*/
|
||||||
|
public function setAttribute(string $name, $value)
|
||||||
|
{
|
||||||
|
$this->attributes[$name] = (string) $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Cell[] $cells
|
* @return Cell[] $cells
|
||||||
*/
|
*/
|
||||||
|
@ -151,7 +151,12 @@ EOD;
|
|||||||
$rowIndexOneBased = $worksheet->getLastWrittenRowIndex() + 1;
|
$rowIndexOneBased = $worksheet->getLastWrittenRowIndex() + 1;
|
||||||
$numCells = $row->getNumCells();
|
$numCells = $row->getNumCells();
|
||||||
|
|
||||||
$rowXML = '<row r="' . $rowIndexOneBased . '" spans="1:' . $numCells . '">';
|
$defaultAttributes = [
|
||||||
|
'r' => $rowIndexOneBased,
|
||||||
|
'spans' => '1:' . $numCells,
|
||||||
|
];
|
||||||
|
|
||||||
|
$rowXML = $this->getRowXML(array_merge($row->getAttributes(), $defaultAttributes));
|
||||||
|
|
||||||
foreach ($row->getCells() as $columnIndexZeroBased => $cell) {
|
foreach ($row->getCells() as $columnIndexZeroBased => $cell) {
|
||||||
$registeredStyle = $this->applyStyleAndRegister($cell, $rowStyle);
|
$registeredStyle = $this->applyStyleAndRegister($cell, $rowStyle);
|
||||||
@ -275,6 +280,20 @@ EOD;
|
|||||||
return $cellXMLFragment;
|
return $cellXMLFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $attributes
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getRowXML(array $attributes)
|
||||||
|
{
|
||||||
|
$attributes = array_map(function($key) use ($attributes)
|
||||||
|
{
|
||||||
|
return $key . '="' . $this->stringsEscaper->escape($attributes[$key]) . '"';
|
||||||
|
}, array_keys($attributes));
|
||||||
|
|
||||||
|
return '<row ' . implode(' ', $attributes) . '>';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user