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

Source for file Color.php

Documentation is available at Color.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2009 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_Style
  23.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.6.5, 2009-01-05
  26.  */
  27.  
  28.  
  29. /** PHPExcel_IComparable */
  30. require_once 'PHPExcel/IComparable.php';
  31.  
  32.  
  33. /**
  34.  * PHPExcel_Style_Color
  35.  *
  36.  * @category   PHPExcel
  37.  * @package    PHPExcel_Style
  38.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  39.  */
  40. class PHPExcel_Style_Color implements PHPExcel_IComparable
  41. {
  42.     /* Colors */
  43.     const COLOR_BLACK                        'FF000000';
  44.     const COLOR_WHITE                        'FFFFFFFF';
  45.     const COLOR_RED                            'FFFF0000';
  46.     const COLOR_DARKRED                        'FF800000';
  47.     const COLOR_BLUE                        'FF0000FF';
  48.     const COLOR_DARKBLUE                    'FF000080';
  49.     const COLOR_GREEN                        'FF00FF00';
  50.     const COLOR_DARKGREEN                    'FF008000';
  51.     const COLOR_YELLOW                        'FFFFFF00';
  52.     const COLOR_DARKYELLOW                    'FF808000';
  53.     
  54.     /**
  55.      * Indexed colors array
  56.      *
  57.      * @var array 
  58.      */
  59.     private static $_indexedColors;
  60.     
  61.     /**
  62.      * ARGB - Alpha RGB
  63.      *
  64.      * @var string 
  65.      */
  66.     private $_argb;
  67.         
  68.     /**
  69.      * Create a new PHPExcel_Style_Color
  70.      * 
  71.      * @param string $pARGB 
  72.      */
  73.     public function __construct($pARGB PHPExcel_Style_Color::COLOR_BLACK)
  74.     {
  75.         // Initialise values
  76.         $this->_argb            = $pARGB;
  77.     }
  78.     
  79.     /**
  80.      * Apply styles from array
  81.      * 
  82.      * <code>
  83.      * $objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray( array('rgb' => '808080') );
  84.      * </code>
  85.      * 
  86.      * @param    array    $pStyles    Array containing style information
  87.      * @throws    Exception
  88.      */
  89.     public function applyFromArray($pStyles null{
  90.         if (is_array($pStyles)) {
  91.             if (array_key_exists('rgb'$pStyles)) {
  92.                 $this->setRGB($pStyles['rgb']);
  93.             }
  94.             if (array_key_exists('argb'$pStyles)) {
  95.                 $this->setARGB($pStyles['argb']);
  96.             }
  97.         else {
  98.             throw new Exception("Invalid style array passed.");
  99.         }
  100.     }
  101.     
  102.     /**
  103.      * Get ARGB
  104.      *
  105.      * @return string 
  106.      */
  107.     public function getARGB({
  108.         return $this->_argb;
  109.     }
  110.     
  111.     /**
  112.      * Set ARGB
  113.      *
  114.      * @param string $pValue 
  115.      */
  116.     public function setARGB($pValue PHPExcel_Style_Color::COLOR_BLACK{
  117.         if ($pValue == ''{
  118.             $pValue PHPExcel_Style_Color::COLOR_BLACK;
  119.         }
  120.         $this->_argb = $pValue;
  121.     }
  122.     
  123.     /**
  124.      * Get RGB
  125.      *
  126.      * @return string 
  127.      */
  128.     public function getRGB({
  129.         return substr($this->_argb2);
  130.     }
  131.     
  132.     /**
  133.      * Set RGB
  134.      *
  135.      * @param string $pValue 
  136.      */
  137.     public function setRGB($pValue '000000'{
  138.         if ($pValue == ''{
  139.             $pValue '000000';
  140.         }
  141.         $this->_argb = 'FF' $pValue;
  142.     }
  143.     
  144.     /**
  145.      * Get indexed color
  146.      * 
  147.      * @param    int        $pIndex 
  148.      * @return    PHPExcel_Style_Color 
  149.      */
  150.     public static function indexedColor($pIndex{
  151.         // Clean parameter
  152.         $pIndex intval($pIndex);
  153.         
  154.         // Indexed colors
  155.         if (is_null(self::$_indexedColors)) {
  156.             self::$_indexedColors array();
  157.             self::$_indexedColors['00000000';
  158.             self::$_indexedColors['00FFFFFF';
  159.             self::$_indexedColors['00FF0000';
  160.             self::$_indexedColors['0000FF00';
  161.             self::$_indexedColors['000000FF';
  162.             self::$_indexedColors['00FFFF00';
  163.             self::$_indexedColors['00FF00FF';
  164.             self::$_indexedColors['0000FFFF';
  165.             self::$_indexedColors['00000000';
  166.             self::$_indexedColors['00FFFFFF';
  167.             self::$_indexedColors['00FF0000';
  168.             self::$_indexedColors['0000FF00';
  169.             self::$_indexedColors['000000FF';
  170.             self::$_indexedColors['00FFFF00';
  171.             self::$_indexedColors['00FF00FF';
  172.             self::$_indexedColors['0000FFFF';
  173.             self::$_indexedColors['00800000';
  174.             self::$_indexedColors['00008000';
  175.             self::$_indexedColors['00000080';
  176.             self::$_indexedColors['00808000';
  177.             self::$_indexedColors['00800080';
  178.             self::$_indexedColors['00008080';
  179.             self::$_indexedColors['00C0C0C0';
  180.             self::$_indexedColors['00808080';
  181.             self::$_indexedColors['009999FF';
  182.             self::$_indexedColors['00993366';
  183.             self::$_indexedColors['00FFFFCC';
  184.             self::$_indexedColors['00CCFFFF';
  185.             self::$_indexedColors['00660066';
  186.             self::$_indexedColors['00FF8080';
  187.             self::$_indexedColors['000066CC';
  188.             self::$_indexedColors['00CCCCFF';
  189.             self::$_indexedColors['00000080';
  190.             self::$_indexedColors['00FF00FF';
  191.             self::$_indexedColors['00FFFF00';
  192.             self::$_indexedColors['0000FFFF';
  193.             self::$_indexedColors['00800080';
  194.             self::$_indexedColors['00800000';
  195.             self::$_indexedColors['00008080';
  196.             self::$_indexedColors['000000FF';
  197.             self::$_indexedColors['0000CCFF';
  198.             self::$_indexedColors['00CCFFFF';
  199.             self::$_indexedColors['00CCFFCC';
  200.             self::$_indexedColors['00FFFF99';
  201.             self::$_indexedColors['0099CCFF';
  202.             self::$_indexedColors['00FF99CC';
  203.             self::$_indexedColors['00CC99FF';
  204.             self::$_indexedColors['00FFCC99';
  205.             self::$_indexedColors['003366FF';
  206.             self::$_indexedColors['0033CCCC';
  207.             self::$_indexedColors['0099CC00';
  208.             self::$_indexedColors['00FFCC00';
  209.             self::$_indexedColors['00FF9900';
  210.             self::$_indexedColors['00FF6600';
  211.             self::$_indexedColors['00666699';
  212.             self::$_indexedColors['00969696';
  213.             self::$_indexedColors['00003366';
  214.             self::$_indexedColors['00339966';
  215.             self::$_indexedColors['00003300';
  216.             self::$_indexedColors['00333300';
  217.             self::$_indexedColors['00993300';
  218.             self::$_indexedColors['00993366';
  219.             self::$_indexedColors['00333399';
  220.             self::$_indexedColors['00333333';
  221.         }
  222.         
  223.         if (array_key_exists($pIndexself::$_indexedColors)) {
  224.             return new PHPExcel_Style_Color(self::$_indexedColors[$pIndex]);
  225.         }
  226.         
  227.         return new PHPExcel_Style_Color();
  228.     }
  229.  
  230.     /**
  231.      * Get hash code
  232.      *
  233.      * @return string    Hash code
  234.      */    
  235.     public function getHashCode({
  236.         return md5(
  237.               $this->_argb
  238.             . __CLASS__
  239.         );
  240.     }
  241.     
  242.     /**
  243.      * Hash index
  244.      *
  245.      * @var string 
  246.      */
  247.     private $_hashIndex;
  248.     
  249.     /**
  250.      * Get hash index
  251.      * 
  252.      * Note that this index may vary during script execution! Only reliable moment is
  253.      * while doing a write of a workbook and when changes are not allowed.
  254.      *
  255.      * @return string    Hash index
  256.      */
  257.     public function getHashIndex({
  258.         return $this->_hashIndex;
  259.     }
  260.     
  261.     /**
  262.      * Set hash index
  263.      * 
  264.      * Note that this index may vary during script execution! Only reliable moment is
  265.      * while doing a write of a workbook and when changes are not allowed.
  266.      *
  267.      * @param string    $value    Hash index
  268.      */
  269.     public function setHashIndex($value{
  270.         $this->_hashIndex = $value;
  271.     }
  272.         
  273.     /**
  274.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  275.      */
  276.     public function __clone({
  277.         $vars get_object_vars($this);
  278.         foreach ($vars as $key => $value{
  279.             if (is_object($value)) {
  280.                 $this->$key clone $value;
  281.             else {
  282.                 $this->$key $value;
  283.             }
  284.         }
  285.     }
  286. }

Documentation generated on Mon, 05 Jan 2009 20:36:41 +0100 by phpDocumentor 1.4.1