cvs: pear /Structures_DataGrid/DataGrid/Renderer XLS.php

From: Date: Fri, 28 Oct 2005 13:58:35 +0000
Subject: cvs: pear /Structures_DataGrid/DataGrid/Renderer XLS.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-35930@lists.php.net to get a copy of this message
olivierg Fri Oct 28 09:58:35 2005 EDT Modified files: /pear/Structures_DataGrid/DataGrid/Renderer XLS.php Log: Added support for external/custom Excel Writer and Format objects (Fix requests: #5806 and #5808) http://cvs.php.net/diff.php/pear/Structures_DataGrid/DataGrid/Renderer/XLS.php?r1=1.23&r2=1.24&ty=u Index: pear/Structures_DataGrid/DataGrid/Renderer/XLS.php diff -u pear/Structures_DataGrid/DataGrid/Renderer/XLS.php:1.23 pear/Structures_DataGrid/DataGrid/Renderer/XLS.php:1.24 --- pear/Structures_DataGrid/DataGrid/Renderer/XLS.php:1.23 Mon Oct 10 20:40:01 2005 +++ pear/Structures_DataGrid/DataGrid/Renderer/XLS.php Fri Oct 28 09:58:33 2005 @@ -16,14 +16,14 @@ // | Author: Andrew Nagy <asnagy@webitecture.org> | // +----------------------------------------------------------------------+ // -// $Id: XLS.php,v 1.23 2005/10/11 00:40:01 olivierg Exp $ +// $Id: XLS.php,v 1.24 2005/10/28 13:58:33 olivierg Exp $ require_once 'Spreadsheet/Excel/Writer.php'; /** * Structures_DataGrid_Renderer_XLS Class * - * @version $Revision: 1.23 $ + * @version $Revision: 1.24 $ * @author Andrew S. Nagy <asnagy@webitecture.org> * @access public * @package Structures_DataGrid @@ -74,6 +74,27 @@ */ var $_rendered = false; + + /** + * Header format + * + * The 0 default value means "no format" as specified by the + * Spreadsheet_Excel_Writer_Worksheet::write() method prototype + * + * @var mixed Spreadsheet_Excel_Writer_Format object or 0 + */ + var $_headerFormat = 0; + + /** + * Body format + * + * The 0 default value means "no format" as specified by the + * Spreadsheet_Excel_Writer_Worksheet::write() method prototype + * + * @var mixed Spreadsheet_Excel_Writer_Format object or 0 + */ + var $_bodyFormat = 0; + /** * Constructor * @@ -90,11 +111,14 @@ /** * Sets the name of the file to create * + * This is incompatible with the setCustomWriter() method + * * @param string $filename The name of the file * @param bool $sendToBrowser Whether the spreadsheet should * be send to the browser or written * to a file * @access public + * @see Structures_DataGrid_Renderer_XLS::setCustomWriter() */ function setFilename($filename = 'spreadsheet.xls', $sendToBrowser = true) { @@ -103,6 +127,44 @@ } /** + * Replace the internal Excel Writer with a custom one + * + * This is useful in order to customize your new XLS document + * before Structures_DataGrid fills it with data + * + * This method is incompatible with setFilename() + * + * @param object $workbook Spreadsheet_Excel_Writer_Workbook object + * @param object $worksheet Spreadsheet_Excel_Writer_Worksheet object + * @see Structures_DataGrid_Renderer_XLS::setFilename() + */ + function setCustomWriter (&$workbook, &$worksheet) + { + $this->_workbook =& $workbook; + $this->_worksheet =& $worksheet; + } + + /** + * Set headers format + * + * @param object $format Spreadsheet_Excel_Writer_Format object + */ + function setHeaderFormat (&$format) + { + $this->_headerFormat =& $format; + } + + /** + * Set body format + * + * @param object $format Spreadsheet_Excel_Writer_Format object + */ + function setBodyFormat (&$format) + { + $this->_bodyFormat =& $format; + } + + /** * Determines whether or not to use the header * * @access public @@ -145,20 +207,21 @@ function &getSpreadsheet() { $dg =& $this->_dg; - - if ($this->_sendToBrowser) { - $this->_workbook = new Spreadsheet_Excel_Writer(); - $this->_workbook->send($this->_filename); - } else { - $this->_workbook = new Spreadsheet_Excel_Writer($this->_filename); + + if (!isset ($this->_workbook)) { + if ($this->_sendToBrowser) { + $this->_workbook = new Spreadsheet_Excel_Writer(); + $this->_workbook->send($this->_filename); + } else { + $this->_workbook = new Spreadsheet_Excel_Writer($this->_filename); + } + } + + if (!isset ($this->_worksheet)) { + $this->_worksheet =& $this->_workbook->addWorksheet(); } - $this->_worksheet =& $this->_workbook->addWorksheet(); if (!$this->_rendered) { - /* - // Get the data to be rendered - $dg->fetchDataSource(); - */ // Check to see if column headers exist, if not create them // This must follow after any fetch method call $dg->_setDefaultHeaders(); @@ -185,7 +248,7 @@ foreach ($this->_dg->columnSet as $column) { //Define Content $str = $column->columnName; - $this->_worksheet->write(0, $cnt, $str); + $this->_worksheet->write(0, $cnt, $str, $this->_headerFormat); $cnt++; } } @@ -224,7 +287,7 @@ } } - $this->_worksheet->write($rowCnt, $cnt, $content); + $this->_worksheet->write($rowCnt, $cnt, $content, $this->_bodyFormat); $cnt++; }

« previous php.pear.cvs (#35930) next »