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

Source for file Writer.php

Documentation is available at Writer.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.  * Spreadsheet_OpenDocument_Format class file.
  11.  * 
  12.  * Implementation of a <i>Writert</i> class for OpenDocuments like the <i>Writer</i>
  13.  * class in <i>PEAR_Spreadsheet_Writer</i> 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: Writer.php 250 2007-07-31 08:52:06Z 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: Writer.php 250 2007-07-31 08:52:06Z 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/OpenDocumentSpreadsheet.php';
  53. require_once 'OpenDocumentPHP/util/Spreadsheet/Workbook.php';
  54.  
  55. /**
  56.  * Spreadsheet_OpenDocument_Writer
  57.  * 
  58.  * @category    File Formats
  59.  * @package     OpenDocumentPHP
  60.  * @subpackage  util_Spreadsheet
  61.  * @author      Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  62.  * @copyright   Copyright in 2006, 2007 by The OpenDocumentPHP Team
  63.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  64.  * @version     Release: @package_version@
  65.  * @link        http://opendocumentphp.org
  66.  * @link        http://pear.php.net/package/Spreadsheet_Excel_Writer
  67.  * @since       0.6.0 - 22. Jul. 2007
  68.  */
  69.  
  70.     /**
  71.      * The constructor. It just creates a Workbook
  72.      *
  73.      * @param       string|OpenDocumentArchive $filename   Eigther the optional filename
  74.      *                                                       for the Workbook or a completly ready
  75.      *                                                       OpenDocumentArchive object.
  76.      * @throws      Exception if no filename or OpenDocumentArchive is given.
  77.      * @since       0.6.0 - 22. Jul. 2007
  78.      */
  79.     function __construct($filename=null)
  80.     {
  81.         if (is_null($filename)) {
  82.             /*
  83.              * FATAL ERROR !!! We need a file name or a OpenDocument here! 
  84.              */
  85.             throw new Exception('Spreadsheet_OpenDocument_Writer::__construct needs a file name or a OpenDocumentArchive class as input');
  86.         }
  87.         if ($filename instanceof OpenDocumentArchive{
  88.             /*
  89.              * We got a read OpenDocumentArchive object here, everything will be fine!
  90.              */
  91.             $tmpOpenDocument $filename;
  92.         else {
  93.            /*
  94.             * We first need to create an OpenDocumentSpreadsheet file here!
  95.             */
  96.             $tmpOpenDocument new OpenDocumentSpreadsheet($filename);
  97.         }        
  98.         parent::__construct($tmpOpenDocument);            
  99.     }
  100.     
  101.     /**
  102.      * Utility function for writing formulas Converts a cell's coordinates to the A1 format.
  103.      * 
  104.      * Make sure that $col is in [0..701] as this is the range [A..ZZ]!
  105.      * Also make sure that $row is in [0..MAXINT]!
  106.      * 
  107.      * Examples:
  108.      * <code>
  109.      *      $cellA1 = Spreadsheet_OpenDocument_Writer::rowcolToCell(0, 0);
  110.      *      $cellB4 = Spreadsheet_OpenDocument_Writer::rowcolToCell(3, 1);
  111.      *      $cellD2 = Spreadsheet_OpenDocument_Writer::rowcolToCell(1, 3);
  112.      * </code>
  113.      * 
  114.      * @return      The cell identifier in A1 format
  115.      * @static
  116.      * @access      public
  117.      * @param       integer $row    Row for the cell to convert (0-indexed).
  118.      * @param       integer $col    Column for the cell to convert (0-indexed).
  119.      * 
  120.      */
  121.     static function rowcolToCell($row$col)
  122.     {
  123.         if ($row 0{
  124.             throw new Exception('Index out of bounds (row negative).');
  125.         }
  126.         
  127.         if ($col 0{
  128.             throw new Exception('Index out of bounds (col negative).');        
  129.         }
  130.         if ($col 701{
  131.             throw new Exception('Index out of bounds (col greater ZZ).');
  132.         }
  133.         $strCol '';
  134.         $c $col;   
  135.         do {
  136.             $tmp = (int) $c 26;
  137.             $strCol chr(65 $tmp$strCol;
  138.             $c $c 27;
  139.         while ($c 0);
  140.         return $strCol."$row";
  141.     }
  142.     
  143.     /**
  144.      * Send HTTP headers for the OpenDocument Calc file.
  145.      * 
  146.      * *** NOT IMPLEMENTED NOW ***
  147.      * 
  148.      * @access      public
  149.      * @param       string $filename    The filename to use for HTTP headers
  150.      * 
  151.      */
  152.     function send($filename)
  153.     {
  154.     
  155.     }
  156. }

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