From f5d72b0bbf09fd9d0037ea107839946ac77997e4 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 24 Aug 2022 13:02:03 +0200 Subject: [PATCH] wip #5414 @0.25 --- src/ExcelToArray.php | 52 +++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/ExcelToArray.php b/src/ExcelToArray.php index 526d5af..42da32b 100644 --- a/src/ExcelToArray.php +++ b/src/ExcelToArray.php @@ -61,6 +61,10 @@ class ExcelToArray throw new Exception('The file type ' . $ext . ' is not supported'); } + public static function excelToArrayRaw($file, $force = false) + { + return self::_excelToArray($file, false, $force); + } /** * @throws Exception @@ -167,9 +171,14 @@ class ExcelToArray return $res; } - public static function excelToArrayIndexKeyVars($file, $skipEmptyId = false, $force = false) + /** + * @param $file + * @param $force + * @return \PhpOffice\PhpSpreadsheet\Spreadsheet + * @throws Exception + */ + protected static function _excelToArrayKeyVarsCommon($file, $force = false) { - $e = explode('#', $file); $file = $e[0]; @@ -184,7 +193,15 @@ class ExcelToArray } else { $worksheet = array_shift($worksheets); } + return $worksheet; + } + /** + * @throws Exception + */ + public static function excelToArrayIndexKeyVars($file, $force = false) + { + $worksheet = self::_excelToArrayKeyVarsCommon($file, $force); $res = []; foreach ($worksheet as $i => $line) { if ($i === 0) { @@ -207,24 +224,12 @@ class ExcelToArray return $res; } + /** + * @throws Exception + */ public static function excelToArrayKeyVars($file, $skipEmptyId = false, $force = false) { - $e = explode('#', $file); - $file = $e[0]; - - $worksheets = self::_excelToArray($file, false, $force); - - if (isset($e[1])) { - $sheetName = trim($e[1]); - } - - if (isset($sheetName, $worksheets[$sheetName])) { - $worksheet = $worksheets[$sheetName]; - } else { - $worksheet = array_shift($worksheets); - } - - + $worksheet = self::_excelToArrayKeyVarsCommon($file, $force); $res = []; foreach ($worksheet as $i => $line) { if ($i === 0) { @@ -260,9 +265,12 @@ class ExcelToArray return $res; } - public static function excelToArrayKeyValMulti($file,$force = false) + /** + * @throws Exception + */ + public static function excelToArrayKeyValMulti($file, $force = false) { - $worksheets = self::_excelToArray($file, false, $force); + $worksheets = self::_excelToArray($file, false, $force); $res = []; foreach ($worksheets as $worksheet) { foreach ($worksheet as $line) { @@ -278,6 +286,10 @@ class ExcelToArray return $res; } + /** + * @param $s + * @return array + */ protected static function _assocSheet($s) { $res = []; -- 2.39.5