[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/phpexcel/PHPExcel/ -> RichText.php (source)

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1