* 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);
*
*
- * cfg:
- * formats
- * name : [ Align : left, .... ]
- *
- * workbook : nameof
*
- * head : [
- [ "a", "b" ]
- [],
- [ "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(
+
+new Pman_Core_SimpleExcel($data_array, array(
+ 'formats' => array(
+ 'format_name' => array( 'Align' => 'left' ), // etc...
+ ),
+ 'workbook' => 'name_of_workbook'm
+
+ 'head' => array(
+ array ( 'this', 'is', 'the' , 'first', 'row'),
+ array ( 'this', 'is', 'the' , 'seconde', 'row'), // ... etc.
+ array ( array( 'string', 'format_name') , 'another cell') , // with formating..
+ ),
+
+ '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",
'dataIndex'=> 'id',
- * 'dataFormat' => 'string' // to force a string..
+ 'dataFormat' => 'string' // to force a string..
'width'=> 75,
'renderer' => array($this, 'getThumb'),
- 'txtrenderer' => array($this, 'cleanValue'), // for
- * '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
+ '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 this is set then it will add a tab foreach one.
- workbooks = array(
- workbook ->
-
- 'leave_open' => false
-
+ //..... and ther rows...
+ ),
+
+ // if this is set then it will add a tab foreach one.
+ 'workbooks' = array(
+ workbook => '....' // ???
+ ),
+ 'leave_open' => false, // if you call addrows?? later..
- // callbacks: renderer
+));
+
+ callbacks: renderer
function($value, $worksheet, $row, $col, $row_data)
continue;
}
if (isset($col_cfg['renderer'])) {
+
+ if (is_a($col_cfg['renderer'], 'Closure')) {
+ $col_cfg['renderer']->call($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));
$worksheet->setRow($start_row +$r, $cfg['row_height']);
}
- $height = 1;
+ $line_height = (isset($cfg['line_height'])) ? $cfg['line_height'] : 12;
+ $height = 0;
foreach($cfg['cols'] as $c => $col_cfg) {
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']->call($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;
}
$worksheet->write($start_row+$r, $c, $v, $format);
}
-// if(isset($col_cfg['autoHeight'])){
+ if(isset($col_cfg['autoHeight'])){
$vv = explode("\n", $v);
-
- $height = MAX(count($vv), $height);;
- $worksheet->setRow($start_row+$r, null);
-// }
+ $height = MAX(count($vv) * $line_height, $height);;
+ $worksheet->setRow($start_row+$r, $height);
+ }
}
$this->start_row++;
}
require_once 'File/Convert.php';
+ //var_Dump($this->outfile2);
$fc= new File_Convert($this->outfile2, "application/vnd.ms-excel");
- $fn = $fc->convert("application/vnd.ms-excel");
+ $fn = $fc->convert("application/vnd.ms-excel");
+ //print_r($fc);
$fc->serve('attachment',$fname); // can fix IE Mess
}
-}
\ No newline at end of file
+}