diff --git a/README.md b/README.md
index 40830a0..69acf86 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# SimpleXLSXGen class 0.9.24 (Official)
+# SimpleXLSXGen class 0.9.25 (Official)
[
](https://www.patreon.com/shuchkin) [
](https://github.com/shuchkin/simplexlsxgen/blob/master/license.md) [
](https://github.com/shuchkin/simplexlsxgen/stargazers) [
](https://github.com/shuchkin/simplexlsxgen/network) [
](https://github.com/shuchkin/simplexlsxgen/issues)
Export data to Excel XLSX file. PHP XLSX generator. No external tools and libraries.
@@ -40,8 +40,9 @@ $data = [
['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,7 @@ 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
v0.9.23 (2021-01-25) Fix local floats in XML
v0.9.22 (2020-11-04) Added multiple sheets support, thx [Savino59](https://github.com/Savino59), class ready for extend now
diff --git a/datatypes.png b/datatypes.png
index 55a92de..e918044 100644
Binary files a/datatypes.png and b/datatypes.png differ
diff --git a/src/SimpleXLSXGen.php b/src/SimpleXLSXGen.php
index 0533ff9..48e8ac2 100644
--- a/src/SimpleXLSXGen.php
+++ b/src/SimpleXLSXGen.php
@@ -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 .= ''
.($ct === 'inlineStr' ? ''.$cv.'' : '' . $cv . '')."\r\n";
}