From 91ca3f6fff6afe6f079822b8407f913659328cfd Mon Sep 17 00:00:00 2001 From: Andrew Robinson Date: Fri, 31 Mar 2023 17:04:03 +1100 Subject: [PATCH] Added Font-Size Ability --- src/SimpleXLSXGen.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/SimpleXLSXGen.php b/src/SimpleXLSXGen.php index a500cba..dfc38a7 100644 --- a/src/SimpleXLSXGen.php +++ b/src/SimpleXLSXGen.php @@ -80,6 +80,7 @@ class SimpleXLSXGen { $this->curSheet = -1; $this->defaultFont = 'Calibri'; + $this->defaultFontSize = 10; $this->sheets = [['name' => 'Sheet1', 'rows' => [], 'hyperlinks' => [], 'mergecells' => [], 'colwidth' => [], 'autofilter' => '']]; $this->extLinkId = 0; $this->SI = []; // sharedStrings index @@ -385,7 +386,7 @@ class SimpleXLSXGen } foreach ($this->XF as $xf) { - // 0 - num fmt, 1 - align, 2 - font, 3 - fill, 4 - font color, 5 - bgcolor, 6 - border + // 0 - num fmt, 1 - align, 2 - font, 3 - fill, 4 - font color, 5 - bgcolor, 6 - border, 7 - font size // fonts $F_KEY = $xf[2] . '-' . $xf[4]; if (isset($F_KEYS[$F_KEY])) { @@ -394,7 +395,7 @@ class SimpleXLSXGen $F_ID = $F_KEYS[$F_KEY] = count($FONTS); $FONTS[] = '' - . ($this->defaultFontSize ? '' : '') + . ($xf[7] ? '' : '') . ($xf[2] & self::F_BOLD ? '' : '') . ($xf[2] & self::F_ITALIC ? '' : '') . ($xf[2] & self::F_UNDERLINE ? '' : '') @@ -660,7 +661,7 @@ class SimpleXLSXGen } $ct = $cv = $cf = null; - $N = $A = $F = $FL = $C = $BG = 0; + $N = $A = $F = $FL = $C = $BG = $FS = 0; $BR = ''; if (is_string($v)) { @@ -708,6 +709,12 @@ class SimpleXLSXGen $BR = $b; } } + if (preg_match('/ font-size="([^"]+)"/', $m[1], $m2)) { + $FS = (int)$m2[1]; + if($RH == 0){ + $RH = (int)($FS * 1.25); + } + } } if (strpos($v, '') !== false) { $A += self::A_LEFT; @@ -858,7 +865,7 @@ class SimpleXLSXGen $cs = 0; - if (($N + $A + $F + $FL > 0) || $BR !== '') { + if (($N + $A + $F + $FL + $FS > 0) || $BR !== '') { if ($FL === self::FL_COLOR) { $FL += self::FL_SOLID; @@ -868,7 +875,7 @@ class SimpleXLSXGen $C = 'FF0563C1'; } - $XF_KEY = $N . '-' . $A . '-' . $F . '-' . $FL . '-' . $C . '-' . $BG . '-' . $BR; + $XF_KEY = $N . '-' . $A . '-' . $F . '-' . $FL . '-' . $C . '-' . $BG . '-' . $BR . '-' . $FS; // echo $cname .'='.$XF_KEY.PHP_EOL; if (isset($this->XF_KEYS[$XF_KEY])) { $cs = $this->XF_KEYS[$XF_KEY]; @@ -876,7 +883,7 @@ class SimpleXLSXGen if ($cs === 0) { $cs = count($this->XF); $this->XF_KEYS[$XF_KEY] = $cs; - $this->XF[] = [$N, $A, $F, $FL, $C, $BG, $BR]; + $this->XF[] = [$N, $A, $F, $FL, $C, $BG, $BR, $FS]; } }