phpDocumentor OpenDocumentPHP
util_Spreadsheet
[ class tree: OpenDocumentPHP ] [ index: OpenDocumentPHP ] [ all elements ]

Source for file Workbook.php

Documentation is available at Workbook.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /*
  6.  * Created on 22. Jul. 2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  7.  */
  8.  
  9. /**
  10.  * Speadsheet_OpenDocument_Workbook class file.
  11.  * 
  12.  * Implementation of a Workbook for OpenDocuments like the PEAR_Spreadsheet_Writer
  13.  * does.
  14.  * 
  15.  * PHP versions 5
  16.  *   
  17.  * LICENSE:
  18.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  *
  30.  * This software consists of voluntary contributions made by many individuals
  31.  * and is licensed under the GPL. For more information please see
  32.  * <http://opendocumentphp.org>.
  33.  * 
  34.  * $Id: Workbook.php 257 2007-08-02 12:19:56Z nmarkgraf $
  35.  * 
  36.  * @category    File Formats
  37.  * @package     OpenDocumentPHP
  38.  * @subpackage  util_Spreadsheet
  39.  * @author      Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  40.  * @copyright   Copyright in 2006, 2007 by The OpenDocumentPHP Team
  41.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  42.  * @version     SVN: $Id: Workbook.php 257 2007-08-02 12:19:56Z nmarkgraf $
  43.  * @link        http://opendocumentphp.org
  44.  * @link        http://pear.php.net/package/Spreadsheet_Excel_Writer
  45.  * @since       0.6.0 - 22. Jul. 2007
  46.  */
  47.  
  48. /**
  49.  * 
  50.  */
  51. require_once 'OpenDocumentPHP/OpenDocumentArchive.php';
  52. require_once 'OpenDocumentPHP/util/Spreadsheet/Worksheet.php';
  53.  
  54. /**
  55.  * Spreadsheet_OpenDocument_Workbook
  56.  * 
  57.  * @category    File Formats
  58.  * @package     OpenDocumentPHP
  59.  * @subpackage  util_Spreadsheet
  60.  * @author      Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  61.  * @copyright   Copyright in 2006, 2007 by The OpenDocumentPHP Team
  62.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  63.  * @version     Release: @package_version@
  64.  * @link        http://opendocumentphp.org
  65.  * @link        http://pear.php.net/package/Spreadsheet_Excel_Writer
  66.  * @since       0.6.0 - 22. Jul. 2007
  67.  */
  68.  
  69.     protected $_worksheets;
  70.  
  71.     protected $mainOpenDocument;
  72.     
  73.     protected $_automaticStyles;
  74.  
  75.     /**
  76.      * Constructor
  77.      */
  78.     function __construct($openDocument)
  79.     {
  80.         /*
  81.          * Connect this Workbook to the $opendocument
  82.          */
  83.         $this->mainOpenDocument = $openDocument;
  84.         /*
  85.          * Initialize the worksheets array
  86.          */
  87.         $this->_worksheets = array();
  88.         /*
  89.          * Initialize automatic-styles class.
  90.          */
  91.         $this->_automaticStyles = $this->mainOpenDocument->getContent()->getAutomaticStyles();
  92.         /*
  93.          * Add something like:
  94.          * <style:style style:name="DefaultColumn" style:family="table-column">
  95.          *      <style:table-column-properties fo:break-before="auto"
  96.          *                                     style:column-width="2.267cm" />
  97.          * </style:style>
  98.          *  
  99.          */
  100.         $defColStyle $this->addNewAutomaticStyle('DefaultColumn');
  101.         $tableColumnProperties new TableColumnProperties();
  102.         $defColStyle->appendChild($tableColumnProperties);
  103.         $tableColumnProperties->setColumnWidth('2.267cm');
  104.         /*
  105.          * Add something like:      
  106.          * <style:style style:name="ro1" style:family="table-row">
  107.          *      <style:table-row-properties style:row-height="0.453cm"
  108.          *                                  fo:break-before="auto" 
  109.          *                                  style:use-optimal-row-height="true" />
  110.          * </style:style>
  111.          */
  112.         $defRowStyle $this->addNewAutomaticStyle('DefaultRow');
  113.         $tableRowProperties new TableRowProperties();
  114.         $defRowStyle->appendChild($tableRowProperties);
  115.         $tableRowProperties->setRowHeight('0.453cm');
  116.         $tableRowProperties->setUseOptimalRowHeight();
  117.         
  118. /*        
  119.         <style:style style:name="co2" style:family="table-column">
  120.             <style:table-column-properties fo:break-before="auto"
  121.                 style:column-width="1cm" />
  122.         </style:style>
  123. */        
  124.         
  125.     }
  126.     
  127.     /**
  128.      * @param $name string
  129.      * @return Worksheet|PEAR_ErrorWorksheet object on success, PEAR_Error on failure
  130.      */     
  131.     function addWorksheet($name=''
  132.     {
  133.         /*
  134.          * Check if $opendocument is from type Calc.
  135.          * Connect this Worksheet to the $opendocument
  136.         $this->mainOpenDocument = $opendocument;
  137.          */
  138.         /*
  139.          * Check if no $name was given, in this case we need to find a free space 
  140.          * and add the new worksheer there.
  141.          */
  142.         if ($name ''{
  143.             $i 0;
  144.             while ($this->_worksheets["$i"]{
  145.                 $i++;
  146.             }
  147.             $name "$i";
  148.         }
  149.         /*
  150.          * Create a new OpenDocument Worksheet
  151.          */
  152.         $newWorksheet new Spreadsheet_OpenDocument_Worksheet($name$this);
  153.         /*
  154.          * Add it to the worksheet list
  155.          */
  156.         $this->_worksheets[$name$newWorksheet;
  157.         /*
  158.          * return the new worksheet
  159.          */
  160.         return $newWorksheet
  161.     }
  162.     
  163.     /**
  164.      * @param $properties array
  165.      */
  166.     function addFormat($properties=array())
  167.     {
  168.     
  169.     }
  170.     
  171.     /**
  172.      * @param $dir string
  173.      */
  174.     function setTempDir($dir)
  175.     {
  176.     
  177.     }
  178.     
  179.     /**
  180.      * @param integer $index, 
  181.      * @param integer $red 
  182.      * @param integer $green 
  183.      * @param integer $blue 
  184.      */
  185.     function setCustomsColor($index$red$green$blue)
  186.     {
  187.     
  188.     }
  189.     
  190.     /**
  191.      * @return bool|PEAR_Errortrue on success, PEAR_Error on failure
  192.      */
  193.     function close(
  194.     {           
  195.         /*
  196.          * We need to check if there is any worksheet in the workbook.
  197.          * If there are some, we include ever worksheet to the 
  198.          * OpenDocument calc archive
  199.          */
  200.  
  201.         /*
  202.          * Get body object of the OpenDocument.
  203.          */
  204.         $body $this->mainOpenDocument->getContent()->getBody();
  205.         
  206.         foreach($this->_worksheets as $worksheet{
  207.             /*
  208.              * create a new table
  209.              */
  210.             $table $body->getNewTableFragment($worksheet->getName());
  211.             /*
  212.              * If this worksheet is protected by a password...
  213.              */
  214.             if ($worksheet->proteced{
  215.                 /*
  216.                  * ... add password to the table in the OpenDocument
  217.                  */
  218.                 $table->setProtection('true'$worksheet->protectionKey);             
  219.             }
  220.             /*
  221.              * 
  222.              */
  223.             /*
  224.              * Put cells into the OpenDocument
  225.              */
  226.             $cells $worksheet->getCells();
  227.             foreach($cells as $row => $cellRow{
  228.                 foreach($cellRow as $col => $cellRowCol{
  229.                     switch ($cellRowCol['type']{
  230.                         case 'url':
  231.                             $cell $table->getCell($col$row);
  232.                             $cell->setLinkContent($cellRowCol['url']$cellRowCol['token']);
  233.                             break;
  234.                             
  235.                         default:
  236.                             $table->setCellContent($cellRowCol['token']$col$row);
  237.                     }
  238.                 }
  239.             }
  240.         }
  241.         $tmp $body->getDocumentFragment();
  242.         $this->mainOpenDocument->close();
  243.         return true;
  244.     }
  245.     
  246.     function addNewAutomaticStyle($name=null{
  247.         static $counter 1;
  248.         $newStyle new Style();
  249.         $this->_automaticStyles->appendChild($newStyle);
  250.         if (is_null($name)) {
  251.             $newStyle->setStyleName('au'."$counter");
  252.             $counter++;
  253.         else {
  254.             $newStyle->setStyleName($name);
  255.         }
  256.         return $newStyle;                
  257.     }
  258. }
  259. ?>

Documentation generated on Wed, 18 Jun 2008 06:34:26 +0200 by phpDocumentor 1.3.2