Source for file Worksheet.php
Documentation is available at Worksheet.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* Created on 22. Jul. 2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
* Spreadsheet_OpenDocument_Worksheet class file.
* Implementation of a <i>Worksheet</i> class for OpenDocuments like the <i>Worksheet</i>
* class in <i>PEAR_Spreadsheet_Writer</i> does.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* This software consists of voluntary contributions made by many individuals
* and is licensed under the GPL. For more information please see
* <http://opendocumentphp.org>.
* $Id: Worksheet.php 260 2007-08-03 13:42:29Z nmarkgraf $
* @package OpenDocumentPHP
* @subpackage util_Spreadsheet
* @author Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
* @copyright Copyright in 2006, 2007 by The OpenDocumentPHP Team
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
* @version SVN: $Id: Worksheet.php 260 2007-08-03 13:42:29Z nmarkgraf $
* @link http://opendocumentphp.org
* @link http://pear.php.net/package/Spreadsheet_Excel_Writer
* @since 0.6.0 - 22. Jul. 2007
require_once 'OpenDocumentPHP/OpenDocumentArchive.php';
* Spreadsheet_OpenDocument_Worksheet
* @package OpenDocumentPHP
* @subpackage util_Spreadsheet
* @author Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
* @copyright Copyright in 2006, 2007 by The OpenDocumentPHP Team
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
* @version Release: @package_version@
* @link http://opendocumentphp.org
* @link http://pear.php.net/package/Spreadsheet_Excel_Writer
* @since 0.6.0 - 22. Jul. 2007
* The storage of the worksheet.
* We simple put all the information in this multi-dimensional array.
* <li>$_sheet[$row][$col]['token'] contains the content.</li>
* <li>$_sheet[$row][$col}['format'] contains (if set) some additional format informations.</li>
* The worksheets will not be writen by this class. This work is up to the workbook class.
* Here we store the non-default colStyles
* @var string Name of the worksheet
* @var bool is this worksheet protected by a password
* @var string the password, if this sheet is protected
* @param string $name Name of the current worksheet
* Store the name of this worksheet
* initialize first and last used column
$this->firstCol = 999999;
* initialize non-default column styles
$this->colStyles = array();
* $this->automaticStyles = ?????;
* Retrieve the worksheet name.
* This is usefull when creating worksheets without a name.
* @return The worksheet's name
* @since 0.6.0 - 23. Jul. 2007
* We have to keep $firstCol and $lastCol in sync, so this will
* check if it is in sync and updated it, if needed
* @param integer $col a column that we use.
private function _updateColumns($col)
if ($col < $this->firstCol) {
if ($col > $this->lastCol) {
* Map to the appropriate write method acording to the token recieved.
* @param integer $row The row of the cell we are writing to
* @param integer $col The column of the cell we are writing to
* @param mixed $token What we are writing
* @param mixed $format The optional format to apply to the cell
* @since 0.6.0 - 23. Jul. 2007
function write($row, $col, $token, $format= null)
* Check if we need to update firstCol or lastCol
$this->_updateColumns($col);
* Check if row exists on sheet
$tmp = $this->_sheet[$row];
* If it does not, add the row.
$this->_sheet[$row] = array();
* Check if the col exists in that row
$tmp = $this->_sheet[$row][$col];
* If the col does not, add the col to the row
$this->_sheet[$row][$col] = array();
* Add token to the sheet in that row and col
$this->_sheet[$row][$col]['token'] = "$token";
* Check if will need to add a format too
if (isset ($format) && !(is_null($format))) {
* If so, add the given format to the row and col
$this->_sheet[$row][$col]['format'] = $format;
* This is comprised of two elements: the visible label and the invisible link.
* The visible label is the same as the link unless an alternative string is specified.
* The label is written using the writeString() method. Therefore the 255 characters
* string limit applies. $string and $format are optional.
* The hyperlink can be to a http, ftp, mail, internal sheet (not yet),
* or external directory url.
* @return integer 0 : normal termination -2 : row or column out of range -3 : long string truncated to 255 chars
* @param integer $row Row
* @param integer $col Column
* @param string $url URL string
* @param string $string Alternative label
* @param mixed $format The cell format
function writeUrl($row, $col, $url, $string = '', $format = null)
* Check if we need to update firstCol or lastCol
$this->_updateColumns($col);
* If no $string was given, use $url as display
* We should do some checks here ... maybe ...
$ret = $this->write($row, $col, $string, $format);
* Mark this as hyperlink ('type' = 'url')
$this->_sheet[$row][$col]['type'] = 'url';
* Add url to use ('url' = '$url);
$this->_sheet[$row][$col]['url'] = $url;
* Set the worksheet protection flag to prevent accidental modification and to hide formulas if the locked and hidden format properties have been set.
* @param string $password The password to use for protecting the sheet.
* @since 0.6.0 - 23. Jul. 2007
* Set protected flag and password, to store it later (at close) in the
* Set the width of a single column or a range of columns.
* @param integer $firstcol - first column on the range
* @param integer $lastcol - last column on the range
* @param float $width - width to set
* @param mixed $format - The optional XF format to apply to the columns
* @param integer $hidden - The optional hidden atribute
function setColumn($firstcol, $lastcol, $width, $format= null , $hidden= null)
* Check if we need to update firstCol or lastCol
$this->_updateColumns($firstCol);
$this->_updateColumns($lastCol);
* Create a new automatic style with a table-col-property and set width to $width
$newColStyle = $this->workbook->addNewAutomaticStyle();
$newColStyle->setFamily('table-column');
$colStyleName = $newColStyle->getStyleName();
$newColStyle->appendChild($newTableColProp);
$newTableColProp->setColumnWidth($width);
* Add all columns to this new property.
for($i = $firstcol; $i < $lastcol; $i++ ) {
$this->colStyles[$i] = $colStyleName;
* @since 0.6.0 - 23. Jul. 2007
|