1
0
mirror of https://github.com/shuchkin/simplexlsxgen.git synced 2023-08-10 21:12:59 +03:00
This commit is contained in:
Sergey Shuchkin 2022-05-17 12:03:35 +06:00
parent ff3f016358
commit 6db113f753
4 changed files with 31 additions and 11 deletions

View File

@ -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 `<style height="50">Custom row height 50</style>`
* Vertical align `<bottom>12345</bottom>`
## 1.2.10 (2022-04-24)
* Added colors `&lt;style color="#FFFF00" bgcolor="#00FF00"&gt;Yellow text on blue background&lt;/style&gt;`, thx [mrjemson](https://github.com/mrjemson)
* Added colors `<style color="#FFFF00" bgcolor="#00FF00">Yellow text on blue background</style>`, thx [mrjemson](https://github.com/mrjemson)
## 1.1.12 (2022-03-15)
* Added `$xlsx->mergeCells('A1:C1')`

View File

@ -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** <sergey.shuchkin@gmail.com> 2020-2021<br/>
**Sergey Shuchkin** <sergey.shuchkin@gmail.com> 2020-2022<br/>
*Hey, bro, please ★ the package for my motivation :) and [donate](https://opencollective.com/simplexlsx) for more motivation!*
@ -70,12 +70,16 @@ $data = [
['Center', '<center>12345.67</center>'],
['Right', '<right>Right Text</right>'],
['Center + Bold', '<center><b>Name</b></center>'],
['<center>MERGE CELLS</center>', null]
['Row height', '<style height="50">Row Height = 50</style>'],
['Top', '<style height="50"><top>Top</top></style>'],
['Middle + Center', '<style height="50"><middle><center>Middle + Center</center></middle></style>'],
['Bottom + Right', '<style height="50"><bottom><right>Bottom + Right</right></bottom></style>'],
['<center>MERGE CELLS</center>', null],
];
SimpleXLSXGen::fromArray( $data )
->setDefaultFont( 'Courier New' )
->setDefaultFontSize( 14 )
->mergeCells('A16:B16')
->mergeCells('A20:B20')
->saveAs('styles_and_tags.xlsx');
```
![XLSX screenshot](styles.png)

View File

@ -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 ? '><fgColor rgb="'.$xf[5].'"/><bgColor indexed="64"/></patternFill>' : ' />')
.'</fill>';
}
$align = ($xf[1] === self::A_LEFT ? ' applyAlignment="1"><alignment horizontal="left"/>' : '')
.($xf[1] === self::A_RIGHT ? ' applyAlignment="1"><alignment horizontal="right"/>' : '')
.($xf[1] === self::A_CENTER ? ' applyAlignment="1"><alignment horizontal="center"/>' : '');
$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[] = '<xf numFmtId="'.$xf[0].'" fontId="'.$F_ID.'" fillId="'.$FL_ID.'" borderId="0" xfId="0"'
.($xf[0] > 0 ? ' applyNumberFormat="1"' : '')
.($F_ID > 0 ? ' applyFont="1"' : '')
.($FL_ID > 0 ? ' applyFill="1"' : '')
.($align ? $align . '</xf>' : '/>');
.($align ? ' applyAlignment="1"><alignment'.$align . '/></xf>' : '/>');
}
// wrap collections
@ -542,6 +548,15 @@ class SimpleXLSXGen {
if ( strpos( $v, '<right>' ) !== false ) {
$A += self::A_RIGHT;
}
if ( strpos( $v, '<top>' ) !== false ) {
$A += self::A_TOP;
}
if ( strpos( $v, '<middle>' ) !== false ) {
$A += self::A_MIDDLE;
}
if ( strpos( $v, '<bottom>' ) !== false ) {
$A += self::A_BOTTOM;
}
if ( preg_match( '/<a href="(https?:\/\/[^"]+)">(.*?)<\/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] : ''];

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 112 KiB