diff --git a/.gitignore b/.gitignore index d2d8606..2f82d3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -vendor* \ No newline at end of file +vendor* +/books.fw.png +/datatypes.fw.png diff --git a/README.md b/README.md index 0c151bf..d4757a2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# SimpleXLSXGen class 0.9.22 (Official) +# SimpleXLSXGen class 0.9.23 (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.
@@ -72,6 +72,7 @@ SimpleXLSXGen::fromArray( $data )->saveAs('debug.xlsx'); ## History +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
v0.9.21 (2020-10-17) Updated images
v0.9.20 (2020-10-04) Disable type detection if string started with chr(0)
diff --git a/src/SimpleXLSXGen.php b/src/SimpleXLSXGen.php index 44806c8..46ad58c 100644 --- a/src/SimpleXLSXGen.php +++ b/src/SimpleXLSXGen.php @@ -223,7 +223,7 @@ class SimpleXLSXGen { } elseif ( $cfilename === 'xl/worksheets/sheet1.xml' ) { foreach ( $this->sheets as $k => $v ) { $filename = 'xl/worksheets/sheet'.($k+1).'.xml'; - $xml = $this->_sheetToXML($this->sheets[$k], $template); + $xml = $this->_sheetToXML($k, $template); $this->_writeEntry($fh, $cdrec, $filename, $xml ); $entries++; } @@ -330,14 +330,16 @@ class SimpleXLSXGen { $cdrec .= $e['comments']; } - protected function _sheetToXML(&$sheet, $template) { - + protected function _sheetToXML($idx, $template) { + // locale floats fr_FR 1.234,56 -> 1234.56 + $_loc = setlocale(LC_NUMERIC,''); + setlocale(LC_NUMERIC,'C'); $COLS = []; $ROWS = []; - if ( count($sheet['rows']) ) { + if ( count($this->sheets[$idx]['rows']) ) { $CUR_ROW = 0; $COL = []; - foreach( $sheet['rows'] as $r ) { + foreach( $this->sheets[$idx]['rows'] as $r ) { $CUR_ROW++; $row = ''; $CUR_COL = 0; @@ -409,7 +411,9 @@ class SimpleXLSXGen { $this->SI_KEYS[$skey] = $cv; } } - } elseif ( is_int( $v ) || is_float( $v ) ) { + } elseif ( is_int( $v ) ) { + $cv = $v; + } elseif ( is_float( $v ) ) { $cv = $v; } else { continue; @@ -429,6 +433,9 @@ class SimpleXLSXGen { $ROWS[] = '0'; $REF = 'A1:A1'; } + //restore locale + setlocale(LC_NUMERIC, $_loc); + return str_replace(['{REF}','{COLS}','{ROWS}'], [ $REF, implode("\r\n", $COLS), implode("\r\n",$ROWS) ], $template );