21
21
* @category PHPExcel
22
22
* @package PHPExcel_RichText
23
23
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
24
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
25
* @version ##VERSION##, ##DATE##
26
26
*/
27
27
35
35
*/
36
36
class PHPExcel_RichText implements PHPExcel_IComparable
37
37
{
38
- /**
39
- * Rich text elements
40
- *
41
- * @var PHPExcel_RichText_ITextElement[]
42
- */
43
- private $ _richTextElements ;
38
+ /**
39
+ * Rich text elements
40
+ *
41
+ * @var PHPExcel_RichText_ITextElement[]
42
+ */
43
+ private $ _richTextElements ;
44
44
45
45
/**
46
46
* Create a new PHPExcel_RichText instance
47
47
*
48
- * @param PHPExcel_Cell $pParent
49
- * @throws PHPExcel_Exception
48
+ * @param PHPExcel_Cell $pParent
49
+ * @throws PHPExcel_Exception
50
50
*/
51
51
public function __construct (PHPExcel_Cell $ pCell = null )
52
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
- }
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
68
}
69
69
70
70
/**
71
71
* Add text
72
72
*
73
- * @param PHPExcel_RichText_ITextElement $pText Rich text element
74
- * @throws PHPExcel_Exception
73
+ * @param PHPExcel_RichText_ITextElement $pText Rich text element
74
+ * @throws PHPExcel_Exception
75
75
* @return PHPExcel_RichText
76
76
*/
77
77
public function addText (PHPExcel_RichText_ITextElement $ pText = null )
78
78
{
79
- $ this ->_richTextElements [] = $ pText ;
80
- return $ this ;
79
+ $ this ->_richTextElements [] = $ pText ;
80
+ return $ this ;
81
81
}
82
82
83
83
/**
84
84
* Create text
85
85
*
86
- * @param string $pText Text
87
- * @return PHPExcel_RichText_TextElement
88
- * @throws PHPExcel_Exception
86
+ * @param string $pText Text
87
+ * @return PHPExcel_RichText_TextElement
88
+ * @throws PHPExcel_Exception
89
89
*/
90
90
public function createText ($ pText = '' )
91
91
{
92
- $ objText = new PHPExcel_RichText_TextElement ($ pText );
93
- $ this ->addText ($ objText );
94
- return $ objText ;
92
+ $ objText = new PHPExcel_RichText_TextElement ($ pText );
93
+ $ this ->addText ($ objText );
94
+ return $ objText ;
95
95
}
96
96
97
97
/**
98
98
* Create text run
99
99
*
100
- * @param string $pText Text
101
- * @return PHPExcel_RichText_Run
102
- * @throws PHPExcel_Exception
100
+ * @param string $pText Text
101
+ * @return PHPExcel_RichText_Run
102
+ * @throws PHPExcel_Exception
103
103
*/
104
104
public function createTextRun ($ pText = '' )
105
105
{
106
- $ objText = new PHPExcel_RichText_Run ($ pText );
107
- $ this ->addText ($ objText );
108
- return $ objText ;
106
+ $ objText = new PHPExcel_RichText_Run ($ pText );
107
+ $ this ->addText ($ objText );
108
+ return $ objText ;
109
109
}
110
110
111
111
/**
@@ -115,25 +115,26 @@ public function createTextRun($pText = '')
115
115
*/
116
116
public function getPlainText ()
117
117
{
118
- // Return value
119
- $ returnValue = '' ;
118
+ // Return value
119
+ $ returnValue = '' ;
120
120
121
- // Loop through all PHPExcel_RichText_ITextElement
122
- foreach ($ this ->_richTextElements as $ text ) {
123
- $ returnValue .= $ text ->getText ();
124
- }
121
+ // Loop through all PHPExcel_RichText_ITextElement
122
+ foreach ($ this ->_richTextElements as $ text ) {
123
+ $ returnValue .= $ text ->getText ();
124
+ }
125
125
126
- // Return
127
- return $ returnValue ;
126
+ // Return
127
+ return $ returnValue ;
128
128
}
129
129
130
130
/**
131
131
* Convert to string
132
132
*
133
133
* @return string
134
134
*/
135
- public function __toString () {
136
- return $ this ->getPlainText ();
135
+ public function __toString ()
136
+ {
137
+ return $ this ->getPlainText ();
137
138
}
138
139
139
140
/**
@@ -143,54 +144,56 @@ public function __toString() {
143
144
*/
144
145
public function getRichTextElements ()
145
146
{
146
- return $ this ->_richTextElements ;
147
+ return $ this ->_richTextElements ;
147
148
}
148
149
149
150
/**
150
151
* Set Rich Text elements
151
152
*
152
- * @param PHPExcel_RichText_ITextElement[] $pElements Array of elements
153
- * @throws PHPExcel_Exception
153
+ * @param PHPExcel_RichText_ITextElement[] $pElements Array of elements
154
+ * @throws PHPExcel_Exception
154
155
* @return PHPExcel_RichText
155
156
*/
156
157
public function setRichTextElements ($ pElements = null )
157
158
{
158
- if (is_array ($ pElements )) {
159
- $ this ->_richTextElements = $ pElements ;
160
- } else {
161
- throw new PHPExcel_Exception ("Invalid PHPExcel_RichText_ITextElement[] array passed. " );
162
- }
163
- return $ this ;
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 ;
164
165
}
165
166
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
- );
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
+ );
181
183
}
182
184
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
- }
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
+ }
196
199
}
0 commit comments