mirror of
https://github.com/shuchkin/simplexlsxgen.git
synced 2023-08-10 21:12:59 +03:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
9b2c9d3e1c | |||
9824e5b25d | |||
c3d64d13ef | |||
22cbd84f3c | |||
291b508143 | |||
5a4c04025a | |||
982de475c9 | |||
e92d3a5284 |
@ -1,4 +1,4 @@
|
||||
# SimpleXLSXGen class 0.9.15 (Official)
|
||||
# SimpleXLSXGen class 0.9.17 (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/>
|
||||
@ -40,8 +40,9 @@ $data = [
|
||||
['Integer', 123],
|
||||
['Float', 12.35],
|
||||
['Procent', '12%'],
|
||||
['Date','2020-05-20'],
|
||||
['Datetime', '2020-05-20 02:38:00'],
|
||||
['Date','2020-05-20'],
|
||||
['Time','02:38:00'],
|
||||
['String', 'See SimpleXLSXGen column autosize feature']
|
||||
];
|
||||
SimpleXLSXGen::fromArray( $data )->saveAs('datatypes.xlsx');
|
||||
@ -61,6 +62,8 @@ SimpleXLSXGen::fromArray( $data )->saveAs('debug.xlsx');
|
||||
|
||||
|
||||
## History
|
||||
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.15 (2020-07-14) escape of shared strings for special chars in cells [#1](https://github.com/shuchkin/simplexlsxgen/issues/1) <br/>
|
||||
v0.9.14 (2020-05-31) fixed num2name A-Z,AA-AZ column names, thx Ertan Yusufoglu<br/>
|
||||
v0.9.13 (2020-05-21) if string more 160 chars, save as inlineStr<br/>
|
||||
|
@ -117,7 +117,7 @@ class SimpleXLSXGen {
|
||||
return true;
|
||||
}
|
||||
public function download() {
|
||||
return $this->downloadAs( gmdate('YmdHi.xlsx') );
|
||||
return $this->downloadAs( gmdate('YmdHi') . '.xlsx' );
|
||||
}
|
||||
public function downloadAs( $filename ) {
|
||||
$fh = fopen('php://memory','wb');
|
||||
@ -162,6 +162,7 @@ class SimpleXLSXGen {
|
||||
}
|
||||
|
||||
$SI = [];
|
||||
$SI_KEYS = [];
|
||||
$COLS = [];
|
||||
$ROWS = [];
|
||||
if ( count($this->rows) ) {
|
||||
@ -189,12 +190,12 @@ class SimpleXLSXGen {
|
||||
|
||||
if ( preg_match( '/^[-+]?\d{1,18}$/', $v ) ) {
|
||||
$cv = ltrim($v,'+');
|
||||
} elseif ( preg_match('/^[-+]?\d+\.?\d*$/', $v ) ) {
|
||||
} elseif ( preg_match('/^[-+]?\d+\.\d+$/', $v ) ) {
|
||||
$cv = ltrim($v,'+');
|
||||
} elseif ( preg_match('/^([-+]?\d+)%$/', $v, $m) ) {
|
||||
$cv = round( $m[1] / 100, 2);
|
||||
$cs = 1; // [9] 0%
|
||||
} elseif ( preg_match('/^([-+]\d+\.\d*)%$/', $v, $m) ) {
|
||||
} elseif ( preg_match('/^([-+]\d+\.\d+)%$/', $v, $m) ) {
|
||||
$cv = round( $m[1] / 100, 4 );
|
||||
$cs = 2; // [10] 0.00%
|
||||
} elseif ( preg_match('/^(\d\d\d\d)-(\d\d)-(\d\d)$/', $v, $m ) ){
|
||||
@ -212,10 +213,15 @@ class SimpleXLSXGen {
|
||||
} else {
|
||||
$ct = 's'; // shared string
|
||||
$v = str_replace(['&','<','>'],['&','<','>'], $v);
|
||||
$cv = array_search( $v, $SI, true );
|
||||
$cv = false;
|
||||
if ( isset($SI_KEYS[$v]) ) {
|
||||
$cv = $SI_KEYS[$v];
|
||||
}
|
||||
|
||||
if ( $cv === false ) {
|
||||
$SI[] = $v;
|
||||
$cv = count( $SI ) - 1;
|
||||
$SI_KEYS[$v] = $cv;
|
||||
}
|
||||
}
|
||||
} elseif ( is_int( $v ) || is_float( $v ) ) {
|
||||
@ -357,6 +363,12 @@ class SimpleXLSXGen {
|
||||
return $letter;
|
||||
}
|
||||
public function date2excel($year, $month, $day, $hours=0, $minutes=0, $seconds=0) {
|
||||
$excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;
|
||||
|
||||
if ( $year === 0 ) {
|
||||
return $excelTime;
|
||||
}
|
||||
|
||||
// self::CALENDAR_WINDOWS_1900
|
||||
$excel1900isLeapYear = True;
|
||||
if (((int)$year === 1900) && ($month <= 2)) { $excel1900isLeapYear = False; }
|
||||
@ -374,8 +386,6 @@ class SimpleXLSXGen {
|
||||
$decade = substr($year,2,2);
|
||||
$excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $myExcelBaseDate + $excel1900isLeapYear;
|
||||
|
||||
$excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;
|
||||
|
||||
return (float) $excelDate + $excelTime;
|
||||
}
|
||||
}
|
||||
return (float) $excelDate + $excelTime;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user