gestion de la différence odd/even
This commit is contained in:
parent
f9fd6b838e
commit
23ded28680
@ -195,6 +195,13 @@ class SpoutBuilder extends AbstractBuilder {
|
|||||||
|
|
||||||
protected int $rowStyle;
|
protected int $rowStyle;
|
||||||
|
|
||||||
|
protected ?bool $differentOddEven = null;
|
||||||
|
|
||||||
|
function setDifferentOddEven(bool $differentOddEven): self {
|
||||||
|
$this->differentOddEven = $differentOddEven;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|int|null $sheetName
|
* @param string|int|null $sheetName
|
||||||
*/
|
*/
|
||||||
@ -303,10 +310,11 @@ class SpoutBuilder extends AbstractBuilder {
|
|||||||
|
|
||||||
function _write(array $row, ?array $colsStyle=null, ?array $rowStyle=null): void {
|
function _write(array $row, ?array $colsStyle=null, ?array $rowStyle=null): void {
|
||||||
$sheetParams = $this->sheetParams;
|
$sheetParams = $this->sheetParams;
|
||||||
$defaultStyle = $sheetParams["default_style"] ?? null;
|
|
||||||
$headerStyle = $sheetParams["header_style"] ?? null;
|
$headerStyle = $sheetParams["header_style"] ?? null;
|
||||||
$oddStyle = $sheetParams["odd_style"] ?? null;
|
$oddStyle = $sheetParams["odd_style"] ?? null;
|
||||||
$evenStyle = $sheetParams["even_style"] ?? null;
|
$evenStyle = $sheetParams["even_style"] ?? null;
|
||||||
|
$differentOddEven = $this->differentOddEven;
|
||||||
|
$differentOddEven ??= $sheetParams["different_odd_even"] ?? true;
|
||||||
|
|
||||||
$cells = [];
|
$cells = [];
|
||||||
foreach ($row as $key => $col) {
|
foreach ($row as $key => $col) {
|
||||||
@ -327,12 +335,10 @@ class SpoutBuilder extends AbstractBuilder {
|
|||||||
}
|
}
|
||||||
if ($this->rowStyle === self::STYLE_HEADER) {
|
if ($this->rowStyle === self::STYLE_HEADER) {
|
||||||
$rowStyle ??= $headerStyle;
|
$rowStyle ??= $headerStyle;
|
||||||
} elseif (($this->index + 1) % 2 == 0) {
|
} elseif ($differentOddEven && ($this->index + 1) % 2 == 0) {
|
||||||
$rowStyle ??= $evenStyle;
|
$rowStyle ??= $evenStyle;
|
||||||
} else {
|
|
||||||
$rowStyle ??= $oddStyle;
|
|
||||||
}
|
}
|
||||||
$rowStyle ??= $defaultStyle;
|
$rowStyle ??= $oddStyle;
|
||||||
self::ensure_style($rowStyle);
|
self::ensure_style($rowStyle);
|
||||||
$this->ss->addRow(WriterEntityFactory::createRow($cells, $rowStyle));
|
$this->ss->addRow(WriterEntityFactory::createRow($cells, $rowStyle));
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,9 @@ class ref_params_ods extends ref_params {
|
|||||||
|
|
||||||
const SHEET = [
|
const SHEET = [
|
||||||
"->setName" => ["string"],
|
"->setName" => ["string"],
|
||||||
"default_style" => self::STYLE,
|
|
||||||
"header_style" => self::STYLE,
|
"header_style" => self::STYLE,
|
||||||
"row_style" => self::STYLE,
|
"odd_style" => self::STYLE,
|
||||||
|
"even_style" => self::STYLE,
|
||||||
|
"different_odd_even" => "bool",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -50,10 +50,10 @@ class ref_params_xlsx extends ref_params {
|
|||||||
"->setColumnWidth" => ["int", "int"],
|
"->setColumnWidth" => ["int", "int"],
|
||||||
"->setColumnWidthForRange" => ["int", "int", "int"],
|
"->setColumnWidthForRange" => ["int", "int", "int"],
|
||||||
"view" => self::SHEET_VIEW,
|
"view" => self::SHEET_VIEW,
|
||||||
"default_style" => self::STYLE,
|
|
||||||
"header_style" => self::STYLE,
|
"header_style" => self::STYLE,
|
||||||
"odd_style" => self::STYLE,
|
"odd_style" => self::STYLE,
|
||||||
"even_style" => self::STYLE,
|
"even_style" => self::STYLE,
|
||||||
|
"different_odd_even" => "bool",
|
||||||
];
|
];
|
||||||
|
|
||||||
const SHEET_VIEW = [
|
const SHEET_VIEW = [
|
||||||
|
Loading…
Reference in New Issue
Block a user