ExcelToJson.php
[Pman.Core] / ExcelToJson.php
index 4c885ea..3072cb4 100644 (file)
@@ -43,15 +43,25 @@ class Pman_Core_ExcelToJson extends Pman_Roo
         }
         
         $req = array(
-            
+            'LINE', 'ITEM CODE', 'DESCRIPTION', 'QUANTITY'
         );
         
         $cols = false;
         $rows = array();
+        $header = false;
         
         while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
-            if (!$cols) {
-                
+            if(!array_filter($n)){
+                $header = true;
+                continue;
+            }
+            
+            if(!$header){
+               $rows[$n[0]] = $n[1];
+               continue;
+            }
+            
+            if(!$cols){
                 $cols = array();
                 foreach($n as $k) {
                     $cols[] = strtoupper(trim($k));
@@ -60,6 +70,7 @@ class Pman_Core_ExcelToJson extends Pman_Roo
                 if (empty($cols)) {
                     continue;
                 }
+               
                 foreach($req as $r) {
                     if (!in_array($r,$cols)) {
                         $cols = false;
@@ -68,16 +79,18 @@ class Pman_Core_ExcelToJson extends Pman_Roo
                 }
                 continue;
             }
+            
             foreach($cols as $i=>$k) {
                 $row[$k] = $n[$i];
             }
             $rows[] = $row;
+            
         }
         
         if (empty($cols)) {
             $this->jerr("could not find a row with " . implode(' / ', $req));
         }
-        
+        print_r($cols);
         fclose($fh);
         
         exit;