DataObjects/Core_notify.php
[Pman.Core] / SimpleExcel.php
index bf71e36..5c557b9 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
@@ -40,6 +41,7 @@
  
  
  
+require_once 'Pman.php';
 
 
 class Pman_Core_SimpleExcel extends Pman
@@ -76,12 +78,12 @@ class Pman_Core_SimpleExcel extends Pman
              
         }
          
-
-        if (!isset($cfg['workbooks'])) {
-            $this->buildpage(   $formats , $data,$cfg);
+         
+        if (!empty($cfg['workbook'])) {
+            $this->buildPage(   $formats , $data,$cfg);
         } elseif (!empty($cfg['workbooks'])) {
             foreach($cfg['workbooks'] as $i =>$wcfg) {
-                $this->buildpage(   $formats , $data[$i],$wcfg);
+                $this->buildPage(   $formats , $data[$i],$wcfg);
             }
             
         }
@@ -109,7 +111,7 @@ class Pman_Core_SimpleExcel extends Pman
     }
     
     
-    function buildpage( $formats , $data, $cfg)
+    function buildPage( $formats , $data, $cfg)
     {
         $workbook = $this->workbook;
         //echo '<PRE>';        print_R($cfg);
@@ -120,7 +122,8 @@ class Pman_Core_SimpleExcel extends Pman
         $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());
@@ -157,7 +160,6 @@ class Pman_Core_SimpleExcel extends Pman
                     'header' => $col_cfg,
                     'dataIndex' => $col_cfg,
                     'width' => 50,
-                    
                 );
             }
         }
@@ -167,7 +169,6 @@ 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;
@@ -272,11 +273,13 @@ 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 {
           
@@ -289,7 +292,7 @@ class Pman_Core_SimpleExcel extends Pman
     }
      
     
-    function send($fn)
+    function send($fname)
     {
         if (!empty($this->workbook)) {
             $this->workbook->close();
@@ -299,7 +302,7 @@ class Pman_Core_SimpleExcel extends Pman
         require_once 'File/Convert.php';
         $fc=  new File_Convert($this->outfile2, "application/vnd.ms-excel");
         $fn = $fc->convert("application/vnd.ms-excel"); 
-        $fc->serve('attachment',$fn); // can fix IE Mess
+        $fc->serve('attachment',$fname); // can fix IE Mess
     }