Compare commits

...

2 Commits

Author SHA1 Message Date
6c1c85bcd2 remplacer nur_func par func 2025-04-29 11:07:02 +04:00
3cdcf4958d support de multiples définitions pour border 2025-04-29 11:06:50 +04:00

View File

@ -6,7 +6,6 @@ use nulib\file\tab\AbstractBuilder;
use nulib\file\tab\TAbstractBuilder; use nulib\file\tab\TAbstractBuilder;
use nulib\os\path; use nulib\os\path;
use nulib\php\func; use nulib\php\func;
use nulib\php\nur_func;
use nulib\php\time\Date; use nulib\php\time\Date;
use nulib\php\time\DateTime; use nulib\php\time\DateTime;
use nulib\ref\ext\spout\ref_builder; use nulib\ref\ext\spout\ref_builder;
@ -86,20 +85,23 @@ class SpoutBuilder extends AbstractBuilder {
if (($wrap = $cell["wrap"] ?? null) !== null) $style->setShouldWrapText($wrap); if (($wrap = $cell["wrap"] ?? null) !== null) $style->setShouldWrapText($wrap);
if (($format = $cell["format"] ?? null) !== null) $style->setFormat($format); if (($format = $cell["format"] ?? null) !== null) $style->setFormat($format);
if (($border = $cell["border"] ?? null) !== null) { if (($border = $cell["border"] ?? null) !== null) {
if (is_string($border)) { if (is_array($border)) $borderDefs = $border;
$parts = explode(" ", $border); else $borderDefs = preg_split('/\s*,\s*/', trim(strval($border)));
$border = []; $border = null;
foreach ($borderDefs as $borderDef) {
$parts = preg_split('/\s+/', $borderDef);
$borderDef = [];
$styleAll = null; $styleAll = null;
$widthAll = null; $widthAll = null;
$colorAll = null; $colorAll = null;
foreach ($parts as $part) { foreach ($parts as $part) {
if ($part === "all") { if ($part === "all") {
$border["left"] = []; $borderDef["left"] = [];
$border["top"] = []; $borderDef["top"] = [];
$border["right"] = []; $borderDef["right"] = [];
$border["bottom"] = []; $borderDef["bottom"] = [];
} elseif (preg_match('/^(left|top|right|bottom)$/', $part)) { } elseif (preg_match('/^(left|top|right|bottom)$/', $part)) {
$border[$part] = []; $borderDef[$part] = [];
} elseif (preg_match('/^(none|solid|dashed|dotted|double)$/', $part)) { } elseif (preg_match('/^(none|solid|dashed|dotted|double)$/', $part)) {
$styleAll = $part; $styleAll = $part;
} elseif (preg_match('/^(thin|medium|thick)$/', $part)) { } elseif (preg_match('/^(thin|medium|thick)$/', $part)) {
@ -108,22 +110,22 @@ class SpoutBuilder extends AbstractBuilder {
$colorAll = $part; $colorAll = $part;
} }
} }
foreach ($border as &$part) { foreach ($borderDef as &$part) {
if ($styleAll !== null) $part["style"] = $styleAll; if ($styleAll !== null) $part["style"] = $styleAll;
if ($widthAll !== null) $part["width"] = $widthAll; if ($widthAll !== null) $part["width"] = $widthAll;
if ($colorAll !== null) $part["color"] = $colorAll; if ($colorAll !== null) $part["color"] = $colorAll;
}; unset($part); }; unset($part);
}
$top = $border["top"] ?? null; $top = $borderDef["top"] ?? null;
$right = $border["right"] ?? null; $right = $borderDef["right"] ?? null;
$bottom = $border["bottom"] ?? null; $bottom = $borderDef["bottom"] ?? null;
$left = $border["left"] ?? null; $left = $borderDef["left"] ?? null;
$border = null;
self::add_border_part($border, "top", $top); self::add_border_part($border, "top", $top);
self::add_border_part($border, "right", $right); self::add_border_part($border, "right", $right);
self::add_border_part($border, "bottom", $bottom); self::add_border_part($border, "bottom", $bottom);
self::add_border_part($border, "left", $left); self::add_border_part($border, "left", $left);
}
if ($border !== null) $style->setBorder($border); if ($border !== null) $style->setBorder($border);
} }
return $style; return $style;
@ -321,13 +323,8 @@ class SpoutBuilder extends AbstractBuilder {
} }
if (array_key_exists("cook_func", $sheetParams)) { if (array_key_exists("cook_func", $sheetParams)) {
$cookFunc = $sheetParams["cook_func"] ?? null; $cookFunc = $sheetParams["cook_func"] ?? null;
$cookCtx = $cookArgs = null; if ($cookFunc !== null) $cookFunc = func::with($cookFunc)->bind($this);
if ($cookFunc !== null) { $this->cookFunc = $cookFunc;
nur_func::ensure_func($cookFunc, $this, $cookArgs);
$cookCtx = nur_func::_prepare($cookFunc);
}
$this->cookCtx = $cookCtx;
$this->cookArgs = $cookArgs;
} }
} }
return $this; return $this;