* class to generate excel file from rows of data, and a configuration.
*
* usage :
- * $x = new Pman_Core_SimpleExcel(array())
+ * $x = new Pman_Core_SimpleExcel($data_array, array())
* $x->send($fn);
*
*
'dataFormat' => 'string' // to force a string..
'width'=> 75,
'renderer' => array($this, 'getThumb'),
- 'txtrenderer' => array($this, 'cleanValue'), // for
+ 'txtrenderer' => function($value, $worksheet, $row, $col, $row_data) {
+ return $value
+ }, // for text content...
'color' => 'yellow', // set color for the cell which is a header element
'fillBlank' => 'gray', // set the color for the cell which is a blank area
),
if (empty($cl[$col_cfg['dataIndex']])) {
continue;
}
- if (isset($col_cfg['renderer'])) {
+ if (!empty($col_cfg['renderer'])) {
+
+ if (is_a($col_cfg['renderer'], 'Closure')) {
+ $col_cfg['renderer']($cl[$col_cfg['dataIndex']], $worksheet, $r+1, $c, $cl);
+ } else {
// not sure if row is correct here...!!!?
- call_user_func($col_cfg['renderer'], $cl[$col_cfg['dataIndex']], $worksheet, $r+1, $c, $cl);
+ call_user_func($col_cfg['renderer'], $cl[$col_cfg['dataIndex']], $worksheet, $r+1, $c, $cl);
+ }
}
// echo "<PRE>WRITE: ". htmlspecialchars(print_r(array($r+1, $c, $cl[$col_cfg['dataIndex']]), true));
continue;
}
if (isset($col_cfg['txtrenderer'])) {
- $v = call_user_func($col_cfg['txtrenderer'],
- $cl[$col_cfg['dataIndex']], $worksheet, $r+1, $c, $clo);
+
+ if (is_a($col_cfg['txtrenderer'], 'Closure')) {
+
+ $v = $col_cfg['txtrenderer']($cl[$col_cfg['dataIndex']], $worksheet, $r+1, $c, $clo);
+ } else {
+ $v = call_user_func($col_cfg['txtrenderer'],
+ $cl[$col_cfg['dataIndex']], $worksheet, $r+1, $c, $clo);
+ }
if ($v === false) {
continue;
}