Compare commits

...

2 Commits

View File

@ -95,20 +95,23 @@ class SpoutBuilder extends AbstractBuilder {
if (($rotation = $cell["rotation"] ?? null) !== null) $style->setTextRotation($rotation); if (($rotation = $cell["rotation"] ?? null) !== null) $style->setTextRotation($rotation);
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)) {
@ -117,18 +120,23 @@ 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 = $borderDef["top"] ?? null;
$right = $borderDef["right"] ?? null;
$bottom = $borderDef["bottom"] ?? null;
$left = $borderDef["left"] ?? null;
self::add_border_part($border, "top", $top);
self::add_border_part($border, "right", $right);
self::add_border_part($border, "bottom", $bottom);
self::add_border_part($border, "left", $left);
} }
$parts = null; if ($border !== null) $style->setBorder(new Border(...$border));
self::add_border_part($parts, "top", $border["top"] ?? null);
self::add_border_part($parts, "right", $border["right"] ?? null);
self::add_border_part($parts, "bottom", $border["bottom"] ?? null);
self::add_border_part($parts, "left", $border["left"] ?? null);
if ($parts !== null) $style->setBorder(new Border(...$parts));
} }
if (($autofit = $cell["autofit"] ?? null) !== null) $style->setShouldShrinkToFit($autofit); if (($autofit = $cell["autofit"] ?? null) !== null) $style->setShouldShrinkToFit($autofit);
return $style; return $style;