[ "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(
array(
'header'=> "Thumbnail",
'dataIndex'=> 'id',
+ * 'dataFormat' => 'string' // to force a string..
'width'=> 75,
'renderer' => array($this, 'getThumb'),
* 'color' => 'yellow', // set color for the cell which is a header element
$cfg['formats'] = isset($cfg['formats']) ? $cfg['formats'] : array();
foreach($cfg['formats'] as $f=>$fcfg) {
- $formats[$f] = & $workbook->addFormat();
- foreach($fcfg as $k=>$v) {
- $formats[$f]->{'set' . $k}($v);
+
+ $this->formats[$f] = & $workbook->addFormat();
+ foreach((array)$fcfg as $k=>$v) {
+ $this->formats[$f]->{'set' . $k}($v);
}
-
+
}
if (!empty($cfg['workbook'])) {
- $this->buildPage( $formats , $data,$cfg);
+ $this->buildPage( array(), $data,$cfg);
} elseif (!empty($cfg['workbooks'])) {
foreach($cfg['workbooks'] as $i =>$wcfg) {
- $this->buildPage( $formats , $data[$i],$wcfg);
+ $this->buildPage( array() , $data[$i],$wcfg);
}
}
// copy the config and alias so that book can be written to..
$this->worksheet_cfg[$cfg['workbook']] = &$cfg;
- $this->formats = $formats;
+
+ //$this->formats = (array)$formats;
+
+ foreach($formats as $k=>$fcfg) {
+ if (!isset($this->formats[$f])) {
+ $this->formats[$f] = & $workbook->addFormat();
+ }
+ if (is_a($fcfg,'Spreadsheet_Excel_Writer_Format')) {
+ continue; // skip!?!?
+ }
+ // not an object..
+ foreach((array)$fcfg as $k=>$v) {
+ $this->formats[$f]->{'set' . $k}($v);
+ }
+ }
+
+ if (isset($cfg['formats'])) {
+
+ foreach($cfg['formats'] as $f=>$fcfg) {
+ if (!isset($this->formats[$f])) {
+ $this->formats[$f] = & $workbook->addFormat();
+ }
+ foreach((array)$fcfg as $k=>$v) {
+ $this->formats[$f]->{'set' . $k}($v);
+ }
+
+ }
+
+
+ }
+
+
+
//var_dump($cfg['workbook']);
$worksheet = $workbook->addWorksheet($cfg['workbook']);
//print_R($worksheet);
$worksheet->setInputEncoding('UTF-8');
+ if(!empty($cfg['merged_ranges'])){ // merge cell
+ $worksheet->_merged_ranges = $cfg['merged_ranges'];
+ }
+
$this->worksheet = $worksheet;
$start_row = 0;
foreach($cfg['head'] as $row) {
foreach($row as $c => $col) {
if (is_array($col)) {
- $format = isset($formats[$col[1]] ) ? $formats[$col[1]] : false;
+ $format = isset($this->formats[$col[1]] ) ?$this->formats[$col[1]] : false;
$worksheet->write($start_row, $c, $col[0], $format);
continue;
}
foreach($cfg['cols'] as $c=>$col_cfg) {
- $format = isset($col_cfg['color']) ? $formats[$col_cfg['color']] : false;
- $worksheet->write($start_row, $c, $col_cfg['header'],$format);
+
+ $format = isset($col_cfg['color']) && isset($this->formats[$col_cfg['color']]) ? $this->formats[$col_cfg['color']] : false;
+ $worksheet->write($start_row, $c, @$col_cfg['header'],$format);
$worksheet->setColumn ( $c, $c, $col_cfg['width'] / 5);
}
$start_row++;
$hasRender = false;
+ if (empty($data)) {
+ return;
+ }
+
foreach($data as $r=>$clo) {
$hasRenderRow = $this->addLine($cfg['workbook'], $clo);
foreach($row as $c => $col) {
// if it's an array? - formated ???
if (is_array($col)) {
- $format = isset($formats[$col[1]] ) ? $formats[$col[1]] : false;
+ $format = isset($this->formats[$col[1]] ) ? $this->formats[$col[1]] : false;
$worksheet->write($start_row, $c, $col[0], $format);
continue;
}
// add a spacer..
$start_row++;
}
-
-
-
+
}
function addLine($worksheet_name, $clo)
{
$cfg = $this->worksheet_cfg[$worksheet_name];
$start_row = $this->start_row;
- $formats = $this->formats;
+ $formats = (array)$this->formats;
$worksheet = $this->worksheet;
$hasRender = false;
foreach($cfg['cols'] as $c=>$col_cfg) {
- if(isset($cl[$col_cfg['dataIndex']])){
+ if(isset($col_cfg['dataIndex']) && isset($cl[$col_cfg['dataIndex']])){
$v = $cl[$col_cfg['dataIndex']];
}else{
if(isset($col_cfg['fillBlank'])){
$v = @iconv('UTF-8', 'UTF-8//IGNORE', $v);
+ $dataFormat = empty($col_cfg['dataFormat']) ? '' : $col_cfg['dataFormat'];
+ ;
+
$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 ( (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);
} else {