/**
* class to generate excel file from rows of data, and a configuration.
+ *
+ * usage :
+ * $x = new Pman_Core_SimpleExcel(array())
+ * $x->send($fn);
+ *
*
* cfg:
* formats
* name : [ Align : left, .... ]
- * workbook : nameof
- * close : array(
+ *
+ * workbook : nameof
+ *
+ * head : [
+ [ "a", "b" ]
+ [],
+ [ "A", "B" ]
+ ],
+ * cols : array(
array(
'header'=> "Thumbnail",
'dataIndex'=> 'id',
'width'=> 75,
'renderer' => array($this, 'getThumb')
),
+
+
+
+
*/
$worksheet =& $workbook->addWorksheet($cfg['workbook']);
$worksheet->setInputEncoding('UTF-8');
+
+
+ $start_row = 0;
+
+ if (!empty($cfg['head'])) {
+ foreach($cfg['head'] as $row) {
+ foreach($row as $c => $col) {
+ $worksheet->write($start_row, $c, $col);
+
+ }
+ $start_row++;
+ }
+ // add a spacer..
+ $start_row++;
+ }
+
+
+
+
+
+
+
+
foreach($cfg['cols'] as $c=>$col_cfg) {
- $worksheet->write(0, $c, $col_cfg['header']);
+ $worksheet->write($start_row, $c, $col_cfg['header']);
$worksheet->setColumn ( $c, $c, $col_cfg['width'] / 5);
}
+ $start_row++;
// DB_DataObject::debugLevel(1);
foreach($data as $r=>$cl) {
if (isset($cfg['row_height'])) {
- $worksheet->setRow($r+1, $cfg['row_height']);
+ $worksheet->setRow($start_row +$r, $cfg['row_height']);
}
foreach($cfg['cols'] as $c=>$col_cfg) {
$format = isset($col_cfg['format']) ? $formats[$col_cfg['format']] : false;
// echo "<PRE>WRITE: ". htmlspecialchars(print_r(array($r+1, $c,$v), true));
- $worksheet->write($r+1, $c, $v, $format);
+ $worksheet->write($start_row+$r, $c, $v, $format);
}
}