diff --git a/CHANGELOG.md b/CHANGELOG.md index 80ff193..696c23d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,11 @@ # Changelog -## 1.2.11 (2022-) -* Row height `<style height="50">Custom row height 50</style>` +## 1.2.11 (2022-05-17) +* Row height `` +* Vertical align `12345` ## 1.2.10 (2022-04-24) -* Added colors `<style color="#FFFF00" bgcolor="#00FF00">Yellow text on blue background</style>`, thx [mrjemson](https://github.com/mrjemson) +* Added colors ``, thx [mrjemson](https://github.com/mrjemson) ## 1.1.12 (2022-03-15) * Added `$xlsx->mergeCells('A1:C1')` diff --git a/README.md b/README.md index 4a0f4f7..2a62d35 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Export data to Excel XLSX file. PHP XLSX generator. No external tools and librar - XLS reader [here](https://github.com/shuchkin/simplexls) - CSV reader/writer [here](https://github.com/shuchkin/simplecsv) -**Sergey Shuchkin** 2020-2021
+**Sergey Shuchkin** 2020-2022
*Hey, bro, please ★ the package for my motivation :) and [donate](https://opencollective.com/simplexlsx) for more motivation!* @@ -70,12 +70,16 @@ $data = [ ['Center', '
12345.67
'], ['Right', 'Right Text'], ['Center + Bold', '
Name
'], - ['
MERGE CELLS
', null] + ['Row height', ''], + ['Top', ''], + ['Middle + Center', ''], + ['Bottom + Right', ''], + ['
MERGE CELLS
', null], ]; SimpleXLSXGen::fromArray( $data ) ->setDefaultFont( 'Courier New' ) ->setDefaultFontSize( 14 ) - ->mergeCells('A16:B16') + ->mergeCells('A20:B20') ->saveAs('styles_and_tags.xlsx'); ``` ![XLSX screenshot](styles.png) diff --git a/src/SimpleXLSXGen.php b/src/SimpleXLSXGen.php index b109df1..7be540d 100644 --- a/src/SimpleXLSXGen.php +++ b/src/SimpleXLSXGen.php @@ -46,7 +46,10 @@ class SimpleXLSXGen { const A_DEFAULT = 0; const A_LEFT = 1; const A_RIGHT = 2; - const A_CENTER = 3; + const A_CENTER = 4; + const A_TOP = 8; + const A_MIDDLE = 16; + const A_BOTTOM = 32; public function __construct() { $this->curSheet = -1; @@ -346,15 +349,18 @@ class SimpleXLSXGen { .( $xf[3] & self::FL_COLOR ? '>' : ' />') .''; } - $align = ($xf[1] === self::A_LEFT ? ' applyAlignment="1">' : '') - .($xf[1] === self::A_RIGHT ? ' applyAlignment="1">' : '') - .($xf[1] === self::A_CENTER ? ' applyAlignment="1">' : ''); + $align = ($xf[1] & self::A_LEFT ? ' horizontal="left"' : '') + .($xf[1] & self::A_RIGHT ? ' horizontal="right"' : '') + .($xf[1] & self::A_CENTER ? ' horizontal="center"' : '') + .($xf[1] & self::A_TOP ? ' vertical="top"' : '') + .($xf[1] & self::A_MIDDLE ? ' vertical="center"' : '') + .($xf[1] & self::A_BOTTOM ? ' vertical="bottom"' : ''); $XF[] = ' 0 ? ' applyNumberFormat="1"' : '') .($F_ID > 0 ? ' applyFont="1"' : '') .($FL_ID > 0 ? ' applyFill="1"' : '') - .($align ? $align . '' : '/>'); + .($align ? ' applyAlignment="1">' : '/>'); } // wrap collections @@ -542,6 +548,15 @@ class SimpleXLSXGen { if ( strpos( $v, '' ) !== false ) { $A += self::A_RIGHT; } + if ( strpos( $v, '' ) !== false ) { + $A += self::A_TOP; + } + if ( strpos( $v, '' ) !== false ) { + $A += self::A_MIDDLE; + } + if ( strpos( $v, '' ) !== false ) { + $A += self::A_BOTTOM; + } if ( preg_match( '/(.*?)<\/a>/i', $v, $m ) ) { $h = explode( '#', $m[1] ); $this->sheets[ $idx ]['hyperlinks'][] = ['ID' => 'rId' . ( count( $this->sheets[ $idx ]['hyperlinks'] ) + 1 ), 'R' => $cname, 'H' => $h[0], 'L' => isset( $h[1] ) ? $h[1] : '']; diff --git a/styles.png b/styles.png index d3b32fd..523df6a 100644 Binary files a/styles.png and b/styles.png differ