diff --git a/CHANGELOG.md b/CHANGELOG.md index 10f8246..ad56a5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.3.12 (2023-03-31) +* `````` - font size in cells, thx [Andrew Robinson](https://github.com/mrjemson) + + ## 1.3.11 (2023-03-28) * freezePanes( corner_cell ) - freezePanes to keep an area of a worksheet visible while you scroll, corner_cell is not included, thx [Javier](https://github.com/xaviermdq) diff --git a/README.md b/README.md index ab77754..1db905a 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ $data = [ ['Italic + Hyperlink + Anchor', 'SimpleXLSXGen'], ['Green', ''], ['Bold Red Text', ''], + ['Size 32 Font', ''], ['Blue Text and Yellow Fill', ''], ['Border color', ''], ['Border style',''], @@ -85,8 +86,7 @@ $data = [ ['Middle + Center', ''], ['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', ''], + ['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"], ]; SimpleXLSXGen::fromArray($data) ->setDefaultFont('Courier New') diff --git a/src/SimpleXLSXGen.php b/src/SimpleXLSXGen.php index dfc38a7..b28d8e0 100644 --- a/src/SimpleXLSXGen.php +++ b/src/SimpleXLSXGen.php @@ -112,9 +112,9 @@ class SimpleXLSXGen ]; - $this->XF = [ // styles 0 - num fmt, 1 - align, 2 - font, 3 - fill, 4 - font color, 5 - bgcolor, 6 - border - [self::N_NORMAL, self::A_DEFAULT, self::F_NORMAL, self::FL_NONE, 0, 0, ''], - [self::N_NORMAL, self::A_DEFAULT, self::F_NORMAL, self::FL_GRAY_125, 0, 0, ''], // hack + $this->XF = [ // styles 0 - num fmt, 1 - align, 2 - font, 3 - fill, 4 - font color, 5 - bgcolor, 6 - border, 7 - font size + [self::N_NORMAL, self::A_DEFAULT, self::F_NORMAL, self::FL_NONE, 0, 0, '', 0], + [self::N_NORMAL, self::A_DEFAULT, self::F_NORMAL, self::FL_GRAY_125, 0, 0, '', 0], // hack ]; $this->XF_KEYS[implode('-', $this->XF[0])] = 0; // & keys $this->XF_KEYS[implode('-', $this->XF[1])] = 1; @@ -388,7 +388,7 @@ class SimpleXLSXGen foreach ($this->XF as $xf) { // 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]; + $F_KEY = $xf[2] . '-' . $xf[4].'-'.$xf[7]; if (isset($F_KEYS[$F_KEY])) { $F_ID = $F_KEYS[$F_KEY]; } else { @@ -626,18 +626,30 @@ class SimpleXLSXGen $cell = $this->sheets[$idx]['frozen']; self::cell2coord($cell, $x, $y); } else { - if (isset($this->sheets[$idx]['frozen'][0])) $x = $this->sheets[$idx]['frozen'][0]; - if (isset($this->sheets[$idx]['frozen'][1])) $y = $this->sheets[$idx]['frozen'][1]; + if (isset($this->sheets[$idx]['frozen'][0])) { + $x = $this->sheets[$idx]['frozen'][0]; + } + if (isset($this->sheets[$idx]['frozen'][1])) { + $y = $this->sheets[$idx]['frozen'][1]; + } $cell = self::coord2cell($x, $y); } if ($x > 0 || $y > 0) { $split = ''; - if ($x > 0) $split .= " xSplit=\"{$x}\""; - if ($y > 0) $split .= " ySplit=\"{$y}\""; + if ($x > 0) { + $split .= ' xSplit="'.$x.'"'; + } + if ($y > 0) { + $split .= ' ySplit="'.$y.'"'; + } $activepane = 'bottomRight'; - if ($x > 0 && $y == 0) $activepane = 'topRight'; - if ($x == 0 && $y > 0) $activepane = 'bottomLeft'; - $SHEETVIEWS = ""; + if ($x > 0 && $y === 0) { + $activepane = 'topRight'; + } + if ($x === 0 && $y > 0) { + $activepane = 'bottomLeft'; + } + $SHEETVIEWS = ''; } } $COLS[] = ''; @@ -711,9 +723,9 @@ class SimpleXLSXGen } if (preg_match('/ font-size="([^"]+)"/', $m[1], $m2)) { $FS = (int)$m2[1]; - if($RH == 0){ - $RH = (int)($FS * 1.25); - } + if ($RH === 0) { // fix row height + $RH = ($FS > $this->defaultFontSize) ? round($FS * 1.50,1) : 0; + } } } if (strpos($v, '') !== false) { @@ -1039,7 +1051,7 @@ class SimpleXLSXGen public static function raw($value) { - return "\0" . (string)$value; + return "\0" . $value; } public static function cell2coord($cell, &$x, &$y) @@ -1047,9 +1059,15 @@ class SimpleXLSXGen $x = $y = 0; $lettercount = 0; $cell = str_replace([' ', '\t', '\r', '\n', '\v', '\0'], '', $cell); - if (empty($cell)) return; + if (empty($cell)) { + return; + } $cell = strtoupper($cell); - for ($i = 0; $i < strlen($cell); $i++) if ($cell[$i] >= 'A' && $cell[$i] <= 'Z') $lettercount++; + for ($i = 0, $len = strlen($cell); $i < $len; $i++) { + if ($cell[$i] >= 'A' && $cell[$i] <= 'Z') { + $lettercount++; + } + } if ($lettercount > 0) { $x = ord($cell[$lettercount - 1]) - ord('A'); $e = 1; @@ -1058,15 +1076,18 @@ class SimpleXLSXGen $e++; } } - if ($lettercount < strlen($cell)) $y = ((int)substr($cell, $lettercount)) - 1; + if ($lettercount < strlen($cell)) { + $y = ((int)substr($cell, $lettercount)) - 1; + } } public static function coord2cell($x, $y, $absolute = false) { $c = ''; - for ($i = $x; $i >= 0; $i = ((int)($i / 26)) - 1) $c = chr(ord('A') + $i % 26) . $c; - if ($absolute) $absolute = '$'; else $absolute = ''; - return $absolute . $c . $absolute . ($y+1); + for ($i = $x; $i >= 0; $i = ((int)($i / 26)) - 1) { + $c = chr(ord('A') + $i % 26) . $c; + } + return ($absolute ? '$' : '') . $c . $absolute . ($y+1); } public function freezePanes($cell) diff --git a/styles.png b/styles.png index 0ad95da..a2e1209 100644 Binary files a/styles.png and b/styles.png differ