From 58ec5aaff0cdc2102efbae1f52377beeb8cadf16 Mon Sep 17 00:00:00 2001 From: Abdulraheem-Radman <42248034+Abdulraheem-Radman@users.noreply.github.com> Date: Wed, 3 Aug 2022 01:06:05 +0300 Subject: [PATCH 1/6] update to php8 --- SpreadsheetReader_XLSX.php | 39 ++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/SpreadsheetReader_XLSX.php b/SpreadsheetReader_XLSX.php index 9cf8d12..88b1356 100644 --- a/SpreadsheetReader_XLSX.php +++ b/SpreadsheetReader_XLSX.php @@ -941,7 +941,7 @@ public function GeneralFormat($Value) * Rewind the Iterator to the first element. * Similar to the reset() function for arrays in PHP */ - public function rewind() + public function rewind(): void { // Removed the check whether $this -> Index == 0 otherwise ChangeSheet doesn't work properly @@ -956,12 +956,21 @@ public function rewind() $this -> Worksheet = new XMLReader; } - $this -> Worksheet -> open($this -> WorksheetPath); + try{ + if(empty($this -> WorksheetPath)){ + throw new Exception('SpreadsheetReader_XLSX: Error in File or sheet name'); + } else { + $this -> Worksheet -> open($this -> WorksheetPath); - $this -> Valid = true; - $this -> RowOpen = false; - $this -> CurrentRow = false; - $this -> Index = 0; + $this -> Valid = true; + $this -> RowOpen = false; + $this -> CurrentRow = false; + $this -> Index = 0; + + } + } catch (Exception $ex){ + throw new Exception('SpreadsheetReader_XLSX: Error in File or sheet name'); + } } /** @@ -970,7 +979,7 @@ public function rewind() * * @return mixed current element from the collection */ - public function current() + public function current(): mixed { if ($this -> Index == 0 && $this -> CurrentRow === false) { @@ -984,7 +993,7 @@ public function current() * Move forward to next element. * Similar to the next() function for arrays in PHP */ - public function next() + public function next(): void { $this -> Index++; @@ -1046,7 +1055,8 @@ public function next() // If it is a closing tag, skip it if ($this -> Worksheet -> nodeType == XMLReader::END_ELEMENT) { - continue; + break; + //continue; } $StyleId = (int)$this -> Worksheet -> getAttribute('s'); @@ -1080,7 +1090,8 @@ public function next() case 'is': if ($this -> Worksheet -> nodeType == XMLReader::END_ELEMENT) { - continue; + break; + //continue; } $Value = $this -> Worksheet -> readString(); @@ -1114,7 +1125,7 @@ public function next() } } - return $this -> CurrentRow; + //return $this -> CurrentRow; } /** @@ -1123,7 +1134,7 @@ public function next() * * @return mixed either an integer or a string */ - public function key() + public function key(): mixed { return $this -> Index; } @@ -1134,7 +1145,7 @@ public function key() * * @return boolean FALSE if there's nothing more to iterate over */ - public function valid() + public function valid(): bool { return $this -> Valid; } @@ -1144,7 +1155,7 @@ public function valid() * Ostensibly should return the count of the contained items but this just returns the number * of rows read so far. It's not really correct but at least coherent. */ - public function count() + public function count(): int { return $this -> Index + 1; } From 39c6739e7a824f84a4b709427c131b51055a161c Mon Sep 17 00:00:00 2001 From: Abdulraheem-Radman <42248034+Abdulraheem-Radman@users.noreply.github.com> Date: Wed, 3 Aug 2022 01:13:51 +0300 Subject: [PATCH 2/6] Update SpreadsheetReader.php --- SpreadsheetReader.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/SpreadsheetReader.php b/SpreadsheetReader.php index b019f8f..ebb26f7 100644 --- a/SpreadsheetReader.php +++ b/SpreadsheetReader.php @@ -43,7 +43,7 @@ public function __construct($Filepath, $OriginalFilename = false, $MimeType = fa { throw new Exception('SpreadsheetReader: File ('.$Filepath.') not readable'); } - + // To avoid timezone warnings and exceptions for formatting dates retrieved from files $DefaultTZ = @date_default_timezone_get(); if ($DefaultTZ) @@ -70,7 +70,7 @@ public function __construct($Filepath, $OriginalFilename = false, $MimeType = fa } $Extension = strtolower(pathinfo($OriginalFilename, PATHINFO_EXTENSION)); - + switch ($MimeType) { case 'text/csv': @@ -230,7 +230,7 @@ private static function Load($Type) * Rewind the Iterator to the first element. * Similar to the reset() function for arrays in PHP */ - public function rewind() + public function rewind(): void { $this -> Index = 0; if ($this -> Handle) @@ -245,7 +245,7 @@ public function rewind() * * @return mixed current element from the collection */ - public function current() + public function current(): mixed { if ($this -> Handle) { @@ -258,15 +258,15 @@ public function current() * Move forward to next element. * Similar to the next() function for arrays in PHP */ - public function next() + public function next(): void { if ($this -> Handle) { $this -> Index++; - return $this -> Handle -> next(); + $this -> Handle -> next(); } - return null; + //return null; } /** @@ -275,7 +275,7 @@ public function next() * * @return mixed either an integer or a string */ - public function key() + public function key(): mixed { if ($this -> Handle) { @@ -290,7 +290,7 @@ public function key() * * @return boolean FALSE if there's nothing more to iterate over */ - public function valid() + public function valid(): bool { if ($this -> Handle) { @@ -300,7 +300,7 @@ public function valid() } // !Countable interface method - public function count() + public function count(): int { if ($this -> Handle) { @@ -315,13 +315,17 @@ public function count() * * @param int Position in file */ - public function seek($Position) + public function seek($Position): void { if (!$this -> Handle) { throw new OutOfBoundsException('SpreadsheetReader: No file opened'); } + if (!isset($this ->Handle[$position])) { + throw new OutOfBoundsException("invalid seek position ($position)"); + } + $CurrentIndex = $this -> Handle -> key(); if ($CurrentIndex != $Position) @@ -342,7 +346,7 @@ public function seek($Position) } } - return null; + //return null; } } ?> From ec1820c24137f20689f8a30f4fc71be902917993 Mon Sep 17 00:00:00 2001 From: Abdulraheem-Radman <42248034+Abdulraheem-Radman@users.noreply.github.com> Date: Wed, 3 Aug 2022 01:15:02 +0300 Subject: [PATCH 3/6] Update SpreadsheetReader_CSV.php --- SpreadsheetReader_CSV.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SpreadsheetReader_CSV.php b/SpreadsheetReader_CSV.php index 1cae82b..1b122ce 100644 --- a/SpreadsheetReader_CSV.php +++ b/SpreadsheetReader_CSV.php @@ -156,7 +156,7 @@ public function ChangeSheet($Index) * Rewind the Iterator to the first element. * Similar to the reset() function for arrays in PHP */ - public function rewind() + public function rewind(): void { fseek($this -> Handle, $this -> BOMLength); $this -> CurrentRow = null; @@ -169,7 +169,7 @@ public function rewind() * * @return mixed current element from the collection */ - public function current() + public function current(): mixed { if ($this -> Index == 0 && is_null($this -> CurrentRow)) { @@ -183,7 +183,7 @@ public function current() * Move forward to next element. * Similar to the next() function for arrays in PHP */ - public function next() + public function next(): void { $this -> CurrentRow = array(); @@ -239,7 +239,7 @@ public function next() } } - return $this -> CurrentRow; + //return $this -> CurrentRow; } /** @@ -248,7 +248,7 @@ public function next() * * @return mixed either an integer or a string */ - public function key() + public function key(): mixed { return $this -> Index; } @@ -259,7 +259,7 @@ public function key() * * @return boolean FALSE if there's nothing more to iterate over */ - public function valid() + public function valid(): bool { return ($this -> CurrentRow || !feof($this -> Handle)); } @@ -269,9 +269,9 @@ public function valid() * Ostensibly should return the count of the contained items but this just returns the number * of rows read so far. It's not really correct but at least coherent. */ - public function count() + public function count(): int { return $this -> Index + 1; } } -?> \ No newline at end of file +?> From 814a4b979f72e8d253ef5ad14a1d03483be8d276 Mon Sep 17 00:00:00 2001 From: Abdulraheem-Radman <42248034+Abdulraheem-Radman@users.noreply.github.com> Date: Wed, 3 Aug 2022 01:16:03 +0300 Subject: [PATCH 4/6] Update SpreadsheetReader_ODS.php --- SpreadsheetReader_ODS.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SpreadsheetReader_ODS.php b/SpreadsheetReader_ODS.php index b12d9e7..60642dc 100644 --- a/SpreadsheetReader_ODS.php +++ b/SpreadsheetReader_ODS.php @@ -157,7 +157,7 @@ public function ChangeSheet($Index) * Rewind the Iterator to the first element. * Similar to the reset() function for arrays in PHP */ - public function rewind() + public function rewind(): void { if ($this -> Index > 0) { @@ -182,7 +182,7 @@ public function rewind() * * @return mixed current element from the collection */ - public function current() + public function current(): mixed { if ($this -> Index == 0 && is_null($this -> CurrentRow)) { @@ -196,7 +196,7 @@ public function current() * Move forward to next element. * Similar to the next() function for arrays in PHP */ - public function next() + public function next(): void { $this -> Index++; @@ -301,7 +301,7 @@ public function next() } } - return $this -> CurrentRow; + //return $this -> CurrentRow; } /** @@ -310,7 +310,7 @@ public function next() * * @return mixed either an integer or a string */ - public function key() + public function key(): mixed { return $this -> Index; } @@ -321,7 +321,7 @@ public function key() * * @return boolean FALSE if there's nothing more to iterate over */ - public function valid() + public function valid(): bool { return $this -> Valid; } @@ -331,9 +331,9 @@ public function valid() * Ostensibly should return the count of the contained items but this just returns the number * of rows read so far. It's not really correct but at least coherent. */ - public function count() + public function count(): int { return $this -> Index + 1; } } -?> \ No newline at end of file +?> From 5634aa64e2b690cdab1c7b0bfaeb798e6a79a84a Mon Sep 17 00:00:00 2001 From: Abdulraheem-Radman <42248034+Abdulraheem-Radman@users.noreply.github.com> Date: Wed, 3 Aug 2022 01:17:48 +0300 Subject: [PATCH 5/6] Update SpreadsheetReader_XLS.php --- SpreadsheetReader_XLS.php | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/SpreadsheetReader_XLS.php b/SpreadsheetReader_XLS.php index 2031f07..3ca9fec 100644 --- a/SpreadsheetReader_XLS.php +++ b/SpreadsheetReader_XLS.php @@ -165,7 +165,7 @@ public function __get($Name) * Rewind the Iterator to the first element. * Similar to the reset() function for arrays in PHP */ - public function rewind() + public function rewind(): void { $this -> Index = 0; } @@ -176,7 +176,7 @@ public function rewind() * * @return mixed current element from the collection */ - public function current() + public function current(): mixed { if ($this -> Index == 0) { @@ -190,35 +190,37 @@ public function current() * Move forward to next element. * Similar to the next() function for arrays in PHP */ - public function next() + public function next(): void { // Internal counter is advanced here instead of the if statement // because apparently it's fully possible that an empty row will not be // present at all $this -> Index++; + + $this -> CurrentRow = array(); if ($this -> Error) { - return array(); + //return array(); } elseif (isset($this -> Handle -> sheets[$this -> CurrentSheet]['cells'][$this -> Index])) { $this -> CurrentRow = $this -> Handle -> sheets[$this -> CurrentSheet]['cells'][$this -> Index]; - if (!$this -> CurrentRow) + if ($this -> CurrentRow) { - return array(); - } + $this -> CurrentRow = $this -> CurrentRow + $this -> EmptyRow; + ksort($this -> CurrentRow); - $this -> CurrentRow = $this -> CurrentRow + $this -> EmptyRow; - ksort($this -> CurrentRow); + $this -> CurrentRow = array_values($this -> CurrentRow); + //return $this -> CurrentRow; + } + //return array(); - $this -> CurrentRow = array_values($this -> CurrentRow); - return $this -> CurrentRow; } else { $this -> CurrentRow = $this -> EmptyRow; - return $this -> CurrentRow; + //return $this -> CurrentRow; } } @@ -228,7 +230,7 @@ public function next() * * @return mixed either an integer or a string */ - public function key() + public function key(): mixed { return $this -> Index; } @@ -239,7 +241,7 @@ public function key() * * @return boolean FALSE if there's nothing more to iterate over */ - public function valid() + public function valid(): bool { if ($this -> Error) { @@ -253,7 +255,7 @@ public function valid() * Ostensibly should return the count of the contained items but this just returns the number * of rows read so far. It's not really correct but at least coherent. */ - public function count() + public function count(): int { if ($this -> Error) { @@ -263,4 +265,4 @@ public function count() return $this -> RowCount; } } -?> \ No newline at end of file +?> From 95fd3d47a5e4999b31855112961b93839676b32b Mon Sep 17 00:00:00 2001 From: Abdulraheem-Radman <42248034+Abdulraheem-Radman@users.noreply.github.com> Date: Wed, 3 Aug 2022 01:31:03 +0300 Subject: [PATCH 6/6] Update SpreadsheetReader_XLSX.php --- SpreadsheetReader_XLSX.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/SpreadsheetReader_XLSX.php b/SpreadsheetReader_XLSX.php index 88b1356..3249632 100644 --- a/SpreadsheetReader_XLSX.php +++ b/SpreadsheetReader_XLSX.php @@ -451,11 +451,10 @@ private function PrepareSharedStringCache() } break; case 't': - if ($this -> SharedStrings -> nodeType == XMLReader::END_ELEMENT) + if ($this -> SharedStrings -> nodeType != XMLReader::END_ELEMENT) { - continue; + $CacheValue .= $this -> SharedStrings -> readString(); } - $CacheValue .= $this -> SharedStrings -> readString(); break; } } @@ -576,11 +575,10 @@ private function GetSharedString($Index) switch ($this -> SharedStrings -> name) { case 't': - if ($this -> SharedStrings -> nodeType == XMLReader::END_ELEMENT) + if ($this -> SharedStrings -> nodeType != XMLReader::END_ELEMENT) { - continue; + $Value .= $this -> SharedStrings -> readString(); } - $Value .= $this -> SharedStrings -> readString(); break; case 'si': if ($this -> SharedStrings -> nodeType == XMLReader::END_ELEMENT)