Commit | Line | Data |
---|---|---|
c030b5ee | 1 | <?php |
6aaa17c7 | 2 | |
117bd748 PS |
3 | // This file is part of Moodle - http://moodle.org/ |
4 | // | |
c030b5ee | 5 | // Moodle is free software: you can redistribute it and/or modify |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
117bd748 | 14 | // |
c030b5ee | 15 | // You should have received a copy of the GNU General Public License |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
6aaa17c7 | 17 | |
c030b5ee | 18 | /** |
19 | * excellib.class.php | |
117bd748 | 20 | * |
78bfb562 PS |
21 | * @copyright (C) 2001-3001 Eloy Lafuente (stronk7) {@link http://contiento.com} |
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
23 | * @package core | |
24 | * @subpackage lib | |
c030b5ee | 25 | */ |
26 | ||
78bfb562 PS |
27 | defined('MOODLE_INTERNAL') || die(); |
28 | ||
29 | /** setup.php includes our hacked pear libs first */ | |
6aaa17c7 | 30 | require_once 'Spreadsheet/Excel/Writer.php'; |
31 | ||
32 | /** | |
c030b5ee | 33 | * Define and operate over one Moodle Workbook. |
34 | * | |
35 | * A big part of this class acts as a wrapper over the PEAR | |
36 | * Spreadsheet_Excel_Writer_Workbook and OLE libraries | |
37 | * maintaining Moodle functions isolated from underlying code. | |
38 | * | |
39 | * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} | |
40 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
41 | * @package moodlecore | |
42 | */ | |
6aaa17c7 | 43 | class MoodleExcelWorkbook { |
c030b5ee | 44 | /** @var object */ |
6aaa17c7 | 45 | var $pear_excel_workbook; |
c030b5ee | 46 | /** @var bool */ |
63620581 | 47 | var $latin_output; |
6aaa17c7 | 48 | |
6d5b31e1 | 49 | /** |
50 | * Constructs one Moodle Workbook. | |
51 | * | |
c030b5ee | 52 | * @global object |
6aaa17c7 | 53 | * @param string $filename The name of the file |
54 | */ | |
55 | function MoodleExcelWorkbook($filename) { | |
ce5ce136 | 56 | global $CFG; |
6aaa17c7 | 57 | /// Internally, create one PEAR Spreadsheet_Excel_Writer_Workbook class |
58 | $this->pear_excel_workbook = new Spreadsheet_Excel_Writer($filename); | |
59 | /// Prepare it to accept UTF-16LE data and to encode it properly | |
767e6e45 | 60 | if (empty($CFG->latinexcelexport)) { /// Only if don't want to use latin (win1252) stronger output |
2f078622 | 61 | $this->pear_excel_workbook->setVersion(8); |
63620581 | 62 | $this->latin_output = false; |
63 | } else { /// We want latin (win1252) output | |
64 | $this->latin_output = true; | |
2f078622 | 65 | } |
ffbf004f | 66 | /// Choose our temporary directory - see MDL-7176, found by paulo.matos |
af9b1444 | 67 | make_temp_directory('excel'); |
7aa06e6d | 68 | $this->pear_excel_workbook->setTempDir($CFG->tempdir.'/excel'); |
6aaa17c7 | 69 | } |
70 | ||
6d5b31e1 | 71 | /** |
72 | * Create one Moodle Worksheet | |
73 | * | |
6aaa17c7 | 74 | * @param string $name Name of the sheet |
c030b5ee | 75 | * @return object MoodleExcelWorksheet |
6aaa17c7 | 76 | */ |
bf404559 TH |
77 | function add_worksheet($name = '') { |
78 | // Create the Moodle Worksheet. Returns one pointer to it | |
e4361ed6 | 79 | $ws = new MoodleExcelWorksheet ($name, $this->pear_excel_workbook, $this->latin_output); |
6aaa17c7 | 80 | return $ws; |
81 | } | |
82 | ||
6d5b31e1 | 83 | /** |
84 | * Create one Moodle Format | |
85 | * | |
6aaa17c7 | 86 | * @param array $properties array of properties [name]=value; |
87 | * valid names are set_XXXX existing | |
88 | * functions without the set_ part | |
89 | * i.e: [bold]=1 for set_bold(1)...Optional! | |
c030b5ee | 90 | * @return object MoodleExcelFormat |
6aaa17c7 | 91 | */ |
92 | function &add_format($properties = array()) { | |
93 | /// Create the Moodle Format. Returns one pointer to it | |
e4361ed6 | 94 | $ft = new MoodleExcelFormat ($this->pear_excel_workbook, $properties); |
6aaa17c7 | 95 | return $ft; |
96 | } | |
97 | ||
6d5b31e1 | 98 | /** |
99 | * Close the Moodle Workbook | |
6aaa17c7 | 100 | */ |
101 | function close() { | |
102 | $this->pear_excel_workbook->close(); | |
103 | } | |
104 | ||
6d5b31e1 | 105 | /** |
106 | * Write the correct HTTP headers | |
107 | * | |
c030b5ee | 108 | * @param string $filename Name of the downloaded file |
6aaa17c7 | 109 | */ |
110 | function send($filename) { | |
111 | $this->pear_excel_workbook->send($filename); | |
112 | } | |
113 | } | |
114 | ||
115 | /** | |
c030b5ee | 116 | * Define and operate over one Worksheet. |
117 | * | |
118 | * A big part of this class acts as a wrapper over the PEAR | |
119 | * Spreadsheet_Excel_Writer_Workbook and OLE libraries | |
120 | * maintaining Moodle functions isolated from underlying code. | |
121 | * | |
122 | * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} | |
123 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
124 | * @package moodlecore | |
125 | */ | |
6aaa17c7 | 126 | class MoodleExcelWorksheet { |
c030b5ee | 127 | /** @var object */ |
6aaa17c7 | 128 | var $pear_excel_worksheet; |
c030b5ee | 129 | /** @var bool Only if don't want to use latin (win1252) stronger output */ |
63620581 | 130 | var $latin_output; |
6aaa17c7 | 131 | |
6d5b31e1 | 132 | /** |
133 | * Constructs one Moodle Worksheet. | |
134 | * | |
6aaa17c7 | 135 | * @param string $filename The name of the file |
136 | * @param object $workbook The internal PEAR Workbook onject we are creating | |
c030b5ee | 137 | * @param bool $latin_output Only if don't want to use latin (win1252) stronger output |
6aaa17c7 | 138 | */ |
63620581 | 139 | function MoodleExcelWorksheet($name, &$workbook, $latin_output=false) { |
2f078622 | 140 | |
bf404559 TH |
141 | // Replace any characters in the name that Excel cannot cope with. |
142 | $name = strtr($name, '[]*/\?:', ' '); | |
143 | ||
0484f1ef TH |
144 | if (strlen($name) > 31) { |
145 | // Excel does not seem able to cope with sheet names > 31 chars. | |
146 | // With $latin_output = false, it does not cope at all. | |
147 | // With $latin_output = true it is supposed to work, but in our experience, | |
148 | // it doesn't. Therefore, truncate in all circumstances. | |
f8311def | 149 | $name = textlib::substr($name, 0, 31); |
0484f1ef TH |
150 | } |
151 | ||
117bd748 | 152 | /// Internally, add one sheet to the workbook |
6aaa17c7 | 153 | $this->pear_excel_worksheet =& $workbook->addWorksheet($name); |
63620581 | 154 | $this->latin_output = $latin_output; |
117bd748 | 155 | /// Set encoding to UTF-16LE |
63620581 | 156 | if (!$this->latin_output) { /// Only if don't want to use latin (win1252) stronger output |
2f078622 | 157 | $this->pear_excel_worksheet->setInputEncoding('UTF-16LE'); |
158 | } | |
6aaa17c7 | 159 | } |
160 | ||
6d5b31e1 | 161 | /** |
162 | * Write one string somewhere in the worksheet | |
163 | * | |
6aaa17c7 | 164 | * @param integer $row Zero indexed row |
165 | * @param integer $col Zero indexed column | |
166 | * @param string $str The string to write | |
167 | * @param mixed $format The XF format for the cell | |
168 | */ | |
21fed7a3 | 169 | function write_string($row, $col, $str, $format=null) { |
6aaa17c7 | 170 | /// Calculate the internal PEAR format |
171 | $format = $this->MoodleExcelFormat2PearExcelFormat($format); | |
6aaa17c7 | 172 | /// Convert the text from its original encoding to UTF-16LE |
63620581 | 173 | if (!$this->latin_output) { /// Only if don't want to use latin (win1252) stronger output |
f8311def | 174 | $str = textlib::convert($str, 'utf-8', 'utf-16le'); |
63620581 | 175 | } else { /// else, convert to latin (win1252) |
f8311def | 176 | $str = textlib::convert($str, 'utf-8', 'windows-1252'); |
2f078622 | 177 | } |
6aaa17c7 | 178 | /// Add the string safely to the PEAR Worksheet |
179 | $this->pear_excel_worksheet->writeString($row, $col, $str, $format); | |
180 | } | |
181 | ||
6d5b31e1 | 182 | /** |
183 | * Write one number somewhere in the worksheet | |
184 | * | |
6aaa17c7 | 185 | * @param integer $row Zero indexed row |
186 | * @param integer $col Zero indexed column | |
187 | * @param float $num The number to write | |
188 | * @param mixed $format The XF format for the cell | |
189 | */ | |
21fed7a3 | 190 | function write_number($row, $col, $num, $format=null) { |
6aaa17c7 | 191 | /// Calculate the internal PEAR format |
192 | $format = $this->MoodleExcelFormat2PearExcelFormat($format); | |
193 | /// Add the number safely to the PEAR Worksheet | |
194 | $this->pear_excel_worksheet->writeNumber($row, $col, $num, $format); | |
195 | } | |
196 | ||
6d5b31e1 | 197 | /** |
198 | * Write one url somewhere in the worksheet | |
199 | * | |
6aaa17c7 | 200 | * @param integer $row Zero indexed row |
201 | * @param integer $col Zero indexed column | |
202 | * @param string $url The url to write | |
203 | * @param mixed $format The XF format for the cell | |
204 | */ | |
21fed7a3 | 205 | function write_url($row, $col, $url, $format=null) { |
6aaa17c7 | 206 | /// Calculate the internal PEAR format |
207 | $format = $this->MoodleExcelFormat2PearExcelFormat($format); | |
208 | /// Add the url safely to the PEAR Worksheet | |
209 | $this->pear_excel_worksheet->writeUrl($row, $col, $url, $format); | |
210 | } | |
211 | ||
07ca3a4a FM |
212 | /** |
213 | * Write one date somewhere in the worksheet | |
214 | * @param integer $row Zero indexed row | |
215 | * @param integer $col Zero indexed column | |
216 | * @param string $date The date to write in UNIX timestamp format | |
217 | * @param mixed $format The XF format for the cell | |
218 | */ | |
219 | function write_date($row, $col, $date, $format=null) { | |
220 | /// Calculate the internal PEAR format | |
221 | $format = $this->MoodleExcelFormat2PearExcelFormat($format); | |
222 | /// Convert the date to Excel format | |
223 | $timezone = get_user_timezone_offset(); | |
869bbb30 DC |
224 | if ($timezone == 99) { |
225 | // system timezone offset in seconds | |
226 | $offset = (int)date('Z'); | |
227 | } else { | |
228 | $offset = (int)($timezone * HOURSECS * 2); | |
229 | } | |
230 | $value = ((usertime($date) + $offset) / 86400) + 25569; | |
07ca3a4a FM |
231 | /// Add the date safely to the PEAR Worksheet |
232 | $this->pear_excel_worksheet->writeNumber($row, $col, $value, $format); | |
233 | } | |
234 | ||
6d5b31e1 | 235 | /** |
236 | * Write one formula somewhere in the worksheet | |
237 | * | |
6aaa17c7 | 238 | * @param integer $row Zero indexed row |
239 | * @param integer $col Zero indexed column | |
240 | * @param string $formula The formula to write | |
241 | * @param mixed $format The XF format for the cell | |
242 | */ | |
21fed7a3 | 243 | function write_formula($row, $col, $formula, $format=null) { |
6aaa17c7 | 244 | /// Calculate the internal PEAR format |
245 | $format = $this->MoodleExcelFormat2PearExcelFormat($format); | |
246 | /// Add the formula safely to the PEAR Worksheet | |
247 | $this->pear_excel_worksheet->writeFormula($row, $col, $formula, $format); | |
248 | } | |
249 | ||
6d5b31e1 | 250 | /** |
251 | * Write one blanck somewhere in the worksheet | |
252 | * | |
6aaa17c7 | 253 | * @param integer $row Zero indexed row |
254 | * @param integer $col Zero indexed column | |
255 | * @param mixed $format The XF format for the cell | |
256 | */ | |
21fed7a3 | 257 | function write_blank($row, $col, $format=null) { |
6aaa17c7 | 258 | /// Calculate the internal PEAR format |
259 | $format = $this->MoodleExcelFormat2PearExcelFormat($format); | |
260 | /// Add the blank safely to the PEAR Worksheet | |
261 | $this->pear_excel_worksheet->writeBlank($row, $col, $format); | |
262 | } | |
263 | ||
6d5b31e1 | 264 | /** |
265 | * Write anything somewhere in the worksheet | |
6aaa17c7 | 266 | * Type will be automatically detected |
6d5b31e1 | 267 | * |
6aaa17c7 | 268 | * @param integer $row Zero indexed row |
269 | * @param integer $col Zero indexed column | |
270 | * @param mixed $token What we are writing | |
271 | * @param mixed $format The XF format for the cell | |
c030b5ee | 272 | * @return void |
6aaa17c7 | 273 | */ |
21fed7a3 | 274 | function write($row, $col, $token, $format=null) { |
6aaa17c7 | 275 | |
276 | /// Analyse what are we trying to send | |
277 | if (preg_match("/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/", $token)) { | |
278 | /// Match number | |
279 | return $this->write_number($row, $col, $token, $format); | |
280 | } elseif (preg_match("/^[fh]tt?p:\/\//", $token)) { | |
281 | /// Match http or ftp URL | |
282 | return $this->write_url($row, $col, $token, '', $format); | |
283 | } elseif (preg_match("/^mailto:/", $token)) { | |
284 | /// Match mailto: | |
285 | return $this->write_url($row, $col, $token, '', $format); | |
286 | } elseif (preg_match("/^(?:in|ex)ternal:/", $token)) { | |
287 | /// Match internal or external sheet link | |
288 | return $this->write_url($row, $col, $token, '', $format); | |
289 | } elseif (preg_match("/^=/", $token)) { | |
290 | /// Match formula | |
291 | return $this->write_formula($row, $col, $token, $format); | |
292 | } elseif (preg_match("/^@/", $token)) { | |
293 | /// Match formula | |
294 | return $this->write_formula($row, $col, $token, $format); | |
295 | } elseif ($token == '') { | |
296 | /// Match blank | |
297 | return $this->write_blank($row, $col, $format); | |
298 | } else { | |
299 | /// Default: match string | |
300 | return $this->write_string($row, $col, $token, $format); | |
301 | } | |
302 | } | |
303 | ||
6d5b31e1 | 304 | /** |
305 | * Sets the height (and other settings) of one row | |
306 | * | |
e6af2cad | 307 | * @param integer $row The row to set |
308 | * @param integer $height Height we are giving to the row (null to set just format withouth setting the height) | |
309 | * @param mixed $format The optional XF format we are giving to the row | |
310 | * @param bool $hidden The optional hidden attribute | |
311 | * @param integer $level The optional outline level (0-7) | |
312 | */ | |
21fed7a3 | 313 | function set_row ($row, $height, $format = null, $hidden = false, $level = 0) { |
e6af2cad | 314 | /// Calculate the internal PEAR format |
315 | $format = $this->MoodleExcelFormat2PearExcelFormat($format); | |
316 | /// Set the row safely to the PEAR Worksheet | |
317 | $this->pear_excel_worksheet->setRow($row, $height, $format, $hidden, $level); | |
318 | } | |
319 | ||
6d5b31e1 | 320 | /** |
321 | * Sets the width (and other settings) of one column | |
322 | * | |
e6af2cad | 323 | * @param integer $firstcol first column on the range |
324 | * @param integer $lastcol last column on the range | |
325 | * @param integer $width width to set | |
326 | * @param mixed $format The optional XF format to apply to the columns | |
327 | * @param integer $hidden The optional hidden atribute | |
328 | * @param integer $level The optional outline level (0-7) | |
329 | */ | |
21fed7a3 | 330 | function set_column ($firstcol, $lastcol, $width, $format = null, $hidden = false, $level = 0) { |
e6af2cad | 331 | /// Calculate the internal PEAR format |
332 | $format = $this->MoodleExcelFormat2PearExcelFormat($format); | |
333 | /// Set the column safely to the PEAR Worksheet | |
334 | $this->pear_excel_worksheet->setColumn($firstcol, $lastcol, $width, $format, $hidden, $level); | |
335 | } | |
336 | ||
dd41247e | 337 | /** |
338 | * Set the option to hide gridlines on the printed page. | |
339 | * | |
340 | * @access public | |
341 | */ | |
342 | function hide_gridlines() { | |
343 | $this->pear_excel_worksheet->hideGridLines(); | |
344 | } | |
345 | ||
346 | /** | |
347 | * Set the option to hide gridlines on the worksheet (as seen on the screen). | |
348 | * | |
349 | * @access public | |
350 | */ | |
351 | function hide_screen_gridlines() { | |
352 | $this->pear_excel_worksheet->hideScreenGridlines(); | |
353 | } | |
117bd748 | 354 | |
dd41247e | 355 | /** |
356 | * Insert a 24bit bitmap image in a worksheet. | |
357 | * | |
358 | * @access public | |
359 | * @param integer $row The row we are going to insert the bitmap into | |
360 | * @param integer $col The column we are going to insert the bitmap into | |
361 | * @param string $bitmap The bitmap filename | |
362 | * @param integer $x The horizontal position (offset) of the image inside the cell. | |
363 | * @param integer $y The vertical position (offset) of the image inside the cell. | |
364 | * @param integer $scale_x The horizontal scale | |
365 | * @param integer $scale_y The vertical scale | |
366 | */ | |
367 | function insert_bitmap($row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1, $scale_y = 1) { | |
368 | /// Add the bitmap safely to the PEAR Worksheet | |
369 | $this->pear_excel_worksheet->insertBitmap($row, $col, $bitmap, $x, $y, $scale_x, $scale_y); | |
370 | } | |
371 | ||
372 | /** | |
373 | * Merges the area given by its arguments. | |
374 | * This is an Excel97/2000 method. It is required to perform more complicated | |
375 | * merging than the normal setAlign('merge'). | |
376 | * | |
377 | * @access public | |
378 | * @param integer $first_row First row of the area to merge | |
379 | * @param integer $first_col First column of the area to merge | |
380 | * @param integer $last_row Last row of the area to merge | |
381 | * @param integer $last_col Last column of the area to merge | |
382 | */ | |
383 | function merge_cells($first_row, $first_col, $last_row, $last_col) { | |
384 | /// Merge cells safely to the PEAR Worksheet | |
385 | $this->pear_excel_worksheet->mergeCells($first_row, $first_col, $last_row, $last_col); | |
386 | } | |
6d5b31e1 | 387 | |
388 | /** | |
389 | * Returns the PEAR Excel Format for one Moodle Excel Format | |
390 | * | |
c030b5ee | 391 | * @param mixed $format MoodleExcelFormat object |
6aaa17c7 | 392 | * @return mixed PEAR Excel Format object |
393 | */ | |
394 | function MoodleExcelFormat2PearExcelFormat($format) { | |
21fed7a3 | 395 | if ($format) { |
6aaa17c7 | 396 | return $format->pear_excel_format; |
397 | } else { | |
21fed7a3 | 398 | return null; |
6aaa17c7 | 399 | } |
400 | } | |
401 | } | |
402 | ||
403 | ||
404 | /** | |
c030b5ee | 405 | * Define and operate over one Format. |
406 | * | |
407 | * A big part of this class acts as a wrapper over the PEAR | |
408 | * Spreadsheet_Excel_Writer_Workbook and OLE libraries | |
409 | * maintaining Moodle functions isolated from underlying code. | |
410 | * | |
411 | * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} | |
412 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
413 | * @package moodlecore | |
414 | */ | |
6aaa17c7 | 415 | class MoodleExcelFormat { |
c030b5ee | 416 | /** @var object */ |
6aaa17c7 | 417 | var $pear_excel_format; |
418 | ||
6d5b31e1 | 419 | /** |
420 | * Constructs one Moodle Format. | |
421 | * | |
6aaa17c7 | 422 | * @param object $workbook The internal PEAR Workbook onject we are creating |
c030b5ee | 423 | * @param array $properties |
6aaa17c7 | 424 | */ |
425 | function MoodleExcelFormat(&$workbook, $properties = array()) { | |
117bd748 | 426 | /// Internally, add one sheet to the workbook |
6aaa17c7 | 427 | $this->pear_excel_format =& $workbook->addFormat(); |
428 | /// If we have something in the array of properties, compute them | |
429 | foreach($properties as $property => $value) { | |
430 | if(method_exists($this,"set_$property")) { | |
431 | $aux = 'set_'.$property; | |
432 | $this->$aux($value); | |
433 | } | |
434 | } | |
435 | } | |
436 | ||
21c36940 | 437 | /** |
438 | * Set the size of the text in the format (in pixels). | |
439 | * By default all texts in generated sheets are 10px. | |
6d5b31e1 | 440 | * |
21c36940 | 441 | * @param integer $size Size of the text (in pixels) |
442 | */ | |
443 | function set_size($size) { | |
444 | /// Set the size safely to the PEAR Format | |
445 | $this->pear_excel_format->setSize($size); | |
446 | } | |
447 | ||
6d5b31e1 | 448 | /** |
449 | * Set weight of the format | |
450 | * | |
6aaa17c7 | 451 | * @param integer $weight Weight for the text, 0 maps to 400 (normal text), |
452 | * 1 maps to 700 (bold text). Valid range is: 100-1000. | |
453 | * It's Optional, default is 1 (bold). | |
454 | */ | |
455 | function set_bold($weight = 1) { | |
456 | /// Set the bold safely to the PEAR Format | |
457 | $this->pear_excel_format->setBold($weight); | |
458 | } | |
459 | ||
6d5b31e1 | 460 | /** |
461 | * Set underline of the format | |
462 | * | |
6aaa17c7 | 463 | * @param integer $underline The value for underline. Possible values are: |
464 | * 1 => underline, 2 => double underline | |
465 | */ | |
466 | function set_underline($underline) { | |
467 | /// Set the underline safely to the PEAR Format | |
468 | $this->pear_excel_format->setUnderline($underline); | |
469 | } | |
470 | ||
6d5b31e1 | 471 | /** |
472 | * Set italic of the format | |
6aaa17c7 | 473 | */ |
474 | function set_italic() { | |
475 | /// Set the italic safely to the PEAR Format | |
476 | $this->pear_excel_format->setItalic(); | |
477 | } | |
478 | ||
6d5b31e1 | 479 | /** |
480 | * Set strikeout of the format | |
6aaa17c7 | 481 | */ |
482 | function set_strikeout() { | |
483 | /// Set the strikeout safely to the PEAR Format | |
484 | $this->pear_excel_format->setStrikeOut(); | |
485 | } | |
486 | ||
6d5b31e1 | 487 | /** |
488 | * Set outlining of the format | |
6aaa17c7 | 489 | */ |
490 | function set_outline() { | |
491 | /// Set the outlining safely to the PEAR Format | |
492 | $this->pear_excel_format->setOutLine(); | |
493 | } | |
494 | ||
6d5b31e1 | 495 | /** |
496 | * Set shadow of the format | |
6aaa17c7 | 497 | */ |
498 | function set_shadow() { | |
499 | /// Set the shadow safely to the PEAR Format | |
500 | $this->pear_excel_format->setShadow(); | |
501 | } | |
502 | ||
6d5b31e1 | 503 | /** |
504 | * Set the script of the text | |
505 | * | |
6aaa17c7 | 506 | * @param integer $script The value for script type. Possible values are: |
507 | * 1 => superscript, 2 => subscript | |
508 | */ | |
509 | function set_script($script) { | |
510 | /// Set the script safely to the PEAR Format | |
511 | $this->pear_excel_format->setScript($script); | |
512 | } | |
513 | ||
6d5b31e1 | 514 | /** |
515 | * Set color of the format. Used to specify the color of the text to be formatted. | |
516 | * | |
6aaa17c7 | 517 | * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]) |
518 | */ | |
519 | function set_color($color) { | |
520 | /// Set the background color safely to the PEAR Format | |
521 | $this->pear_excel_format->setColor($color); | |
522 | } | |
523 | ||
6d5b31e1 | 524 | /** |
525 | * Set foreground color (top layer) of the format. About formatting colors note that cells backgrounds | |
526 | * have TWO layers, in order to support patterns and paint them with two diferent colors. | |
527 | * This method set the color of the TOP layer of the background format. So, when filling | |
528 | * cells with plain colors (no patterns) this is the method to use. | |
529 | * | |
6aaa17c7 | 530 | * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]) |
531 | */ | |
532 | function set_fg_color($color) { | |
533 | /// Set the foreground color safely to the PEAR Format | |
534 | $this->pear_excel_format->setFgColor($color); | |
535 | } | |
536 | ||
6d5b31e1 | 537 | /** |
538 | * Set background color (bottom layer) of the format. About formatting colors note that cells backgrounds | |
539 | * have TWO layers, in order to support patterns and paint them with two diferent colors. | |
540 | * This method set the color of the BOTTOM layer of the background format. So, the color | |
541 | * specified here only will be visible if using patterns. Use set_fg_color() to fill | |
542 | * cells with plain colors (no patterns). | |
543 | * | |
6aaa17c7 | 544 | * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]) |
545 | */ | |
546 | function set_bg_color($color) { | |
547 | /// Set the background color safely to the PEAR Format | |
548 | $this->pear_excel_format->setBgColor($color); | |
549 | } | |
550 | ||
6d5b31e1 | 551 | /** |
552 | * Set the fill pattern of the format | |
6aaa17c7 | 553 | * @param integer Optional. Defaults to 1. Meaningful values are: 0-18 |
554 | * 0 meaning no background. | |
555 | */ | |
556 | function set_pattern($pattern=1) { | |
557 | /// Set the fill pattern safely to the PEAR Format | |
558 | $this->pear_excel_format->setPattern($pattern); | |
559 | } | |
560 | ||
6d5b31e1 | 561 | /** |
562 | * Set text wrap of the format | |
6aaa17c7 | 563 | */ |
564 | function set_text_wrap() { | |
565 | /// Set the shadow safely to the PEAR Format | |
566 | $this->pear_excel_format->setTextWrap(); | |
567 | } | |
568 | ||
6d5b31e1 | 569 | /** |
570 | * Set the cell alignment of the format | |
571 | * | |
6aaa17c7 | 572 | * @param string $location alignment for the cell ('left', 'right', etc...) |
573 | */ | |
574 | function set_align($location) { | |
575 | /// Set the alignment of the cell safely to the PEAR Format | |
576 | $this->pear_excel_format->setAlign($location); | |
577 | } | |
578 | ||
6d5b31e1 | 579 | /** |
580 | * Set the cell horizontal alignment of the format | |
581 | * | |
6aaa17c7 | 582 | * @param string $location alignment for the cell ('left', 'right', etc...) |
583 | */ | |
584 | function set_h_align($location) { | |
585 | /// Set the alignment of the cell safely to the PEAR Format | |
586 | $this->pear_excel_format->setHAlign($location); | |
587 | } | |
588 | ||
6d5b31e1 | 589 | /** |
590 | * Set the cell vertical alignment of the format | |
591 | * | |
6aaa17c7 | 592 | * @param string $location alignment for the cell ('top', 'vleft', etc...) |
593 | */ | |
594 | function set_v_align($location) { | |
595 | /// Set the alignment of the cell safely to the PEAR Format | |
596 | $this->pear_excel_format->setVAlign($location); | |
597 | } | |
598 | ||
6d5b31e1 | 599 | /** |
600 | * Set the top border of the format | |
601 | * | |
6aaa17c7 | 602 | * @param integer $style style for the cell. 1 => thin, 2 => thick |
603 | */ | |
604 | function set_top($style) { | |
605 | /// Set the top border of the cell safely to the PEAR Format | |
606 | $this->pear_excel_format->setTop($style); | |
607 | } | |
608 | ||
6d5b31e1 | 609 | /** |
610 | * Set the bottom border of the format | |
611 | * | |
6aaa17c7 | 612 | * @param integer $style style for the cell. 1 => thin, 2 => thick |
613 | */ | |
614 | function set_bottom($style) { | |
615 | /// Set the bottom border of the cell safely to the PEAR Format | |
616 | $this->pear_excel_format->setBottom($style); | |
617 | } | |
618 | ||
6d5b31e1 | 619 | /** |
620 | * Set the left border of the format | |
621 | * | |
6aaa17c7 | 622 | * @param integer $style style for the cell. 1 => thin, 2 => thick |
623 | */ | |
624 | function set_left($style) { | |
625 | /// Set the left border of the cell safely to the PEAR Format | |
626 | $this->pear_excel_format->setLeft($style); | |
627 | } | |
628 | ||
6d5b31e1 | 629 | /** |
630 | * Set the right border of the format | |
631 | * | |
6aaa17c7 | 632 | * @param integer $style style for the cell. 1 => thin, 2 => thick |
633 | */ | |
634 | function set_right($style) { | |
635 | /// Set the right border of the cell safely to the PEAR Format | |
636 | $this->pear_excel_format->setRight($style); | |
637 | } | |
638 | ||
639 | /** | |
640 | * Set cells borders to the same style | |
6d5b31e1 | 641 | * |
6aaa17c7 | 642 | * @param integer $style style to apply for all cell borders. 1 => thin, 2 => thick. |
643 | */ | |
644 | function set_border($style) { | |
645 | /// Set all the borders of the cell safely to the PEAR Format | |
646 | $this->pear_excel_format->setBorder($style); | |
647 | } | |
648 | ||
6d5b31e1 | 649 | /** |
650 | * Set the numerical format of the format | |
6aaa17c7 | 651 | * It can be date, time, currency, etc... |
6d5b31e1 | 652 | * |
6aaa17c7 | 653 | * @param integer $num_format The numeric format |
654 | */ | |
655 | function set_num_format($num_format) { | |
656 | /// Set the numerical format safely to the PEAR Format | |
657 | $this->pear_excel_format->setNumFormat($num_format); | |
658 | } | |
659 | ||
660 | } |