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

Source for file OpenDocumentSpreadsheet.php

Documentation is available at OpenDocumentSpreadsheet.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /*
  6.  * Created on 04. Jan. 2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  7.  */
  8.  
  9. /**
  10.  * OpenDocumentSpreadsheet class file
  11.  *  
  12.  * PHP versions 5
  13.  *   
  14.  * LICENSE:
  15.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26.  *
  27.  * This software consists of voluntary contributions made by many individuals
  28.  * and is licensed under the GPL. For more information please see
  29.  * <http://opendocumentphp.org>.
  30.  * 
  31.  * $Id: OpenDocumentSpreadsheet.php 263 2007-08-06 08:28:49Z nmarkgraf $
  32.  * 
  33.  * @category    File Formats
  34.  * @package        OpenDocumentPHP
  35.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  36.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  37.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  38.  * @version        SVN: $Id: OpenDocumentSpreadsheet.php 263 2007-08-06 08:28:49Z nmarkgraf $
  39.  * @link           http://opendocumentphp.org
  40.  * @since         0.5.0 - 08. Feb. 2007
  41.  */
  42.  
  43. /**
  44.  *
  45.  */
  46. require_once 'OpenDocumentPHP/OpenDocumentAbstract.php';
  47.  
  48.  /**
  49.  * OpenDocumentSpreadsheet class.
  50.  *
  51.  * You could uses this class as follows:
  52.  *
  53.  * <code>
  54.  *         $fullpath = 'YourFavoriteCalcDocument.odc';
  55.  *         $text = new OpenDocumentSpreadsheet( $fullpath );
  56.  *         // do something with it
  57.  *         ...
  58.  *         // And write it back
  59.  *         $text->close();
  60.  * </code>
  61.  *
  62.  * If you want to revert all modifications and do not write anything back to the archive you can
  63.  * use the first parameter of this function and set it to <b>false</b>.
  64.  *
  65.  * <code>
  66.  *         $fullpath = 'YourFavoriteCalcDocument.odc';
  67.  *         $text = new OpenDocumentSpreadsheet( $fullpath );
  68.  *         // do something with it or not
  69.  *         ...
  70.  *         // But this time, we do not want to write it back to the archive
  71.  *         $text->close( false );
  72.  * </code>
  73.  *
  74.  * Be aware that even if <b>you</b> do not modifiy the OpenDocument, the library will!
  75.  * So do not expect the that the file is absolut the same after you run the close method.
  76.  * 
  77.  * @category    File Formats
  78.  * @package        OpenDocumentPHP
  79.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  80.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  81.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  82.  * @version     Release: @package_version@
  83.  * @link           http://opendocumentphp.org
  84.  * @since         0.5.0 - 08. Feb. 2007
  85.  */
  86.  
  87.     /**
  88.      * Namespace CALC
  89.      */
  90.     const odmCalcNamespace = 'application/vnd.oasis.opendocument.spreadsheet';
  91.     
  92.     /**
  93.      * Constructor method.
  94.      *
  95.      * Read (and if not exists create) an OpenDocument calc file (aka spreadsheet).
  96.      *
  97.      *     
  98.      * @param         string $fullpath Full path and name of the document
  99.      * @since         0.5.0 - 08. Feb. 2007
  100.      */
  101.     function __construct($fullpath=null
  102.     {
  103.         // Construct a text document
  104.         parent :: __construct(self :: odmCalcNamespace);
  105.         // Is the variable $fullpath given?
  106.         if (isset($fullpath&& is_string($fullpath)) {        
  107.             if (file_exists($fullpath)) {
  108.                 // File does exist, so we can load it via open.
  109.                 parent :: open($fullpath);
  110.                 $this->content->getBody()->getSpreadsheetFragment();
  111.             else {
  112.                 // File does not exist, so we can create it.        
  113.                 parent :: open($fullpathself :: CREATEself :: odmCalcNamespace);
  114.                 // Set everything to a OpenDocument CALC file.   
  115.                 $this->content->setSpreadsheet();                
  116.             }
  117.         else {
  118.             // JUST A CLEAN FILE WITH NO FILE NAME JET!!!! DANGER!!!!
  119.             $this->init();
  120.             $this->content->setSpreadsheet();
  121.         }
  122.     }
  123.     
  124.     /**
  125.      * Create a new sheet with the name '$sheetname'.
  126.      * 
  127.      * @access         public
  128.      * @param          string $sheetname The name of the new sheet
  129.      * @return         object 
  130.      * @since         0.5.0 - 08. Feb. 2007
  131.      */
  132.     function addSheet($sheetname
  133.     {
  134.         return $this->content->getTable($sheetname);
  135.     }
  136.  
  137.     /**
  138.      * Setup some default data for the meta.xml.
  139.      * 
  140.      * We will setup some data for the meta.xml document. You can use this method and
  141.      * overwrite even the static given data in this method by calling the MetaFragment
  142.      * or DublinCoreFragment methods again.
  143.      * 
  144.      * Currently we set the following meta datas:
  145.      * 
  146.      * <i>DublinCore:</i>
  147.      * <ul>
  148.      * <li>The subject is set to 'A generated subject by OpenDocumentPHP.'.</li>
  149.      * <li>The title is set to 'This is a generated title by OpenDocumentPHP.'.</li>
  150.      * <li>The description is set to 'This is a short description by OpenDocumentPHP.'.</li>
  151.      * <li>The language is set up 'en' for an english text.</li>
  152.      * </ul>
  153.      * 
  154.      * <i>(OpenDocument-)Meta:</i>
  155.      * <b>currently nothing is set here.</b>
  156.      * 
  157.      * In your own code you can change the value very simple:
  158.      * <code>
  159.      *     $doc = new OpenDocumentText('YourFavoriteText.odt');
  160.      *     ...
  161.      *     // Retreive the DublinCoreFragment to change dublin core meta data
  162.      *     $dc = $doc->getMeta()->getDublinCoreFragment();
  163.      *     // Change title to new title
  164.      *     $dc->setTitle( 'This is a new title of the document.' );
  165.      *     ...
  166.      *     // Retreive the MetaFragment to change OpenDocument meta data
  167.      *     $meta = $doc->getMeta()->getMetaFragment();
  168.      *     // Change the initial creator of the document
  169.      *     $meta->setInitialCreator( 'Robert Duck' );
  170.      *     ...
  171.      * </code>
  172.      * 
  173.      * @access      public
  174.      * @since       0.5.3 - 03. Aug. 2007
  175.      */
  176.     function setDefaultMeta(
  177.     {
  178.         // =====================================================================
  179.         $dc $this->getMeta()->getDublinCoreFragment();
  180.         // ---------------------------------------------------------------------
  181.         $dc->setSubject('A generated subject by OpenDocumentPHP.');
  182.         $dc->setTitle('This is a generated title by OpenDocumentPHP.');
  183.         $dc->setDescription('This is a short description by OpenDocumentPHP.');
  184.         $dc->setLanguage('en');
  185.         // =====================================================================    
  186.         $meta $this->getMeta()->getMetaFragment();
  187.         // ---------------------------------------------------------------------        
  188.     }
  189.  
  190.     /**
  191.      * We set up some default font face declarations here.
  192.      * 
  193.      * We put the same font face declarations in the styles.xml and content.xml
  194.      * document.
  195.      * 
  196.      * There are two font faces declared by this method:
  197.      * <i>Tahoma1</i> and <i>Arial Unicode MS</i>.
  198.      * 
  199.      * @access      public
  200.      * @since       0.5.3 - 04. Aug. 2007
  201.      */
  202.     function setDefaultFontFaces(
  203.     {
  204.         // Get the StylesDocument object
  205.         $styles $this->getStyles();
  206.         // Retrieve the FontFaceDeclarations object
  207.         $ffd $styles->getFontFaceDeclarations();
  208.         /*
  209.          * Create a new font face.
  210.          * We will call it 'Tahoma1' which depends on the 'Tahoma' font family.
  211.          */
  212.         $fontface_Tahoma $ffd->nextFontFace();
  213.         $fontface_Tahoma->setStyleName('Tahoma1');
  214.         $fontface_Tahoma->setSVGFontFamily('Tahoma');
  215.         /*
  216.          * Create a new font face.
  217.          * We will call it 'Arial Unicode MS' which depends on the 'Arial Unicode MS' font family
  218.          * and we set the font pitch to 'variable'.      
  219.          */
  220.         $fontface_Arial $ffd->nextFontFace();
  221.         $fontface_Arial->setStyleName('Arial Unicode MS');
  222.         $fontface_Arial->setSVGFontFamily(utf8_encode("'Arial Unicode MS'"));
  223.         $fontface_Arial->setFontPitch('variable');
  224.         /*
  225.          * We need FontFaceDecl in content.xml too.
  226.          * So we make a copy of the font face declaration and import this 
  227.          * to the font face declaration part of the content.xml
  228.          * 
  229.          */
  230.         $content $this->getContent();
  231.         $cffd $content->getFontFaceDeclarations();
  232.         $cffd->importNode($ffd);        
  233.     }
  234.     
  235.     /**
  236.      * Set up some default styles.
  237.      * 
  238.      * We define the 'Standart' and 'Heading_20_1' fonts in this method.
  239.      * 
  240.      * @access      public
  241.      * @since       0.5.3 - 04. Aug. 2007
  242.      */
  243.      function setDefaultStyles(
  244.      {
  245.         $default_style $this->getStyles()->getStyles()->getDefaultStyle();
  246.         $default_style->setFamily('paragraph');
  247.         
  248.         // Set paragraph properties:
  249.  
  250.         $paragraph_properties $default_style->getParagraphProperties();
  251.         $paragraph_properties->setHyphenationLadderCount('no-limit');
  252.         $paragraph_properties->setTextAutospace('ideograph-alpha');
  253.         $paragraph_properties->setPunctuationWrap ('hanging');
  254.         $paragraph_properties->setLineBreak('strict');
  255.         $paragraph_properties->setTabStopDistance('1.251cm');
  256.         $paragraph_properties->setWritingMode('page');
  257.         
  258.         // Set text properties:
  259.  
  260.         $text_properties $default_style->getTextProperties();
  261.         $text_properties->setLanguage('de');
  262.         $text_properties->setCountry('DE');
  263.         $text_properties->setFontName('Times New Roman');
  264.         $text_properties->setFontSize('12pt');
  265.         $text_properties->setFontNameAsian('Arial Unicode MS');
  266.         $text_properties->setFontSizeAsian('12pt');
  267.         $text_properties->setFontNameComplex('Tahoma');
  268.         $text_properties->setFontSizeComplex('12pt');
  269.         $text_properties->setHyphenate('false');
  270.         $text_properties->setHyphenationRemainCharCount('2');
  271.         $text_properties->setHyphenationPushCharCount('2');
  272.         // ...
  273. /*
  274.             <style:text-properties 
  275.             style:use-window-font-color="true"
  276.                 style:language-asian="none"
  277.                 style:country-asian="none" 
  278.                 style:language-complex="none"
  279.                 style:country-complex="none" 
  280. */
  281.         $style_Standard $this->getStyles()->getStyles()->getStyle();
  282.         $style_Standard->setStyleName('Standard');
  283.         $style_Standard->setFamily('paragraph');
  284.         $style_Standard->setClass('text');
  285.         
  286.     }
  287.     
  288.     
  289. }
  290. ?>

Documentation generated on Wed, 18 Jun 2008 06:31:04 +0200 by phpDocumentor 1.3.2