X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=SimpleExcel.php;h=6c36750ea2e301acfaab413f0d3bc9497c7b89a6;hp=484808cb05a78d748fa630a59e7f5c0fc35dec88;hb=586e4eb470252d837ba18b67e4c3c1702131fd1d;hpb=309360dac02905354483371267f86fc0598c602d diff --git a/SimpleExcel.php b/SimpleExcel.php index 484808cb..6c36750e 100644 --- a/SimpleExcel.php +++ b/SimpleExcel.php @@ -74,8 +74,9 @@ class Pman_Core_SimpleExcel extends Pman var $formats = array(); var $workbook = false; var $worksheet= false; - - function Pman_Core_SimpleExcel($data,$cfg) + var $postRender = array(); + + function __construct($data,$cfg) { // print_r($cfg);exit; require_once 'Spreadsheet/Excel/Writer.php'; @@ -92,11 +93,14 @@ class Pman_Core_SimpleExcel extends Pman $cfg['formats'] = isset($cfg['formats']) ? $cfg['formats'] : array(); + $this->formats['_default_date_format_'] = $workbook->addFormat();; + $this->formats['_default_date_format_']->setNumFormat('YYYY-MM-DD'); + foreach($cfg['formats'] as $f=>$fcfg) { $this->formats[$f] = & $workbook->addFormat(); foreach((array)$fcfg as $k=>$v) { - $this->formats[$f]->{'set' . $k}($v); + $this->formats[$f]->{'set' . $k}($v); } } @@ -239,6 +243,7 @@ class Pman_Core_SimpleExcel extends Pman if (empty($data)) { return; } + foreach($cfg['cols'] as $c => $col_cfg) { if (isset($col_cfg['renderer'])) { $hasRender = true; @@ -275,8 +280,7 @@ class Pman_Core_SimpleExcel extends Pman continue; } if (!empty($col_cfg['renderer'])) { - - if (is_a($col_cfg['renderer'], 'Closure')) { + 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...!!!? @@ -366,6 +370,18 @@ class Pman_Core_SimpleExcel extends Pman } if (isset($col_cfg['renderer'])) { $hasRender = true; + + $v = isset($cl[$col_cfg['dataIndex']]) ? $cl[$col_cfg['dataIndex']] : ''; + if (empty($cl[$col_cfg['dataIndex']])) { + continue; + } + $this->postRender[] = array( + $col_cfg['renderer'], $cl[$col_cfg['dataIndex']], $worksheet, $start_row+$r+1, $c, $cl + ); + + + + continue; } @@ -380,7 +396,14 @@ class Pman_Core_SimpleExcel extends Pman if (preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $v)) { $dataFormat = 'date'; - $format = empty($format) ? 'YYYY-MM-DD' : $format; + $format = empty($format) ? $this->formats['_default_date_format_']: $format; + $ut_to_ed_diff = 86400 * 25569; + $gmt = strtotime('1970-01-01'); + + $v = (strtotime($v) + $ut_to_ed_diff - $gmt) / 86400; + // need to +8hrs to get real time.. + + } if ( (is_numeric($v) && strlen($v) > 1 && substr($v,0,1) == '0' && substr($v,1,1) != '.' ) @@ -406,6 +429,20 @@ class Pman_Core_SimpleExcel extends Pman function send($fname) { + + if (!empty($this->postRender)) { + foreach($this->postRender as $ar) { + if (is_a($ar[0], 'Closure')) { + $ar[0]($ar[1], $ar[2], $ar[3], $ar[4], $ar[5]); + } else { + // not sure if row is correct here...!!!? + call_user_func($ar[0],$ar[1], $ar[2], $ar[3], $ar[4], $ar[5]); + } + } + + } + + if (!empty($this->workbook)) { $this->workbook->close(); $this->workbook = false;