Subversion Repositories eFlore/Applications.cel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2388 jpm 1
<?php
2
/**
3
 * PHPExcel
4
 *
5
 * Copyright (c) 2006 - 2013 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 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
24
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
25
 * @version    ##VERSION##, ##DATE##
26
 */
27
 
28
 
29
/**
30
 * PHPExcel_RichText
31
 *
32
 * @category   PHPExcel
33
 * @package    PHPExcel_RichText
34
 * @copyright  Copyright (c) 2006 - 2013 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 $pCell
49
     * @throws PHPExcel_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 ($pCell !== NULL) {
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($this, PHPExcel_Cell_DataType::TYPE_STRING);
67
        }
68
    }
69
 
70
    /**
71
     * Add text
72
     *
73
     * @param PHPExcel_RichText_ITextElement $pText Rich text element
74
     * @throws PHPExcel_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 PHPExcel_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 PHPExcel_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
    {
137
        return $this->getPlainText();
138
    }
139
 
140
    /**
141
     * Get Rich Text elements
142
     *
143
     * @return PHPExcel_RichText_ITextElement[]
144
     */
145
    public function getRichTextElements()
146
    {
147
        return $this->_richTextElements;
148
    }
149
 
150
    /**
151
     * Set Rich Text elements
152
     *
153
     * @param PHPExcel_RichText_ITextElement[] $pElements Array of elements
154
     * @throws PHPExcel_Exception
155
     * @return PHPExcel_RichText
156
     */
157
    public function setRichTextElements($pElements = null)
158
    {
159
        if (is_array($pElements)) {
160
            $this->_richTextElements = $pElements;
161
        } else {
162
            throw new PHPExcel_Exception("Invalid PHPExcel_RichText_ITextElement[] array passed.");
163
        }
164
        return $this;
165
    }
166
 
167
    /**
168
     * Get hash code
169
     *
170
     * @return string    Hash code
171
     */
172
    public function getHashCode()
173
    {
174
        $hashElements = '';
175
        foreach ($this->_richTextElements as $element) {
176
            $hashElements .= $element->getHashCode();
177
        }
178
 
179
        return md5(
180
              $hashElements
181
            . __CLASS__
182
        );
183
    }
184
 
185
    /**
186
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
187
     */
188
    public function __clone()
189
    {
190
        $vars = get_object_vars($this);
191
        foreach ($vars as $key => $value) {
192
            if (is_object($value)) {
193
                $this->$key = clone $value;
194
            } else {
195
                $this->$key = $value;
196
            }
197
        }
198
    }
199
}