Pman.Gnumeric.js
[Pman.Core] / ExcelToJson.php
index 88fa435..e981d32 100644 (file)
@@ -12,7 +12,7 @@ class Pman_Core_ExcelToJson extends Pman_Roo
         return parent::getAuth();
     }
     
-    function post()
+    function post($v)
     {
         $this->transObj = DB_DataObject::Factory('invhist_transfer');
         
@@ -29,13 +29,16 @@ class Pman_Core_ExcelToJson extends Pman_Roo
         
         require_once 'File/Convert.php';
         $fc = new File_Convert($img->getStoreName(), $img->mimetype );
-        $csv = $fc->convert('text/csv');
-        $data = $this->importCsv($this->walkrows($csv));
-        $this->jdata($data);
+         $csv = $fc->convert('text/csv');
+         $ret = $this->importCsv($csv);
+        
+       
+        
+        $this->jdata($ret['data'], false, isset($ret['extra']) ? $ret['extra'] : array() );
         
     }
     
-    function walkrows($csv)
+    function importCsv($csv)
     {
         ini_set("auto_detect_line_endings", true);
         
@@ -48,10 +51,12 @@ class Pman_Core_ExcelToJson extends Pman_Roo
         $cols = false;
         $header = false;
         $rows = array();
-        $ret = array();
+        $extra = array();
         
         while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
-            if(!array_filter($n)){
+          
+            
+            if(!strlen(trim(implode('', $n)))){ // blank line;
                 if ($header) {
                     continue;
                 }
@@ -60,7 +65,7 @@ class Pman_Core_ExcelToJson extends Pman_Roo
             }
             
             if(!$header){
-               $ret[preg_replace(array('/\s/', '/\:/'), '', $n[0])] = $n[1];
+               $extra[preg_replace(array('/\s/', '/\:/'), '', $n[0])] = $n[1];
                continue;
             }
             
@@ -86,6 +91,8 @@ class Pman_Core_ExcelToJson extends Pman_Roo
         }
         fclose($fh);
         
-        return array('ret' => $ret, 'rows' => $rows);;
+     
+        
+        return array('extra' => $extra, 'data' => $rows);;
     }
 }
\ No newline at end of file