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

Long Numbers format

This commit is contained in:
Sergey Shuchkin 2020-08-23 15:07:29 +06:00
parent aafe6abd5b
commit a551f6485b
2 changed files with 26 additions and 15 deletions

View File

@ -1,4 +1,4 @@
# SimpleXLSXGen class 0.9.18 (Official) # SimpleXLSXGen class 0.9.19 (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) [<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/> Export data to Excel XLSX file. PHP XLSX generator. No external tools and libraries.<br/>
@ -62,7 +62,8 @@ SimpleXLSXGen::fromArray( $data )->saveAs('debug.xlsx');
## History ## History
v0.9.18 (2020-08-22) fixed fast shared strings index<br/> v0.9.19 (2020-08-23) Numbers like SKU right aligned now<br/>
v0.9.18 (2020-08-22) Fixed fast shared strings index<br/>
v0.9.17 (2020-08-21) Fixed real numbers in 123.45 format detection, fast shared strings index (thx fredriksundin)<br/> v0.9.17 (2020-08-21) Fixed real numbers in 123.45 format detection, fast shared strings index (thx fredriksundin)<br/>
v0.9.16 (2020-07-29) Fixed time detection in HH:MM:SS format<br/> v0.9.16 (2020-07-29) Fixed time detection in HH:MM:SS format<br/>
v0.9.15 (2020-07-14) escape of shared strings for special chars in cells [#1](https://github.com/shuchkin/simplexlsxgen/issues/1) <br/> v0.9.15 (2020-07-14) escape of shared strings for special chars in cells [#1](https://github.com/shuchkin/simplexlsxgen/issues/1) <br/>

View File

@ -58,11 +58,13 @@ class SimpleXLSXGen {
<cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" /></cellStyleXfs> <cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" /></cellStyleXfs>
<cellXfs count="6"> <cellXfs count="6">
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/> <xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>
<xf numFmtId="9" fontId="0" fillId="0" borderId="0" xfId="0"/> <xf numFmtId="1" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
<xf numFmtId="10" fontId="0" fillId="0" borderId="0" xfId="0"/> <xf numFmtId="9" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
<xf numFmtId="14" fontId="0" fillId="0" borderId="0" xfId="0"/> <xf numFmtId="10" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
<xf numFmtId="20" fontId="0" fillId="0" borderId="0" xfId="0"/> <xf numFmtId="14" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
<xf numFmtId="22" fontId="0" fillId="0" borderId="0" xfId="0"/> <xf numFmtId="20" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
<xf numFmtId="22" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1" applyAlignment="1"><alignment horizontal="right"/></xf>
</cellXfs> </cellXfs>
<cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles> <cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles>
</styleSheet>', </styleSheet>',
@ -180,7 +182,9 @@ class SimpleXLSXGen {
if ( $v === null || $v === '' ) { if ( $v === null || $v === '' ) {
continue; continue;
} }
$COL[ $CUR_COL ] = max( mb_strlen( (string) $v ), $COL[ $CUR_COL ] ); $vl = mb_strlen( (string) $v );
$COL[ $CUR_COL ] = max( $vl, $COL[ $CUR_COL ] );
$cname = $this->num2name($CUR_COL) . $CUR_ROW; $cname = $this->num2name($CUR_COL) . $CUR_ROW;
@ -188,29 +192,35 @@ class SimpleXLSXGen {
if ( is_string($v) ) { if ( is_string($v) ) {
if ( preg_match( '/^[-+]?[1-9]\d{0,17}$/', $v ) ) { if ( $v === '0' || preg_match( '/^[-+]?[1-9]\d{0,14}$/', $v ) ) { // Integer as General
$cv = ltrim($v,'+'); $cv = ltrim( $v, '+' );
if ( $vl > 10 ) {
$cs = 1; // [1] 0
}
} elseif ( preg_match('/^[-+]?(0|[1-9]\d*)\.\d+$/', $v ) ) { } elseif ( preg_match('/^[-+]?(0|[1-9]\d*)\.\d+$/', $v ) ) {
$cv = ltrim($v,'+'); $cv = ltrim($v,'+');
} elseif ( preg_match('/^([-+]?\d+)%$/', $v, $m) ) { } elseif ( preg_match('/^([-+]?\d+)%$/', $v, $m) ) {
$cv = round( $m[1] / 100, 2); $cv = round( $m[1] / 100, 2);
$cs = 1; // [9] 0% $cs = 2; // [9] 0%
} elseif ( preg_match('/^([-+]\d+\.\d+)%$/', $v, $m) ) { } elseif ( preg_match('/^([-+]\d+\.\d+)%$/', $v, $m) ) {
$cv = round( $m[1] / 100, 4 ); $cv = round( $m[1] / 100, 4 );
$cs = 2; // [10] 0.00% $cs = 3; // [10] 0.00%
} elseif ( preg_match('/^(\d\d\d\d)-(\d\d)-(\d\d)$/', $v, $m ) ){ } elseif ( preg_match('/^(\d\d\d\d)-(\d\d)-(\d\d)$/', $v, $m ) ){
$cv = $this->date2excel($m[1],$m[2],$m[3]); $cv = $this->date2excel($m[1],$m[2],$m[3]);
$cs = 3; // [14] mm-dd-yy $cs = 4; // [14] mm-dd-yy
} elseif ( preg_match('/^(\d\d):(\d\d):(\d\d)$/', $v, $m ) ){ } elseif ( preg_match('/^(\d\d):(\d\d):(\d\d)$/', $v, $m ) ){
$cv = $this->date2excel(0,0,0,$m[1],$m[2],$m[3]); $cv = $this->date2excel(0,0,0,$m[1],$m[2],$m[3]);
$cs = 4; // [14] mm-dd-yy $cs = 5; // [14] mm-dd-yy
} elseif ( preg_match('/^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/', $v, $m ) ) { } elseif ( preg_match('/^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/', $v, $m ) ) {
$cv = $this->date2excel( $m[1], $m[2], $m[3], $m[4], $m[5], $m[6] ); $cv = $this->date2excel( $m[1], $m[2], $m[3], $m[4], $m[5], $m[6] );
$cs = 5; // [22] m/d/yy h:mm $cs = 6; // [22] m/d/yy h:mm
} elseif ( mb_strlen( $v ) > 160 ) { } elseif ( mb_strlen( $v ) > 160 ) {
$ct = 'inlineStr'; $ct = 'inlineStr';
$cv = str_replace(['&','<','>'],['&amp;','&lt;','&gt;'], $v); $cv = str_replace(['&','<','>'],['&amp;','&lt;','&gt;'], $v);
} else { } else {
if ( preg_match('/^[0-9+-.]+$/', $v ) ) { // Long ?
$cs = 7; // Align Right
}
$ct = 's'; // shared string $ct = 's'; // shared string
$v = str_replace(['&','<','>'],['&amp;','&lt;','&gt;'], $v); $v = str_replace(['&','<','>'],['&amp;','&lt;','&gt;'], $v);
$cv = false; $cv = false;