Subversion Repositories eFlore/Applications.cel

Rev

Rev 1604 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
418 aurelien 1
<?php
2
/*
3
*  Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
4
*
5
*  The majority of this is _NOT_ my code.  I simply ported it from the
6
*  PERL Spreadsheet::WriteExcel module.
7
*
1604 raphael 8
*  The author of the Spreadsheet::WriteExcel module is John McNamara
418 aurelien 9
*  <jmcnamara@cpan.org>
10
*
11
*  I _DO_ maintain this code, and John McNamara has nothing to do with the
12
*  porting of this code to PHP.  Any questions directly related to this
13
*  class library should be directed to me.
14
*
15
*  License Information:
16
*
17
*    Spreadsheet_Excel_Writer:  A library for generating Excel Spreadsheets
18
*    Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
19
*
20
*    This library is free software; you can redistribute it and/or
21
*    modify it under the terms of the GNU Lesser General Public
22
*    License as published by the Free Software Foundation; either
23
*    version 2.1 of the License, or (at your option) any later version.
24
*
25
*    This library is distributed in the hope that it will be useful,
26
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
27
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28
*    Lesser General Public License for more details.
29
*
30
*    You should have received a copy of the GNU Lesser General Public
31
*    License along with this library; if not, write to the Free Software
32
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
*/
34
 
1604 raphael 35
require_once 'PEAR.php';
418 aurelien 36
 
37
/**
38
* Class for generating Excel XF records (formats)
39
*
40
* @author   Xavier Noguer <xnoguer@rezebra.com>
41
* @category FileFormats
42
* @package  Spreadsheet_Excel_Writer
43
*/
44
 
45
class Spreadsheet_Excel_Writer_Format extends PEAR
46
{
47
    /**
48
    * The index given by the workbook when creating a new format.
49
    * @var integer
50
    */
51
    var $_xf_index;
52
 
53
    /**
54
    * Index to the FONT record.
55
    * @var integer
56
    */
57
    var $font_index;
58
 
59
    /**
60
    * The font name (ASCII).
61
    * @var string
62
    */
63
    var $_font_name;
64
 
65
    /**
66
    * Height of font (1/20 of a point)
67
    * @var integer
68
    */
69
    var $_size;
70
 
71
    /**
72
    * Bold style
73
    * @var integer
74
    */
75
    var $_bold;
76
 
77
    /**
78
    * Bit specifiying if the font is italic.
79
    * @var integer
80
    */
81
    var $_italic;
82
 
83
    /**
84
    * Index to the cell's color
85
    * @var integer
86
    */
87
    var $_color;
88
 
89
    /**
90
    * The text underline property
91
    * @var integer
92
    */
93
    var $_underline;
94
 
95
    /**
96
    * Bit specifiying if the font has strikeout.
97
    * @var integer
98
    */
99
    var $_font_strikeout;
100
 
101
    /**
102
    * Bit specifiying if the font has outline.
103
    * @var integer
104
    */
105
    var $_font_outline;
106
 
107
    /**
108
    * Bit specifiying if the font has shadow.
109
    * @var integer
110
    */
111
    var $_font_shadow;
112
 
113
    /**
114
    * 2 bytes specifiying the script type for the font.
115
    * @var integer
116
    */
117
    var $_font_script;
118
 
119
    /**
120
    * Byte specifiying the font family.
121
    * @var integer
122
    */
123
    var $_font_family;
124
 
125
    /**
126
    * Byte specifiying the font charset.
127
    * @var integer
128
    */
129
    var $_font_charset;
130
 
131
    /**
132
    * An index (2 bytes) to a FORMAT record (number format).
133
    * @var integer
134
    */
135
    var $_num_format;
136
 
137
    /**
138
    * Bit specifying if formulas are hidden.
139
    * @var integer
140
    */
141
    var $_hidden;
142
 
143
    /**
144
    * Bit specifying if the cell is locked.
145
    * @var integer
146
    */
147
    var $_locked;
148
 
149
    /**
150
    * The three bits specifying the text horizontal alignment.
151
    * @var integer
152
    */
153
    var $_text_h_align;
154
 
155
    /**
156
    * Bit specifying if the text is wrapped at the right border.
157
    * @var integer
158
    */
159
    var $_text_wrap;
160
 
161
    /**
162
    * The three bits specifying the text vertical alignment.
163
    * @var integer
164
    */
165
    var $_text_v_align;
166
 
167
    /**
168
    * 1 bit, apparently not used.
169
    * @var integer
170
    */
171
    var $_text_justlast;
172
 
173
    /**
174
    * The two bits specifying the text rotation.
175
    * @var integer
176
    */
177
    var $_rotation;
178
 
179
    /**
180
    * The cell's foreground color.
181
    * @var integer
182
    */
183
    var $_fg_color;
184
 
185
    /**
186
    * The cell's background color.
187
    * @var integer
188
    */
189
    var $_bg_color;
190
 
191
    /**
192
    * The cell's background fill pattern.
193
    * @var integer
194
    */
195
    var $_pattern;
196
 
197
    /**
198
    * Style of the bottom border of the cell
199
    * @var integer
200
    */
201
    var $_bottom;
202
 
203
    /**
204
    * Color of the bottom border of the cell.
205
    * @var integer
206
    */
207
    var $_bottom_color;
208
 
209
    /**
210
    * Style of the top border of the cell
211
    * @var integer
212
    */
213
    var $_top;
214
 
215
    /**
216
    * Color of the top border of the cell.
217
    * @var integer
218
    */
219
    var $_top_color;
220
 
221
    /**
222
    * Style of the left border of the cell
223
    * @var integer
224
    */
225
    var $_left;
226
 
227
    /**
228
    * Color of the left border of the cell.
229
    * @var integer
230
    */
231
    var $_left_color;
232
 
233
    /**
234
    * Style of the right border of the cell
235
    * @var integer
236
    */
237
    var $_right;
238
 
239
    /**
240
    * Color of the right border of the cell.
241
    * @var integer
242
    */
243
    var $_right_color;
244
 
245
    /**
246
    * Constructor
247
    *
1604 raphael 248
    * @access private
418 aurelien 249
    * @param integer $index the XF index for the format.
250
    * @param array   $properties array with properties to be set on initialization.
251
    */
3473 killian 252
    function __construct($BIFF_version, $index = 0, $properties =  array())
418 aurelien 253
    {
254
        $this->_xf_index       = $index;
1604 raphael 255
        $this->_BIFF_version   = $BIFF_version;
418 aurelien 256
        $this->font_index      = 0;
257
        $this->_font_name      = 'Arial';
258
        $this->_size           = 10;
259
        $this->_bold           = 0x0190;
260
        $this->_italic         = 0;
261
        $this->_color          = 0x7FFF;
262
        $this->_underline      = 0;
263
        $this->_font_strikeout = 0;
264
        $this->_font_outline   = 0;
265
        $this->_font_shadow    = 0;
266
        $this->_font_script    = 0;
267
        $this->_font_family    = 0;
268
        $this->_font_charset   = 0;
1604 raphael 269
 
418 aurelien 270
        $this->_num_format     = 0;
1604 raphael 271
 
418 aurelien 272
        $this->_hidden         = 0;
1604 raphael 273
        $this->_locked         = 0;
418 aurelien 274
 
275
        $this->_text_h_align   = 0;
276
        $this->_text_wrap      = 0;
277
        $this->_text_v_align   = 2;
278
        $this->_text_justlast  = 0;
279
        $this->_rotation       = 0;
280
 
281
        $this->_fg_color       = 0x40;
282
        $this->_bg_color       = 0x41;
283
 
284
        $this->_pattern        = 0;
1604 raphael 285
 
418 aurelien 286
        $this->_bottom         = 0;
287
        $this->_top            = 0;
288
        $this->_left           = 0;
289
        $this->_right          = 0;
1604 raphael 290
        $this->_diag           = 0;
291
 
418 aurelien 292
        $this->_bottom_color   = 0x40;
293
        $this->_top_color      = 0x40;
294
        $this->_left_color     = 0x40;
295
        $this->_right_color    = 0x40;
1604 raphael 296
        $this->_diag_color     = 0x40;
297
 
418 aurelien 298
        // Set properties passed to Spreadsheet_Excel_Writer_Workbook::addFormat()
1604 raphael 299
        foreach ($properties as $property => $value)
418 aurelien 300
        {
1604 raphael 301
            if (method_exists($this, 'set'.ucwords($property))) {
418 aurelien 302
                $method_name = 'set'.ucwords($property);
303
                $this->$method_name($value);
304
            }
305
        }
306
    }
307
 
308
 
309
    /**
310
    * Generate an Excel BIFF XF record (style or cell).
311
    *
312
    * @param string $style The type of the XF record ('style' or 'cell').
313
    * @return string The XF record
314
    */
315
    function getXf($style)
316
    {
317
        // Set the type of the XF record and some of the attributes.
1604 raphael 318
        if ($style == 'style') {
418 aurelien 319
            $style = 0xFFF5;
1604 raphael 320
        } else {
418 aurelien 321
            $style   = $this->_locked;
322
            $style  |= $this->_hidden << 1;
323
        }
1604 raphael 324
 
418 aurelien 325
        // Flags to indicate if attributes have been set.
326
        $atr_num     = ($this->_num_format != 0)?1:0;
327
        $atr_fnt     = ($this->font_index != 0)?1:0;
328
        $atr_alc     = ($this->_text_wrap)?1:0;
329
        $atr_bdr     = ($this->_bottom   ||
330
                        $this->_top      ||
331
                        $this->_left     ||
332
                        $this->_right)?1:0;
333
        $atr_pat     = (($this->_fg_color != 0x40) ||
334
                        ($this->_bg_color != 0x41) ||
335
                        $this->_pattern)?1:0;
1604 raphael 336
        $atr_prot    = $this->_locked | $this->_hidden;
337
 
418 aurelien 338
        // Zero the default border colour if the border has not been set.
339
        if ($this->_bottom == 0) {
340
            $this->_bottom_color = 0;
1604 raphael 341
        }
418 aurelien 342
        if ($this->_top  == 0) {
343
            $this->_top_color = 0;
1604 raphael 344
        }
418 aurelien 345
        if ($this->_right == 0) {
346
            $this->_right_color = 0;
1604 raphael 347
        }
418 aurelien 348
        if ($this->_left == 0) {
349
            $this->_left_color = 0;
1604 raphael 350
        }
351
        if ($this->_diag == 0) {
352
            $this->_diag_color = 0;
353
        }
354
 
418 aurelien 355
        $record         = 0x00E0;              // Record identifier
1604 raphael 356
        if ($this->_BIFF_version == 0x0500) {
357
            $length         = 0x0010;              // Number of bytes to follow
358
        }
359
        if ($this->_BIFF_version == 0x0600) {
360
            $length         = 0x0014;
361
        }
362
 
418 aurelien 363
        $ifnt           = $this->font_index;   // Index to FONT record
364
        $ifmt           = $this->_num_format;  // Index to FORMAT record
1604 raphael 365
        if ($this->_BIFF_version == 0x0500) {
366
            $align          = $this->_text_h_align;       // Alignment
367
            $align         |= $this->_text_wrap     << 3;
368
            $align         |= $this->_text_v_align  << 4;
369
            $align         |= $this->_text_justlast << 7;
370
            $align         |= $this->_rotation      << 8;
371
            $align         |= $atr_num                << 10;
372
            $align         |= $atr_fnt                << 11;
373
            $align         |= $atr_alc                << 12;
374
            $align         |= $atr_bdr                << 13;
375
            $align         |= $atr_pat                << 14;
376
            $align         |= $atr_prot               << 15;
377
 
378
            $icv            = $this->_fg_color;       // fg and bg pattern colors
379
            $icv           |= $this->_bg_color      << 7;
380
 
381
            $fill           = $this->_pattern;        // Fill and border line style
382
            $fill          |= $this->_bottom        << 6;
383
            $fill          |= $this->_bottom_color  << 9;
384
 
385
            $border1        = $this->_top;            // Border line style and color
386
            $border1       |= $this->_left          << 3;
387
            $border1       |= $this->_right         << 6;
388
            $border1       |= $this->_top_color     << 9;
389
 
390
            $border2        = $this->_left_color;     // Border color
391
            $border2       |= $this->_right_color   << 7;
392
 
393
            $header      = pack("vv",       $record, $length);
394
            $data        = pack("vvvvvvvv", $ifnt, $ifmt, $style, $align,
395
                                            $icv, $fill,
396
                                            $border1, $border2);
397
        } elseif ($this->_BIFF_version == 0x0600) {
398
            $align          = $this->_text_h_align;       // Alignment
399
            $align         |= $this->_text_wrap     << 3;
400
            $align         |= $this->_text_v_align  << 4;
401
            $align         |= $this->_text_justlast << 7;
402
 
403
            $used_attrib    = $atr_num              << 2;
404
            $used_attrib   |= $atr_fnt              << 3;
405
            $used_attrib   |= $atr_alc              << 4;
406
            $used_attrib   |= $atr_bdr              << 5;
407
            $used_attrib   |= $atr_pat              << 6;
408
            $used_attrib   |= $atr_prot             << 7;
409
 
410
            $icv            = $this->_fg_color;      // fg and bg pattern colors
411
            $icv           |= $this->_bg_color      << 7;
412
 
413
            $border1        = $this->_left;          // Border line style and color
414
            $border1       |= $this->_right         << 4;
415
            $border1       |= $this->_top           << 8;
416
            $border1       |= $this->_bottom        << 12;
417
            $border1       |= $this->_left_color    << 16;
418
            $border1       |= $this->_right_color   << 23;
419
            $diag_tl_to_rb = 0; // FIXME: add method
420
            $diag_tr_to_lb = 0; // FIXME: add method
421
            $border1       |= $diag_tl_to_rb        << 30;
422
            $border1       |= $diag_tr_to_lb        << 31;
423
 
424
            $border2        = $this->_top_color;    // Border color
425
            $border2       |= $this->_bottom_color   << 7;
426
            $border2       |= $this->_diag_color     << 14;
427
            $border2       |= $this->_diag           << 21;
428
            $border2       |= $this->_pattern        << 26;
429
 
430
            $header      = pack("vv",       $record, $length);
431
 
432
            $rotation      = $this->_rotation;
433
            $biff8_options = 0x00;
434
            $data  = pack("vvvC", $ifnt, $ifmt, $style, $align);
435
            $data .= pack("CCC", $rotation, $biff8_options, $used_attrib);
436
            $data .= pack("VVv", $border1, $border2, $icv);
437
        }
438
 
439
        return($header . $data);
418 aurelien 440
    }
1604 raphael 441
 
418 aurelien 442
    /**
443
    * Generate an Excel BIFF FONT record.
444
    *
445
    * @return string The FONT record
446
    */
447
    function getFont()
448
    {
449
        $dyHeight   = $this->_size * 20;    // Height of font (1/20 of a point)
450
        $icv        = $this->_color;        // Index to color palette
451
        $bls        = $this->_bold;         // Bold style
452
        $sss        = $this->_font_script;  // Superscript/subscript
453
        $uls        = $this->_underline;    // Underline
454
        $bFamily    = $this->_font_family;  // Font family
455
        $bCharSet   = $this->_font_charset; // Character set
1604 raphael 456
        $encoding   = 0;                    // TODO: Unicode support
457
 
458
        $cch        = strlen($this->_font_name); // Length of font name
459
        $record     = 0x31;                      // Record identifier
460
        if ($this->_BIFF_version == 0x0500) {
461
            $length     = 0x0F + $cch;            // Record length
462
        } elseif ($this->_BIFF_version == 0x0600) {
463
            $length     = 0x10 + $cch;
464
        }
418 aurelien 465
        $reserved   = 0x00;                // Reserved
466
        $grbit      = 0x00;                // Font attributes
467
        if ($this->_italic) {
468
            $grbit     |= 0x02;
469
        }
470
        if ($this->_font_strikeout) {
471
            $grbit     |= 0x08;
472
        }
473
        if ($this->_font_outline) {
474
            $grbit     |= 0x10;
475
        }
476
        if ($this->_font_shadow) {
477
            $grbit     |= 0x20;
478
        }
1604 raphael 479
 
418 aurelien 480
        $header  = pack("vv",         $record, $length);
1604 raphael 481
        if ($this->_BIFF_version == 0x0500) {
482
            $data    = pack("vvvvvCCCCC", $dyHeight, $grbit, $icv, $bls,
483
                                          $sss, $uls, $bFamily,
484
                                          $bCharSet, $reserved, $cch);
485
        } elseif ($this->_BIFF_version == 0x0600) {
486
            $data    = pack("vvvvvCCCCCC", $dyHeight, $grbit, $icv, $bls,
487
                                           $sss, $uls, $bFamily,
488
                                           $bCharSet, $reserved, $cch, $encoding);
489
        }
490
        return($header . $data . $this->_font_name);
418 aurelien 491
    }
1604 raphael 492
 
418 aurelien 493
    /**
1604 raphael 494
    * Returns a unique hash key for a font.
418 aurelien 495
    * Used by Spreadsheet_Excel_Writer_Workbook::_storeAllFonts()
496
    *
497
    * The elements that form the key are arranged to increase the probability of
498
    * generating a unique key. Elements that hold a large range of numbers
499
    * (eg. _color) are placed between two binary elements such as _italic
500
    *
501
    * @return string A key for this font
502
    */
503
    function getFontKey()
504
    {
505
        $key  = "$this->_font_name$this->_size";
506
        $key .= "$this->_font_script$this->_underline";
507
        $key .= "$this->_font_strikeout$this->_bold$this->_font_outline";
508
        $key .= "$this->_font_family$this->_font_charset";
509
        $key .= "$this->_font_shadow$this->_color$this->_italic";
1604 raphael 510
        $key  = str_replace(' ', '_', $key);
418 aurelien 511
        return ($key);
512
    }
1604 raphael 513
 
418 aurelien 514
    /**
515
    * Returns the index used by Spreadsheet_Excel_Writer_Worksheet::_XF()
516
    *
517
    * @return integer The index for the XF record
518
    */
519
    function getXfIndex()
520
    {
521
        return($this->_xf_index);
522
    }
1604 raphael 523
 
418 aurelien 524
    /**
525
    * Used in conjunction with the set_xxx_color methods to convert a color
526
    * string into a number. Color range is 0..63 but we will restrict it
527
    * to 8..63 to comply with Gnumeric. Colors 0..7 are repeated in 8..15.
528
    *
529
    * @access private
530
    * @param string $name_color name of the color (i.e.: 'blue', 'red', etc..). Optional.
531
    * @return integer The color index
532
    */
533
    function _getColor($name_color = '')
534
    {
535
        $colors = array(
1604 raphael 536
                          'aqua'    => 0x07,
537
                          'cyan'    => 0x07,
538
                          'black'   => 0x00,
539
                          'blue'    => 0x04,
540
                          'brown'   => 0x10,
541
                          'magenta' => 0x06,
542
                          'fuchsia' => 0x06,
543
                          'gray'    => 0x17,
544
                          'grey'    => 0x17,
545
                          'green'   => 0x11,
546
                          'lime'    => 0x03,
547
                          'navy'    => 0x12,
548
                          'orange'  => 0x35,
549
                          'purple'  => 0x14,
550
                          'red'     => 0x02,
551
                          'silver'  => 0x16,
552
                          'white'   => 0x01,
553
                          'yellow'  => 0x05
418 aurelien 554
                       );
1604 raphael 555
 
418 aurelien 556
        // Return the default color, 0x7FFF, if undef,
1604 raphael 557
        if ($name_color === '') {
418 aurelien 558
            return(0x7FFF);
559
        }
1604 raphael 560
 
418 aurelien 561
        // or the color string converted to an integer,
1604 raphael 562
        if (isset($colors[$name_color])) {
418 aurelien 563
            return($colors[$name_color]);
564
        }
1604 raphael 565
 
418 aurelien 566
        // or the default color if string is unrecognised,
1604 raphael 567
        if (preg_match("/\D/",$name_color)) {
418 aurelien 568
            return(0x7FFF);
569
        }
1604 raphael 570
 
418 aurelien 571
        // or the default color if arg is outside range,
1604 raphael 572
        if ($name_color > 63) {
418 aurelien 573
            return(0x7FFF);
574
        }
1604 raphael 575
 
418 aurelien 576
        // or an integer in the valid range
577
        return($name_color);
578
    }
1604 raphael 579
 
418 aurelien 580
    /**
581
    * Set cell alignment.
582
    *
583
    * @access public
584
    * @param string $location alignment for the cell ('left', 'right', etc...).
585
    */
586
    function setAlign($location)
587
    {
588
        if (preg_match("/\d/",$location)) {
589
            return;                      // Ignore numbers
590
        }
1604 raphael 591
 
592
        $location = strtolower($location);
593
 
594
        if ($location == 'left') {
595
            $this->_text_h_align = 1;
596
        }
597
        if ($location == 'centre') {
598
            $this->_text_h_align = 2;
599
        }
600
        if ($location == 'center') {
601
            $this->_text_h_align = 2;
602
        }
603
        if ($location == 'right') {
604
            $this->_text_h_align = 3;
605
        }
606
        if ($location == 'fill') {
607
            $this->_text_h_align = 4;
608
        }
609
        if ($location == 'justify') {
610
            $this->_text_h_align = 5;
611
        }
612
        if ($location == 'merge') {
613
            $this->_text_h_align = 6;
614
        }
615
        if ($location == 'equal_space') { // For T.K.
616
            $this->_text_h_align = 7;
617
        }
618
        if ($location == 'top') {
619
            $this->_text_v_align = 0;
620
        }
621
        if ($location == 'vcentre') {
622
            $this->_text_v_align = 1;
623
        }
624
        if ($location == 'vcenter') {
625
            $this->_text_v_align = 1;
626
        }
627
        if ($location == 'bottom') {
628
            $this->_text_v_align = 2;
629
        }
630
        if ($location == 'vjustify') {
631
            $this->_text_v_align = 3;
632
        }
633
        if ($location == 'vequal_space') { // For T.K.
634
            $this->_text_v_align = 4;
635
        }
636
    }
637
 
638
    /**
639
    * Set cell horizontal alignment.
640
    *
641
    * @access public
642
    * @param string $location alignment for the cell ('left', 'right', etc...).
643
    */
644
    function setHAlign($location)
645
    {
646
        if (preg_match("/\d/",$location)) {
647
            return;                      // Ignore numbers
648
        }
418 aurelien 649
 
650
        $location = strtolower($location);
651
 
652
        if ($location == 'left') {
653
            $this->_text_h_align = 1;
1604 raphael 654
        }
418 aurelien 655
        if ($location == 'centre') {
656
            $this->_text_h_align = 2;
1604 raphael 657
        }
418 aurelien 658
        if ($location == 'center') {
659
            $this->_text_h_align = 2;
1604 raphael 660
        }
418 aurelien 661
        if ($location == 'right') {
662
            $this->_text_h_align = 3;
1604 raphael 663
        }
418 aurelien 664
        if ($location == 'fill') {
665
            $this->_text_h_align = 4;
1604 raphael 666
        }
418 aurelien 667
        if ($location == 'justify') {
668
            $this->_text_h_align = 5;
1604 raphael 669
        }
418 aurelien 670
        if ($location == 'merge') {
671
            $this->_text_h_align = 6;
1604 raphael 672
        }
418 aurelien 673
        if ($location == 'equal_space') { // For T.K.
674
            $this->_text_h_align = 7;
1604 raphael 675
        }
676
    }
677
 
678
    /**
679
    * Set cell vertical alignment.
680
    *
681
    * @access public
682
    * @param string $location alignment for the cell ('top', 'vleft', 'vright', etc...).
683
    */
684
    function setVAlign($location)
685
    {
686
        if (preg_match("/\d/",$location)) {
687
            return;                      // Ignore numbers
688
        }
689
 
690
        $location = strtolower($location);
691
 
418 aurelien 692
        if ($location == 'top') {
693
            $this->_text_v_align = 0;
1604 raphael 694
        }
418 aurelien 695
        if ($location == 'vcentre') {
696
            $this->_text_v_align = 1;
1604 raphael 697
        }
418 aurelien 698
        if ($location == 'vcenter') {
699
            $this->_text_v_align = 1;
1604 raphael 700
        }
418 aurelien 701
        if ($location == 'bottom') {
702
            $this->_text_v_align = 2;
1604 raphael 703
        }
418 aurelien 704
        if ($location == 'vjustify') {
705
            $this->_text_v_align = 3;
1604 raphael 706
        }
418 aurelien 707
        if ($location == 'vequal_space') { // For T.K.
708
            $this->_text_v_align = 4;
1604 raphael 709
        }
418 aurelien 710
    }
1604 raphael 711
 
418 aurelien 712
    /**
713
    * This is an alias for the unintuitive setAlign('merge')
714
    *
715
    * @access public
716
    */
717
    function setMerge()
718
    {
719
        $this->setAlign('merge');
720
    }
1604 raphael 721
 
418 aurelien 722
    /**
723
    * Sets the boldness of the text.
724
    * Bold has a range 100..1000.
725
    * 0 (400) is normal. 1 (700) is bold.
726
    *
727
    * @access public
728
    * @param integer $weight Weight for the text, 0 maps to 400 (normal text),
729
                             1 maps to 700 (bold text). Valid range is: 100-1000.
730
                             It's Optional, default is 1 (bold).
731
    */
732
    function setBold($weight = 1)
733
    {
1604 raphael 734
        if ($weight == 1) {
418 aurelien 735
            $weight = 0x2BC;  // Bold text
736
        }
1604 raphael 737
        if ($weight == 0) {
418 aurelien 738
            $weight = 0x190;  // Normal text
739
        }
1604 raphael 740
        if ($weight <  0x064) {
418 aurelien 741
            $weight = 0x190;  // Lower bound
742
        }
1604 raphael 743
        if ($weight >  0x3E8) {
418 aurelien 744
            $weight = 0x190;  // Upper bound
745
        }
746
        $this->_bold = $weight;
747
    }
1604 raphael 748
 
749
 
418 aurelien 750
    /************************************
751
    * FUNCTIONS FOR SETTING CELLS BORDERS
752
    */
1604 raphael 753
 
418 aurelien 754
    /**
755
    * Sets the width for the bottom border of the cell
756
    *
757
    * @access public
758
    * @param integer $style style of the cell border. 1 => thin, 2 => thick.
759
    */
760
    function setBottom($style)
761
    {
762
        $this->_bottom = $style;
763
    }
1604 raphael 764
 
418 aurelien 765
    /**
766
    * Sets the width for the top border of the cell
767
    *
768
    * @access public
769
    * @param integer $style style of the cell top border. 1 => thin, 2 => thick.
770
    */
771
    function setTop($style)
772
    {
773
        $this->_top = $style;
774
    }
1604 raphael 775
 
418 aurelien 776
    /**
777
    * Sets the width for the left border of the cell
778
    *
779
    * @access public
780
    * @param integer $style style of the cell left border. 1 => thin, 2 => thick.
781
    */
782
    function setLeft($style)
783
    {
784
        $this->_left = $style;
785
    }
1604 raphael 786
 
418 aurelien 787
    /**
788
    * Sets the width for the right border of the cell
789
    *
790
    * @access public
791
    * @param integer $style style of the cell right border. 1 => thin, 2 => thick.
792
    */
793
    function setRight($style)
794
    {
795
        $this->_right = $style;
796
    }
1604 raphael 797
 
798
 
418 aurelien 799
    /**
800
    * Set cells borders to the same style
801
    *
802
    * @access public
803
    * @param integer $style style to apply for all cell borders. 1 => thin, 2 => thick.
804
    */
805
    function setBorder($style)
806
    {
807
        $this->setBottom($style);
808
        $this->setTop($style);
809
        $this->setLeft($style);
810
        $this->setRight($style);
811
    }
1604 raphael 812
 
813
 
418 aurelien 814
    /*******************************************
815
    * FUNCTIONS FOR SETTING CELLS BORDERS COLORS
816
    */
1604 raphael 817
 
418 aurelien 818
    /**
819
    * Sets all the cell's borders to the same color
820
    *
821
    * @access public
1604 raphael 822
    * @param mixed $color The color we are setting. Either a string (like 'blue'),
418 aurelien 823
    *                     or an integer (range is [8...63]).
824
    */
825
    function setBorderColor($color)
826
    {
827
        $this->setBottomColor($color);
828
        $this->setTopColor($color);
829
        $this->setLeftColor($color);
830
        $this->setRightColor($color);
831
    }
1604 raphael 832
 
418 aurelien 833
    /**
834
    * Sets the cell's bottom border color
835
    *
836
    * @access public
837
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
838
    */
839
    function setBottomColor($color)
840
    {
841
        $value = $this->_getColor($color);
842
        $this->_bottom_color = $value;
843
    }
1604 raphael 844
 
418 aurelien 845
    /**
846
    * Sets the cell's top border color
847
    *
848
    * @access public
849
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
850
    */
851
    function setTopColor($color)
852
    {
853
        $value = $this->_getColor($color);
854
        $this->_top_color = $value;
855
    }
1604 raphael 856
 
418 aurelien 857
    /**
858
    * Sets the cell's left border color
859
    *
860
    * @access public
861
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
862
    */
863
    function setLeftColor($color)
864
    {
865
        $value = $this->_getColor($color);
866
        $this->_left_color = $value;
867
    }
1604 raphael 868
 
418 aurelien 869
    /**
870
    * Sets the cell's right border color
871
    *
872
    * @access public
873
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
874
    */
875
    function setRightColor($color)
876
    {
877
        $value = $this->_getColor($color);
878
        $this->_right_color = $value;
879
    }
1604 raphael 880
 
881
 
418 aurelien 882
    /**
883
    * Sets the cell's foreground color
884
    *
885
    * @access public
886
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
887
    */
888
    function setFgColor($color)
889
    {
890
        $value = $this->_getColor($color);
891
        $this->_fg_color = $value;
1604 raphael 892
        if ($this->_pattern == 0) { // force color to be seen
893
            $this->_pattern = 1;
894
        }
418 aurelien 895
    }
1604 raphael 896
 
418 aurelien 897
    /**
898
    * Sets the cell's background color
899
    *
900
    * @access public
901
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
902
    */
903
    function setBgColor($color)
904
    {
905
        $value = $this->_getColor($color);
906
        $this->_bg_color = $value;
1604 raphael 907
        if ($this->_pattern == 0) { // force color to be seen
908
            $this->_pattern = 1;
909
        }
418 aurelien 910
    }
1604 raphael 911
 
418 aurelien 912
    /**
913
    * Sets the cell's color
914
    *
915
    * @access public
916
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
917
    */
918
    function setColor($color)
919
    {
920
        $value = $this->_getColor($color);
921
        $this->_color = $value;
922
    }
1604 raphael 923
 
418 aurelien 924
    /**
925
    * Sets the fill pattern attribute of a cell
926
    *
927
    * @access public
928
    * @param integer $arg Optional. Defaults to 1. Meaningful values are: 0-18,
929
    *                     0 meaning no background.
930
    */
931
    function setPattern($arg = 1)
932
    {
933
        $this->_pattern = $arg;
934
    }
1604 raphael 935
 
418 aurelien 936
    /**
937
    * Sets the underline of the text
938
    *
939
    * @access public
940
    * @param integer $underline The value for underline. Possible values are:
941
    *                          1 => underline, 2 => double underline.
942
    */
943
    function setUnderline($underline)
944
    {
945
        $this->_underline = $underline;
946
    }
1604 raphael 947
 
418 aurelien 948
    /**
949
    * Sets the font style as italic
950
    *
951
    * @access public
952
    */
953
    function setItalic()
954
    {
955
        $this->_italic = 1;
956
    }
957
 
958
    /**
1604 raphael 959
    * Sets the font size
418 aurelien 960
    *
961
    * @access public
962
    * @param integer $size The font size (in pixels I think).
963
    */
964
    function setSize($size)
965
    {
966
        $this->_size = $size;
967
    }
1604 raphael 968
 
418 aurelien 969
    /**
970
    * Sets text wrapping
971
    *
972
    * @access public
973
    */
974
    function setTextWrap()
975
    {
976
        $this->_text_wrap = 1;
977
    }
978
 
979
    /**
980
    * Sets the orientation of the text
981
    *
982
    * @access public
983
    * @param integer $angle The rotation angle for the text (clockwise). Possible
984
                            values are: 0, 90, 270 and -1 for stacking top-to-bottom.
985
    */
986
    function setTextRotation($angle)
987
    {
988
        switch ($angle)
989
        {
990
            case 0:
991
                $this->_rotation = 0;
992
                break;
993
            case 90:
1604 raphael 994
                if ($this->_BIFF_version == 0x0500) {
418 aurelien 995
                $this->_rotation = 3;
1604 raphael 996
                } elseif ($this->_BIFF_version == 0x0600) {
997
                    $this->_rotation = 180;
998
                }
418 aurelien 999
                break;
1000
            case 270:
1604 raphael 1001
                if ($this->_BIFF_version == 0x0500) {
418 aurelien 1002
                $this->_rotation = 2;
1604 raphael 1003
                } elseif ($this->_BIFF_version == 0x0600) {
1004
                    $this->_rotation = 90;
1005
                }
418 aurelien 1006
                break;
1007
            case -1:
1604 raphael 1008
                if ($this->_BIFF_version == 0x0500) {
418 aurelien 1009
                $this->_rotation = 1;
1604 raphael 1010
                } elseif ($this->_BIFF_version == 0x0600) {
1011
                    $this->_rotation = 255;
1012
                }
418 aurelien 1013
                break;
1014
            default :
1604 raphael 1015
                return $this->raiseError("Invalid value for angle.".
418 aurelien 1016
                                  " Possible values are: 0, 90, 270 and -1 ".
1017
                                  "for stacking top-to-bottom.");
1018
                $this->_rotation = 0;
1019
                break;
1020
        }
1021
    }
1022
 
1023
    /**
1024
    * Sets the numeric format.
1025
    * It can be date, time, currency, etc...
1026
    *
1027
    * @access public
1028
    * @param integer $num_format The numeric format.
1029
    */
1030
    function setNumFormat($num_format)
1031
    {
1032
        $this->_num_format = $num_format;
1033
    }
1034
 
1035
    /**
1036
    * Sets font as strikeout.
1037
    *
1038
    * @access public
1039
    */
1040
    function setStrikeOut()
1041
    {
1042
        $this->_font_strikeout = 1;
1043
    }
1044
 
1045
    /**
1046
    * Sets outlining for a font.
1047
    *
1048
    * @access public
1049
    */
1050
    function setOutLine()
1051
    {
1052
        $this->_font_outline = 1;
1053
    }
1054
 
1055
    /**
1056
    * Sets font as shadow.
1057
    *
1058
    * @access public
1059
    */
1060
    function setShadow()
1061
    {
1062
        $this->_font_shadow = 1;
1063
    }
1064
 
1065
    /**
1066
    * Sets the script type of the text
1067
    *
1068
    * @access public
1069
    * @param integer $script The value for script type. Possible values are:
1070
    *                        1 => superscript, 2 => subscript.
1071
    */
1072
    function setScript($script)
1073
    {
1074
        $this->_font_script = $script;
1075
    }
1076
 
1604 raphael 1077
     /**
1078
     * Locks a cell.
1079
     *
1080
     * @access public
1081
     */
1082
     function setLocked()
1083
     {
1084
         $this->_locked = 1;
1085
     }
1086
 
418 aurelien 1087
    /**
1088
    * Unlocks a cell. Useful for unprotecting particular cells of a protected sheet.
1089
    *
1090
    * @access public
1091
    */
1092
    function setUnLocked()
1093
    {
1094
        $this->_locked = 0;
1095
    }
1604 raphael 1096
 
1097
    /**
1098
    * Sets the font family name.
1099
    *
1100
    * @access public
1101
    * @param string $fontfamily The font family name. Possible values are:
1102
    *                           'Times New Roman', 'Arial', 'Courier'.
1103
    */
1104
    function setFontFamily($font_family)
1105
    {
1106
        $this->_font_name = $font_family;
1107
    }
418 aurelien 1108
}
1109
?>