améliorer gestion bordures

This commit is contained in:
Jephté Clain 2024-11-29 19:39:14 +04:00
parent 8b79df5a75
commit 0c87ff1a7b

View File

@ -108,9 +108,33 @@ class SpoutBuilder extends AbstractBuilder {
if ($cell["wrap_text"] ?? null) $style->setShouldWrapText();
if (($format = $cell["format"] ?? null) !== null) $style->setFormat($format);
if (($border = $cell["border"] ?? null) !== null) {
if ($border === "all") $params = "left top right bottom";
if (is_string($border)) {
$border = array_fill_keys(explode(" ", $border), []);
$parts = explode(" ", $border);
$border = [];
$styleAll = null;
$widthAll = null;
$colorAll = null;
foreach ($parts as $part) {
if ($part === "all") {
$border["left"] = [];
$border["top"] = [];
$border["right"] = [];
$border["bottom"] = [];
} elseif (preg_match('/^(left|top|right|bottom)$/', $part)) {
$border[$part] = [];
} elseif (preg_match('/^(none|solid|dashed|dotted|double)$/', $part)) {
$styleAll = $part;
} elseif (preg_match('/^(thin|medium|thick)$/', $part)) {
$widthAll = $part;
} else {
$colorAll = $part;
}
}
foreach ($border as &$part) {
if ($styleAll !== null) $part["style"] = $styleAll;
if ($widthAll !== null) $part["width"] = $widthAll;
if ($colorAll !== null) $part["color"] = $colorAll;
}; unset($part);
}
$top = $border["top"] ?? null;