DataObjects/Core_notify.php
[Pman.Core] / SimpleExcel.php
index 709bfde..0869d05 100644 (file)
@@ -62,7 +62,8 @@ class Pman_Core_SimpleExcel extends Pman
         //$workbook = new Spreadsheet_Excel_Writer();
         $workbook->setVersion(8);
         // sending HTTP headers
-        
+        $this->workbook = $workbook;
+            
         $formats = array();
        
         $cfg['formats'] = isset($cfg['formats']) ? $cfg['formats'] : array();
@@ -75,18 +76,19 @@ class Pman_Core_SimpleExcel extends Pman
              
         }
          
-
-        if (empty($cfg['workbooks'])) {
-            $this->buildpage( $workbook,  $formats , $data,$cfg);
-        } else {
+         
+        if (!empty($cfg['workbook'])) {
+            $this->buildPage(   $formats , $data,$cfg);
+        } elseif (!empty($cfg['workbooks'])) {
             foreach($cfg['workbooks'] as $i =>$wcfg) {
-                $this->buildpage( $workbook,  $formats , $data[$i],$wcfg);
+                $this->buildPage(   $formats , $data[$i],$wcfg);
             }
             
         }
+        // if workbooks == false - > the user can call buildpage..
+        
         
         if (!empty($cfg['leave_open'])) {
-            $this->workbook = $workbook;
             $this->outfile2 = $outfile2;
             return;
         }
@@ -97,6 +99,8 @@ class Pman_Core_SimpleExcel extends Pman
     }
     
     
+    
+    
     static function date($str)
     {
         
@@ -105,8 +109,9 @@ class Pman_Core_SimpleExcel extends Pman
     }
     
     
-    function buildpage($workbook,  $formats , $data,$cfg)
+    function buildPage( $formats , $data, $cfg)
     {
+        $workbook = $this->workbook;
         //echo '<PRE>';        print_R($cfg);
       //  print_r($cfg);exit;
         // Creating a worksheet
@@ -114,6 +119,9 @@ class Pman_Core_SimpleExcel extends Pman
         // copy the config and alias so that book can be written to..
         $this->worksheet_cfg[$cfg['workbook']] = &$cfg;
         
+        $this->formats = $formats;
+        //var_dump($cfg['workbook']);
+
         $worksheet =  $workbook->addWorksheet($cfg['workbook']);
         if (is_a($worksheet, 'PEAR_Error')) {
             die($worksheet->toString());
@@ -140,7 +148,7 @@ class Pman_Core_SimpleExcel extends Pman
                 $start_row++;
             }
             // add a spacer..
-            $start_row++;
+            if(!isset($cfg['nonspacer'])){ $start_row++; }
         }
             
                
@@ -150,7 +158,6 @@ class Pman_Core_SimpleExcel extends Pman
                     'header' => $col_cfg,
                     'dataIndex' => $col_cfg,
                     'width' => 50,
-                    
                 );
             }
         }
@@ -160,21 +167,19 @@ class Pman_Core_SimpleExcel extends Pman
             $format = isset($col_cfg['color']) ? $formats[$col_cfg['color']] : false;
             $worksheet->write($start_row, $c, $col_cfg['header'],$format);
             $worksheet->setColumn ( $c, $c, $col_cfg['width'] / 5);
-             
         }
         $start_row++;
         $this->start_row = &$start_row;
         
         
         $hasRender  = false;
-           //     DB_DataObject::debugLevel(1);
+         
+        
         foreach($data as $r=>$clo) {
-            echo '<PRE>';print_r($clo);
             $hasRenderRow = $this->addLine($cfg['workbook'], $clo);
             $hasRender = ($hasRender  || $hasRenderRow) ? true : false;
              
         }
-        exit;
         /// call user render on any that are defined..
         if ($hasRender) {
             foreach($data as $r=>$cl) {
@@ -214,9 +219,6 @@ class Pman_Core_SimpleExcel extends Pman
             $start_row++;
         }
             
-        $this->formats = $formats;
-        
-        
         
         
     }
@@ -251,7 +253,7 @@ class Pman_Core_SimpleExcel extends Pman
                 continue;
             }
             
-            if (empty($cl[$col_cfg['dataIndex']])) {
+            if (!isset($cl[$col_cfg['dataIndex']])) {
                 continue;
             }
             if (isset($col_cfg['txtrenderer'])) {
@@ -272,7 +274,13 @@ class Pman_Core_SimpleExcel extends Pman
             
             $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);
+          // handle 0 prefixes..
+            if (is_numeric($v) &&  strlen($v) > 1 && substr($v,0,1) == '0' && substr($v,1,1) != '.' ) {
+                $worksheet->writeString($start_row+$r, $c, $v, $format);
+            } else {
+          
+                $worksheet->write($start_row+$r, $c, $v, $format);
+            }
         }
         $this->start_row++;