PHPExcel_RichText
[ class tree: PHPExcel_RichText ] [ index: PHPExcel_RichText ] [ all elements ]

Source for file RichText.php

Documentation is available at RichText.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2011 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_RichText
  23.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.6, 2011-02-27
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_RichText
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_RichText
  34.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36. class PHPExcel_RichText implements PHPExcel_IComparable
  37. {
  38.     /**
  39.      * Rich text elements
  40.      *
  41.      * @var PHPExcel_RichText_ITextElement[] 
  42.      */
  43.     private $_richTextElements;
  44.  
  45.     /**
  46.      * Create a new PHPExcel_RichText instance
  47.      *
  48.      * @param     PHPExcel_Cell    $pParent 
  49.      * @throws    Exception
  50.      */
  51.     public function __construct(PHPExcel_Cell $pCell null)
  52.     {
  53.         // Initialise variables
  54.         $this->_richTextElements array();
  55.  
  56.         // Rich-Text string attached to cell?
  57.         if (!is_null($pCell)) {
  58.             // Add cell text and style
  59.             if ($pCell->getValue(!= ""{
  60.                 $objRun new PHPExcel_RichText_Run($pCell->getValue());
  61.                 $objRun->setFont(clone $pCell->getParent()->getStyle($pCell->getCoordinate())->getFont());
  62.                 $this->addText($objRun);
  63.             }
  64.  
  65.             // Set parent value
  66.             $pCell->setValueExplicit($thisPHPExcel_Cell_DataType::TYPE_STRING);
  67.         }
  68.     }
  69.  
  70.     /**
  71.      * Add text
  72.      *
  73.      * @param     PHPExcel_RichText_ITextElement        $pText        Rich text element
  74.      * @throws     Exception
  75.      * @return PHPExcel_RichText 
  76.      */
  77.     public function addText(PHPExcel_RichText_ITextElement $pText null)
  78.     {
  79.         $this->_richTextElements[$pText;
  80.         return $this;
  81.     }
  82.  
  83.     /**
  84.      * Create text
  85.      *
  86.      * @param     string    $pText    Text
  87.      * @return    PHPExcel_RichText_TextElement 
  88.      * @throws     Exception
  89.      */
  90.     public function createText($pText '')
  91.     {
  92.         $objText new PHPExcel_RichText_TextElement($pText);
  93.         $this->addText($objText);
  94.         return $objText;
  95.     }
  96.  
  97.     /**
  98.      * Create text run
  99.      *
  100.      * @param     string    $pText    Text
  101.      * @return    PHPExcel_RichText_Run 
  102.      * @throws     Exception
  103.      */
  104.     public function createTextRun($pText '')
  105.     {
  106.         $objText new PHPExcel_RichText_Run($pText);
  107.         $this->addText($objText);
  108.         return $objText;
  109.     }
  110.  
  111.     /**
  112.      * Get plain text
  113.      *
  114.      * @return string 
  115.      */
  116.     public function getPlainText()
  117.     {
  118.         // Return value
  119.         $returnValue '';
  120.  
  121.         // Loop through all PHPExcel_RichText_ITextElement
  122.         foreach ($this->_richTextElements as $text{
  123.             $returnValue .= $text->getText();
  124.         }
  125.  
  126.         // Return
  127.         return $returnValue;
  128.     }
  129.  
  130.     /**
  131.      * Convert to string
  132.      *
  133.      * @return string 
  134.      */
  135.     public function __toString({
  136.         return $this->getPlainText();
  137.     }
  138.  
  139.     /**
  140.      * Get Rich Text elements
  141.      *
  142.      * @return PHPExcel_RichText_ITextElement[] 
  143.      */
  144.     public function getRichTextElements()
  145.     {
  146.         return $this->_richTextElements;
  147.     }
  148.  
  149.     /**
  150.      * Set Rich Text elements
  151.      *
  152.      * @param     PHPExcel_RichText_ITextElement[]    $pElements        Array of elements
  153.      * @throws     Exception
  154.      * @return PHPExcel_RichText 
  155.      */
  156.     public function setRichTextElements($pElements null)
  157.     {
  158.         if (is_array($pElements)) {
  159.             $this->_richTextElements $pElements;
  160.         else {
  161.             throw new Exception("Invalid PHPExcel_RichText_ITextElement[] array passed.");
  162.         }
  163.         return $this;
  164.     }
  165.  
  166.     /**
  167.      * Get hash code
  168.      *
  169.      * @return string    Hash code
  170.      */
  171.     public function getHashCode({
  172.         $hashElements '';
  173.         foreach ($this->_richTextElements as $element{
  174.             $hashElements .= $element->getHashCode();
  175.         }
  176.  
  177.         return md5(
  178.               $hashElements
  179.             . __CLASS__
  180.         );
  181.     }
  182.  
  183.     /**
  184.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  185.      */
  186.     public function __clone({
  187.         $vars get_object_vars($this);
  188.         foreach ($vars as $key => $value{
  189.             if (is_object($value)) {
  190.                 $this->$key clone $value;
  191.             else {
  192.                 $this->$key $value;
  193.             }
  194.         }
  195.     }
  196. }

Documentation generated on Sun, 27 Feb 2011 16:33:43 -0800 by phpDocumentor 1.4.3