]> _ Git - cubist_excel.git/commitdiff
wip #5414 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 24 Aug 2022 11:02:03 +0000 (13:02 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 24 Aug 2022 11:02:03 +0000 (13:02 +0200)
src/ExcelToArray.php

index 526d5af267f34a30205dcfd6613d6ce76073e7f8..42da32be02bc141b09ff8f06f064fa7fb1dc6b37 100644 (file)
@@ -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 = [];