DataObjects/core.sql
[Pman.Core] / SimpleExcel.php
index 61cd053..a0128fe 100644 (file)
@@ -18,6 +18,7 @@
             [ "a", "b" ]
             [],
             [ "A", "B" ]
+            [ "a",  ["test", "left"]  ] << sub array [text, formatname]
         ],
  *     cols :  array(
             array(
@@ -48,9 +49,8 @@ class Pman_Core_SimpleExcel extends Pman
     {
      //  print_r($cfg);
         require_once 'Spreadsheet/Excel/Writer.php';
-        $pman = new Pman();
         // Creating a workbook
-        $outfile2 = $pman->tempName('xls');
+        $outfile2 = $this->tempName('xls');
        // var_dump($outfile2);
         $workbook = new Spreadsheet_Excel_Writer($outfile2);
         //$workbook = new Spreadsheet_Excel_Writer();
@@ -87,6 +87,15 @@ class Pman_Core_SimpleExcel extends Pman
          
     }
     
+    
+    static function date($str)
+    {
+        
+        return (strtotime($str . ' UTC') +  (86400 *  25569)) / 86400;
+        
+    }
+    
+    
     function buildpage($workbook,  $formats , $data,$cfg)
     {
         //echo '<PRE>';        print_R($cfg);
@@ -106,6 +115,12 @@ class Pman_Core_SimpleExcel extends Pman
         if (!empty($cfg['head'])) {
             foreach($cfg['head'] as $row) { 
                 foreach($row as $c => $col) {
+                    if (is_array($col)) {
+                        $format = isset($formats[$col[1]] ) ? $formats[$col[1]] : false;
+                        $worksheet->write($start_row, $c, $col[0], $format);
+                        continue;
+                    }
+                    
                     $worksheet->write($start_row, $c, $col);
                     
                 }
@@ -200,6 +215,11 @@ class Pman_Core_SimpleExcel extends Pman
             foreach($cfg['foot'] as $row) { 
                 foreach($row as $c => $col) {
                     // if it's an array? - formated ???
+                    if (is_array($col)) {
+                        $format = isset($formats[$col[1]] ) ? $formats[$col[1]] : false;
+                        $worksheet->write($start_row, $c, $col[0], $format);
+                        continue;
+                    }
                     $worksheet->write($start_row, $c, $col);
                     
                 }
@@ -215,15 +235,11 @@ class Pman_Core_SimpleExcel extends Pman
         
     }
     
-    
-    
     function send($fn)
     {
         require_once 'File/Convert.php';
         $fc=  new File_Convert($this->outfile2, "application/vnd.ms-excel");
         $fn = $fc->convert("application/vnd.ms-excel"); 
-        print_r($fn);
-        exit;
         $fc->serve('attachment',$fn); // can fix IE Mess
     }