support de merge_cells dans rowParams
This commit is contained in:
parent
51ebba1ab7
commit
1d2d8686c4
@ -241,6 +241,8 @@ class SpoutBuilder extends AbstractBuilder {
|
|||||||
|
|
||||||
protected int $rowStyle;
|
protected int $rowStyle;
|
||||||
|
|
||||||
|
protected int $currentRow;
|
||||||
|
|
||||||
protected ?bool $differentOddEven = null;
|
protected ?bool $differentOddEven = null;
|
||||||
|
|
||||||
protected int $oddEvenIndex = 0;
|
protected int $oddEvenIndex = 0;
|
||||||
@ -267,6 +269,7 @@ class SpoutBuilder extends AbstractBuilder {
|
|||||||
$this->built = false;
|
$this->built = false;
|
||||||
}
|
}
|
||||||
$this->rowStyle = self::STYLE_ROW;
|
$this->rowStyle = self::STYLE_ROW;
|
||||||
|
$this->currentRow = 1;
|
||||||
|
|
||||||
switch ($this->ssType) {
|
switch ($this->ssType) {
|
||||||
case self::SS_TYPE_ODS:
|
case self::SS_TYPE_ODS:
|
||||||
@ -367,7 +370,9 @@ class SpoutBuilder extends AbstractBuilder {
|
|||||||
function _write(array $row, ?array $colStyles=null, ?array $rowStyle=null): void {
|
function _write(array $row, ?array $colStyles=null, ?array $rowStyle=null): void {
|
||||||
$rowParams = null;
|
$rowParams = null;
|
||||||
if ($rowStyle !== null) {
|
if ($rowStyle !== null) {
|
||||||
foreach (array_keys(ref_builder::ROW) as $method) {
|
# séparer rowParams (pour configurer l'instance de $row) et $rowStyle
|
||||||
|
# (pour appliquer un style sur la ligne)
|
||||||
|
foreach (array_keys(ref_builder::ROW_PARAMS) as $method) {
|
||||||
$value = $rowStyle[$method] ?? null;
|
$value = $rowStyle[$method] ?? null;
|
||||||
unset($rowStyle[$method]);
|
unset($rowStyle[$method]);
|
||||||
if ($value !== null) $rowParams[$method] = $value;
|
if ($value !== null) $rowParams[$method] = $value;
|
||||||
@ -398,6 +403,7 @@ class SpoutBuilder extends AbstractBuilder {
|
|||||||
$cell->setType($type);
|
$cell->setType($type);
|
||||||
$cells[] = $cell;
|
$cells[] = $cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->rowStyle === self::STYLE_HEADER) {
|
if ($this->rowStyle === self::STYLE_HEADER) {
|
||||||
$rowStyle ??= $headerStyle;
|
$rowStyle ??= $headerStyle;
|
||||||
} elseif ($differentOddEven && $this->oddEvenIndex % 2 == 0) {
|
} elseif ($differentOddEven && $this->oddEvenIndex % 2 == 0) {
|
||||||
@ -406,7 +412,16 @@ class SpoutBuilder extends AbstractBuilder {
|
|||||||
$rowStyle ??= $oddStyle;
|
$rowStyle ??= $oddStyle;
|
||||||
self::ensure_style($rowStyle);
|
self::ensure_style($rowStyle);
|
||||||
$row = WriterEntityFactory::createRow($cells, $rowStyle);
|
$row = WriterEntityFactory::createRow($cells, $rowStyle);
|
||||||
self::apply_params($row, $rowParams, ref_builder::ROW);
|
self::apply_params($row, $rowParams, ref_builder::ROW_PARAMS);
|
||||||
|
|
||||||
|
$mergeCells = $rowParams["merge_cells"] ?? null;
|
||||||
|
if ($mergeCells !== null) {
|
||||||
|
foreach ($mergeCells as [$leftCol, $rightCol]) {
|
||||||
|
$this->mergeCells($leftCol, $this->currentRow, $rightCol, $this->currentRow);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->ssWriter->addRow($row);
|
$this->ssWriter->addRow($row);
|
||||||
if ($differentOddEven) $this->oddEvenIndex++;
|
if ($differentOddEven) $this->oddEvenIndex++;
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,9 @@ class ref_builder {
|
|||||||
|
|
||||||
const PARAMS_SHEET_VIEW = [];
|
const PARAMS_SHEET_VIEW = [];
|
||||||
|
|
||||||
const ROW = [
|
const ROW_PARAMS = [
|
||||||
"->setHeight" => ["float"],
|
"->setHeight" => ["float"],
|
||||||
|
"merge_cells" => "array",
|
||||||
];
|
];
|
||||||
|
|
||||||
const COLORS = [
|
const COLORS = [
|
||||||
|
Loading…
Reference in New Issue
Block a user