DataObjects/Core_watch.php
[Pman.Core] / SimpleExcel.php
index 2d5730e..0aef6e1 100644 (file)
@@ -24,6 +24,7 @@
             array(
                 'header'=> "Thumbnail",
                 'dataIndex'=> 'id',
+ *              'dataFormat' => 'string' // to force a string..
                 'width'=>  75,
                 'renderer' => array($this, 'getThumb'),
  *              'color' => 'yellow', // set color for the cell which is a header element
@@ -70,8 +71,9 @@ class Pman_Core_SimpleExcel extends Pman
         $cfg['formats'] = isset($cfg['formats']) ? $cfg['formats'] : array();
         
         foreach($cfg['formats'] as $f=>$fcfg) {
+            
             $formats[$f] = & $workbook->addFormat();
-            foreach($fcfg as $k=>$v) {
+            foreach((array)$fcfg as $k=>$v) {
                 $formats[$f]->{'set' . $k}($v);
             }
              
@@ -120,7 +122,25 @@ 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;
+        
+        //$this->formats = (array)$formats;
+        
+        if (isset($cfg['formats']) && empty($formats)) {
+            
+            foreach($cfg['formats'] as $f=>$fcfg) {
+                
+                $formats[$f] = & $workbook->addFormat();
+                foreach((array)$fcfg as $k=>$v) {
+                    $formats[$f]->{'set' . $k}($v);
+                }
+                 
+            }
+            
+            $this->formats = $formats;
+        }
+        
+        
+        
         //var_dump($cfg['workbook']);
 
         $worksheet =  $workbook->addWorksheet($cfg['workbook']);
@@ -175,6 +195,10 @@ class Pman_Core_SimpleExcel extends Pman
         
         $hasRender  = false;
          
+        if (empty($data)) {
+            return;
+        }
+        
         
         foreach($data as $r=>$clo) {
             $hasRenderRow = $this->addLine($cfg['workbook'], $clo);
@@ -228,7 +252,7 @@ class Pman_Core_SimpleExcel extends Pman
     {
         $cfg        = $this->worksheet_cfg[$worksheet_name];
         $start_row  = $this->start_row;
-        $formats    = $this->formats;
+        $formats    = (array)$this->formats;
         $worksheet  = $this->worksheet;
         
         $hasRender   = false;
@@ -272,11 +296,16 @@ class Pman_Core_SimpleExcel extends Pman
             
             $v = @iconv('UTF-8', 'UTF-8//IGNORE', $v);
             
+            $dataFormat = empty($col_cfg['dataFormat']) ? '' : $col_cfg['dataFormat'];
+             ;
+            
             
             $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;
           // handle 0 prefixes..
-            if (is_numeric($v) &&  strlen($v) > 1 && substr($v,0,1) == '0' && substr($v,1,1) != '.' ) {
+            if ( (is_numeric($v) &&  strlen($v) > 1 && substr($v,0,1) == '0' && substr($v,1,1) != '.') 
+                    || 
+                    $dataFormat == 'string' ) {
                 $worksheet->writeString($start_row+$r, $c, $v, $format);
             } else {