Skip to content

Commit cb4db00

Browse files
committed
0.9.5 fixed negative number values and datetime values
1 parent 3d2c0be commit cb4db00

File tree

2 files changed

+14
-45
lines changed

2 files changed

+14
-45
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# SimpleXLS class 0.9.4
1+
# SimpleXLS class 0.9.5
22
[<img src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.herokuapp.com%2Fshuchkin" />](https://www.patreon.com/shuchkin)
33

44
Parse and retrieve data from old Excel XLS files. MS Excel 97 workbooks PHP reader. PHP BIFF reader. No addiditional extensions need (internal olereader). XLS only, MS Excel 2003+ php reader [here](https://github.com/shuchkin/simplexlsx)
55

6-
**Sergey Shuchkin** <sergey.shuchkin@gmail.com> 2016-2018<br/>
6+
**Sergey Shuchkin** <sergey.shuchkin@gmail.com> 2016-2020<br/>
77

88
## Basic Usage
99
```php
@@ -63,6 +63,7 @@ if ($xls->success()) {
6363

6464
## History
6565
```
66+
0.9.5 (2020-01-16) fixed negative number values and datetime values
6667
0.9.4 (2019-03-14) Added git Tag for prevent composer warning
6768
0.9.3 (2019-02-19) Fixed datetime detection
6869
0.9.2 (2018-11-15) GitHub realese, composer

src/SimpleXLS.php

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,8 @@
1717
/**
1818
* A class for reading Microsoft Excel Spreadsheets.
1919
*
20-
* Originally developed by Vadim Tkachenko under the name PHPExcelReader.
21-
* (http://sourceforge.net/projects/phpexcelreader)
22-
* Based on the Java version by Andy Khan (http://www.andykhan.com).
23-
* Maintained by David Sanders. Reads only Biff 7 and Biff 8 formats.
24-
*
25-
* SimpleXLS version 2016 build by sergey.shuchkin@gmail.com
26-
*
27-
* @category Spreadsheet
28-
* @package SimpleXLS
29-
* @author Vadim Tkachenko <vt@phpapache.com>, Sergey Shuchkin <sergey.shuchkin@gmail.com>
30-
* @copyright 1997-2016 The PHP Group
31-
* @license http://www.php.net/license/3_0.txt PHP License 3.0
32-
* @version Release: 0.9.1
33-
* @link
34-
* @see OLE, Spreadsheet_Excel_Writer, SimpleXLSX
20+
* SimpleXLS version 2016-2020 packaged by Sergey Shuchkin <sergey.shuchkin@gmail.com> from
21+
* Spreadsheet_Excel_Reader class developed by Vadim Tkachenko <vt@phpapache.com>
3522
*/
3623
class SimpleXLS {
3724
const BIFF8 = 0x600;
@@ -71,11 +58,6 @@ class SimpleXLS {
7158
const TYPE_NINETEENFOUR = 0x22;
7259
const TYPE_MERGEDCELLS = 0xE5;
7360

74-
const UTCOFFSETDAYS = 25569;
75-
const UTCOFFSETDAYS1904 = 24107;
76-
const MSINADAY = 86400;
77-
//const MSINADAY = 24 * 60 * 60;
78-
7961
//const DEF_NUM_FORMAT = "%.2f";
8062
const DEF_NUM_FORMAT = '%s';
8163

@@ -436,11 +418,7 @@ private function _oleread( $sFileName, $isData = false ) {
436418

437419
public function _GetInt4d( $data, $pos ) {
438420
$value = ord( $data[ $pos ] ) | ( ord( $data[ $pos + 1 ] ) << 8 ) | ( ord( $data[ $pos + 2 ] ) << 16 ) | ( ord( $data[ $pos + 3 ] ) << 24 );
439-
if ( $value >= 4294967294 ) {
440-
$value = - 2;
441-
}
442-
443-
return $value;
421+
return ($value > 0x7FFFFFFF) ? $value - 0x100000000 : $value;
444422
}
445423

446424
// }}}
@@ -1144,29 +1122,19 @@ public function isDate( $spos ) {
11441122
* Dates in Excel are stored as number of seconds from an epoch. On
11451123
* Windows, the epoch is 30/12/1899 and on Mac it's 01/01/1904
11461124
*
1147-
* @access private
1148-
*
1149-
* @param integer $numValue The raw Excel value to convert
1125+
* @param integer $timevalue The raw Excel value to convert
11501126
*
11511127
* @return array First element is the converted date, the second element is number a unix timestamp
11521128
*/
1153-
public function createDate( $numValue ) {
1154-
if ( $numValue > 1 ) {
1155-
$utcDays = $numValue - ( $this->nineteenFour ? self::UTCOFFSETDAYS1904 : self::UTCOFFSETDAYS );
1156-
$utcValue = round( ( $utcDays + 1 ) * self::MSINADAY );
1157-
$string = $this->datetimeFormat ? gmdate( $this->datetimeFormat, $utcValue ) : gmdate( $this->curFormat, $utcValue );
1158-
$raw = $utcValue;
1159-
} else {
1160-
$raw = $numValue;
1161-
$hours = floor( $numValue * 24 );
1162-
/** @noinspection SummerTimeUnsafeTimeManipulationInspection */
1163-
$mins = floor( $numValue * 24 * 60 ) - $hours * 60;
1164-
$secs = floor( $numValue * self::MSINADAY ) - $hours * 60 * 60 - $mins * 60;
1165-
$ts = mktime( $hours, $mins, $secs );
1166-
$string = $this->datetimeFormat ? gmdate( $this->datetimeFormat, $ts ) : gmdate( $this->curFormat, $ts );
1129+
public function createDate( $timevalue ) {
1130+
// $offset = ($timeoffset===null)? date('Z') : $timeoffset * 3600;
1131+
if ($timevalue > 1) {
1132+
$timevalue -= ( $this->nineteenFour ? 24107 : 25569 );
11671133
}
1134+
$ts = round($timevalue * 24 * 3600);
1135+
$string = $this->datetimeFormat ? gmdate( $this->datetimeFormat, $ts ) : gmdate( $this->curFormat, $ts );
1136+
return array( $string, $ts );
11681137

1169-
return array( $string, $raw );
11701138
}
11711139

11721140
public function addcell( $row, $col, $string, $raw = '' ) {

0 commit comments

Comments
 (0)