SimpleExcel.php
[Pman.Core] / SimpleExcel.php
index 519343a..02c29bf 100644 (file)
@@ -34,7 +34,7 @@
         workbooks = array(
             workbook ->
             
-            
+        'leave_open' => false  
             
  */
  
@@ -45,7 +45,7 @@
 class Pman_Core_SimpleExcel extends Pman
 {
     
-    var $workSheetCfg = array();
+    var $worksheet_cfg = array();
     var $start_row = 0;
     var $formats = array();
     var $workbook = false;
@@ -84,7 +84,7 @@ class Pman_Core_SimpleExcel extends Pman
             
         }
         
-        if (empty($cfg['leave_open'])) {
+        if (!empty($cfg['leave_open'])) {
             $this->workbook = $workbook;
             $this->outfile2 = $outfile2;
             return;
@@ -109,9 +109,9 @@ class Pman_Core_SimpleExcel extends Pman
         //echo '<PRE>';        print_R($cfg);
       //  print_r($cfg);exit;
         // Creating a worksheet
-        
+        //print_R($cfg);exit;
         // copy the config and alias so that book can be written to..
-        $this->worksheetCfg[$cfg['workbook']] = &$cfg;
+        $this->worksheet_cfg[$cfg['workbook']] = &$cfg;
         
         $worksheet =  $workbook->addWorksheet($cfg['workbook']);
         if (is_a($worksheet, 'PEAR_Error')) {
@@ -142,9 +142,7 @@ class Pman_Core_SimpleExcel extends Pman
             $start_row++;
         }
             
-            
-            
-         
+               
         foreach($cfg['cols'] as $c=>$col_cfg) {
             if (is_string($col_cfg)) {
                 $cfg['cols'][$c] = array(
@@ -171,7 +169,8 @@ class Pman_Core_SimpleExcel extends Pman
            //     DB_DataObject::debugLevel(1);
         foreach($data as $r=>$clo) {
             
-            $hasRender = $this->addLine($cfg['workbook'], $clo);
+            $hasRenderRow = $this->addLine($cfg['workbook'], $clo);
+            $hasRender = ($hasRender  || $hasRenderRow) ? true : false;
              
         }
         /// call user render on any that are defined..
@@ -184,6 +183,7 @@ class Pman_Core_SimpleExcel extends Pman
                         continue;
                     }
                     if (isset($col_cfg['renderer'])) {
+                        // not sure if row is correct here...!!!?
                         call_user_func($col_cfg['renderer'], $cl[$col_cfg['dataIndex']], $worksheet, $r+1, $c, $cl);
                         
                     }
@@ -221,11 +221,13 @@ class Pman_Core_SimpleExcel extends Pman
     
     function addLine($worksheet_name, $clo)
     {
-        $cfg        = $this->workSheetCfg[$worksheet_name];
+        $cfg        = $this->worksheet_cfg[$worksheet_name];
         $start_row  = $this->start_row;
         $formats    = $this->formats;
         $worksheet  = $this->worksheet;
         
+        
+        
         $hasRender   = false;
         $r = 0;
        
@@ -267,22 +269,23 @@ class Pman_Core_SimpleExcel extends Pman
             
             $v = @iconv('UTF-8', 'UTF-8//IGNORE', $v);
             
-            $format = isset($col_cfg['format']) ? $formats[$col_cfg['format']] : false;
             
+            $format = isset($col_cfg['format'])  && isset($formats[$col_cfg['format']] )   ? $formats[$col_cfg['format']] : false;
+          //  print_R(array($start_row+$r, $c, $v, $format));exit;
             $worksheet->write($start_row+$r, $c, $v, $format);
         }
         $this->start_row++;
         
         return $hasRender;
     }
-    
-    
-    
+     
     
     function send($fn)
     {
-        if (empty($cfg['leave_open'])) {
-                $this->
+        if (!empty($this->workbook)) {
+            $this->workbook->close();
+            $this->workbook = false;
+        }
         
         require_once 'File/Convert.php';
         $fc=  new File_Convert($this->outfile2, "application/vnd.ms-excel");