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

Fix local floats in XML

This commit is contained in:
Sergey Shuchkin 2021-01-25 22:19:37 +06:00
parent 42558401ef
commit 205396b998
3 changed files with 18 additions and 8 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
vendor*
/books.fw.png
/datatypes.fw.png

View File

@ -1,4 +1,4 @@
# SimpleXLSXGen class 0.9.22 (Official)
# SimpleXLSXGen class 0.9.23 (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/>
@ -72,6 +72,7 @@ SimpleXLSXGen::fromArray( $data )->saveAs('debug.xlsx');
## History
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/>
v0.9.20 (2020-10-04) Disable type detection if string started with chr(0)<br/>

View File

@ -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 = '<row r="'.$CUR_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[] = '<row r="1"><c r="A1" t="s"><v>0</v></c></row>';
$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 );