X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=SimpleExcel.php;h=6515710c392420ebbe241cb58dc0134621642591;hp=9cf26afe5d86b8d0a219501dd6df00e2c7a8d4d1;hb=refs%2Fheads%2Fwip_edward_T5851_download_old_offer_sheet;hpb=24111113a9f6c4711831214c14b8e17c9a53007a diff --git a/SimpleExcel.php b/SimpleExcel.php index 9cf26afe..6515710c 100644 --- a/SimpleExcel.php +++ b/SimpleExcel.php @@ -75,7 +75,8 @@ class Pman_Core_SimpleExcel extends Pman var $workbook = false; var $worksheet= false; - function Pman_Core_SimpleExcel($data,$cfg) + + 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); } } @@ -377,7 +381,20 @@ class Pman_Core_SimpleExcel extends Pman $format = isset($col_cfg['format']) && isset($formats[$col_cfg['format']] ) ? $formats[$col_cfg['format']] : false; // print_R(array($start_row+$r, $c, $v, $format));exit; // handle 0 prefixes.. - if ( (is_numeric($v) && strlen($v) > 1 && substr($v,0,1) == '0' && substr($v,1,1) != '.') + + if (preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $v)) { + $dataFormat = 'date'; + $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) != '.' ) || $dataFormat == 'string' ) { $worksheet->writeString($start_row+$r, $c, $v, $format);