DataObjects/Core_watch.php
[Pman.Core] / SimpleExcel.php
index 9ca248a..2805699 100644 (file)
             [ "A", "B" ]
             [ "a",  ["test", "left"]  ] << sub array [text, formatname]
         ],
+ *     merged_ranges : array(
+ *                          array($first_row, $first_col, $last_row, $last_col),
+ * *                        array($first_row, $first_col, $last_row, $last_col),
+ *                      ),
  *     cols :  array(
             array(
                 'header'=> "Thumbnail",
@@ -72,19 +76,19 @@ class Pman_Core_SimpleExcel extends Pman
         
         foreach($cfg['formats'] as $f=>$fcfg) {
             
-            $formats[$f] = & $workbook->addFormat();
+            $this->formats[$f] = & $workbook->addFormat();
             foreach((array)$fcfg as $k=>$v) {
-                $formats[$f]->{'set' . $k}($v);
+                 $this->formats[$f]->{'set' . $k}($v);
             }
-             
+            
         }
          
          
         if (!empty($cfg['workbook'])) {
-            $this->buildPage(   $formats , $data,$cfg);
+            $this->buildPage(  array(), $data,$cfg);
         } elseif (!empty($cfg['workbooks'])) {
             foreach($cfg['workbooks'] as $i =>$wcfg) {
-                $this->buildPage(   $formats , $data[$i],$wcfg);
+                $this->buildPage(   array() , $data[$i],$wcfg);
             }
             
         }
@@ -125,18 +129,32 @@ class Pman_Core_SimpleExcel extends Pman
         
         //$this->formats = (array)$formats;
         
-        if (isset($cfg['formats']) && empty($formats)) {
+        foreach($formats as $k=>$fcfg) {
+            if (!isset($this->formats[$f])) {
+                $this->formats[$f] = & $workbook->addFormat();
+            }
+            if (is_a($fcfg,'Spreadsheet_Excel_Writer_Format')) {
+                continue; // skip!?!?
+            }
+            // not an object..
+            foreach((array)$fcfg as $k=>$v) {
+                $this->formats[$f]->{'set' . $k}($v);
+            }
+        }
+        
+        if (isset($cfg['formats'])) {
             
             foreach($cfg['formats'] as $f=>$fcfg) {
-                
-                $formats[$f] = & $workbook->addFormat();
+                if (!isset($this->formats[$f])) {
+                    $this->formats[$f] = & $workbook->addFormat();
+                }
                 foreach((array)$fcfg as $k=>$v) {
-                    $formats[$f]->{'set' . $k}($v);
+                    $this->formats[$f]->{'set' . $k}($v);
                 }
                  
             }
             
-            $this->formats = $formats;
+             
         }
         
         
@@ -150,6 +168,10 @@ class Pman_Core_SimpleExcel extends Pman
         //print_R($worksheet);
         $worksheet->setInputEncoding('UTF-8'); 
          
+        if(!empty($cfg['merged_ranges'])){ // merge cell
+            $worksheet->_merged_ranges = $cfg['merged_ranges'];
+        }
+        
         $this->worksheet = $worksheet;
          
         $start_row = 0;
@@ -158,7 +180,7 @@ class Pman_Core_SimpleExcel extends Pman
             foreach($cfg['head'] as $row) { 
                 foreach($row as $c => $col) {
                     if (is_array($col)) {
-                        $format = isset($formats[$col[1]] ) ? $formats[$col[1]] : false;
+                        $format = isset($this->formats[$col[1]] ) ?$this->formats[$col[1]] : false;
                         $worksheet->write($start_row, $c, $col[0], $format);
                         continue;
                     }
@@ -185,8 +207,9 @@ class Pman_Core_SimpleExcel extends Pman
          
          
         foreach($cfg['cols'] as $c=>$col_cfg) {
-            $format = isset($col_cfg['color']) ? $formats[$col_cfg['color']] : false;
-            $worksheet->write($start_row, $c, $col_cfg['header'],$format);
+            
+            $format = isset($col_cfg['color']) && isset($this->formats[$col_cfg['color']]) ? $this->formats[$col_cfg['color']] : false;
+            $worksheet->write($start_row, $c, @$col_cfg['header'],$format);
             $worksheet->setColumn ( $c, $c, $col_cfg['width'] / 5);
         }
         $start_row++;
@@ -231,7 +254,7 @@ class Pman_Core_SimpleExcel extends Pman
                 foreach($row as $c => $col) {
                     // if it's an array? - formated ???
                     if (is_array($col)) {
-                        $format = isset($formats[$col[1]] ) ? $formats[$col[1]] : false;
+                        $format = isset($this->formats[$col[1]] ) ? $this->formats[$col[1]] : false;
                         $worksheet->write($start_row, $c, $col[0], $format);
                         continue;
                     }
@@ -243,13 +266,7 @@ class Pman_Core_SimpleExcel extends Pman
             // add a spacer..
             $start_row++;
         }
-        
-        // merge cell
-        print_r($cfg);exit;
-        if(!empty($cfg['merged_ranges'])){
-            $this->_merged_ranges = $cfg['merged_ranges'];
-        }
-        
+         
     }
     
     function addLine($worksheet_name, $clo)
@@ -273,7 +290,7 @@ class Pman_Core_SimpleExcel extends Pman
         
         foreach($cfg['cols']  as $c=>$col_cfg) {
             
-            if(isset($cl[$col_cfg['dataIndex']])){
+            if(isset($col_cfg['dataIndex']) && isset($cl[$col_cfg['dataIndex']])){
                 $v = $cl[$col_cfg['dataIndex']];
             }else{
                 if(isset($col_cfg['fillBlank'])){