From 91ca3f6fff6afe6f079822b8407f913659328cfd Mon Sep 17 00:00:00 2001 From: Andrew Robinson Date: Fri, 31 Mar 2023 17:04:03 +1100 Subject: [PATCH 1/2] 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]; } } From bb09c0d38c721840442af1cc5ba37a7cd609c94f Mon Sep 17 00:00:00 2001 From: Andrew Robinson Date: Fri, 31 Mar 2023 17:05:44 +1100 Subject: [PATCH 2/2] Updated Readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 29eae8d..ab77754 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ $data = [ ['Bottom + Right', ''], ['
MERGE CELLS MERGE CELLS MERGE CELLS MERGE CELLS MERGE CELLS
', null], ['Word wrap', "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book"] + ['Size 16 Font', ''], ]; SimpleXLSXGen::fromArray($data) ->setDefaultFont('Courier New')