1
0
mirror of https://github.com/shuchkin/simplexlsxgen.git synced 2023-08-10 21:12:59 +03:00

2 Commits

Author SHA1 Message Date
d1ccfc6f17 Added PHP Datetime object values in a cells 2021-02-26 21:39:13 +06:00
21db9eca96 * percent 2021-02-26 12:55:41 +06:00
3 changed files with 17 additions and 7 deletions

View File

@ -1,10 +1,10 @@
# SimpleXLSXGen class 0.9.23 (Official)
# SimpleXLSXGen class 0.9.25 (Official)
[<img src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.herokuapp.com%2Fshuchkin" />](https://www.patreon.com/shuchkin) [<img src="https://img.shields.io/github/license/shuchkin/simplexlsxgen" />](https://github.com/shuchkin/simplexlsxgen/blob/master/license.md) [<img src="https://img.shields.io/github/stars/shuchkin/simplexlsxgen" />](https://github.com/shuchkin/simplexlsxgen/stargazers) [<img src="https://img.shields.io/github/forks/shuchkin/simplexlsxgen" />](https://github.com/shuchkin/simplexlsxgen/network) [<img src="https://img.shields.io/github/issues/shuchkin/simplexlsxgen" />](https://github.com/shuchkin/simplexlsxgen/issues)
Export data to Excel XLSX file. PHP XLSX generator. No external tools and libraries.<br/>
(!) XLSX reader [here](https://github.com/shuchkin/simplexlsx).
**Sergey Shuchkin** <sergey.shuchkin@gmail.com> 2020<br/>
**Sergey Shuchkin** <sergey.shuchkin@gmail.com> 2020-2021<br/>
*Hey, bro, please ★ the package for my motivation :)*
@ -36,12 +36,13 @@ or download class [here](https://github.com/shuchkin/simplexlsxgen/blob/master/s
$data = [
['Integer', 123],
['Float', 12.35],
['Procent', '12%'],
['Percent', '12%'],
['Datetime', '2020-05-20 02:38:00'],
['Date','2020-05-20'],
['Time','02:38:00'],
['Datetime PHP', new DateTime('2021-02-06 21:07:00')],
['String', 'Long UTF-8 String in autoresized column'],
['Disable Type Detection', "\0".'2020-10-04 16:02:00']
['RAW string', "\0".'2020-10-04 16:02:00']
];
SimpleXLSXGen::fromArray( $data )->saveAs('datatypes.xlsx');
```
@ -72,6 +73,8 @@ SimpleXLSXGen::fromArray( $data )->saveAs('debug.xlsx');
## History
v0.9.25 (2021-02-26) Added PHP Datetime object values in a cells
v0.9.24 (2021-02-26) * Percent<br/>
v0.9.23 (2021-01-25) Fix local floats in XML<br/>
v0.9.22 (2020-11-04) Added multiple sheets support, thx [Savino59](https://github.com/Savino59), class ready for extend now<br/>
v0.9.21 (2020-10-17) Updated images<br/>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -351,9 +351,6 @@ class SimpleXLSXGen {
if ( $v === null || $v === '' ) {
continue;
}
$vl = mb_strlen( (string) $v );
$COL[ $CUR_COL ] = max( $vl, $COL[ $CUR_COL ] );
$cname = $this->num2name($CUR_COL) . $CUR_ROW;
@ -361,6 +358,8 @@ class SimpleXLSXGen {
if ( is_string($v) ) {
$vl = mb_strlen( $v );
if ( $v === '0' || preg_match( '/^[-+]?[1-9]\d{0,14}$/', $v ) ) { // Integer as General
$cv = ltrim( $v, '+' );
if ( $vl > 10 ) {
@ -412,13 +411,21 @@ class SimpleXLSXGen {
}
}
} elseif ( is_int( $v ) ) {
$vl = mb_strlen( (string) $v );
$cv = $v;
} elseif ( is_float( $v ) ) {
$vl = mb_strlen( (string) $v );
$cv = $v;
} elseif ( $v instanceof DateTime ) {
$vl = 16;
$cv = $this->date2excel( $v->format('Y'), $v->format('m'), $v->format('d'), $v->format('H'), $v->format('i'), $v->format('s') );
$cs = 6; // [22] m/d/yy h:mm
} else {
continue;
}
$COL[ $CUR_COL ] = max( $vl, $COL[ $CUR_COL ] );
$row .= '<c r="' . $cname . '"'.($ct ? ' t="'.$ct.'"' : '').($cs ? ' s="'.$cs.'"' : '').'>'
.($ct === 'inlineStr' ? '<is><t>'.$cv.'</t></is>' : '<v>' . $cv . '</v>')."</c>\r\n";
}