Subversion Repositories eFlore/Applications.cel

Rev

Rev 970 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 970 Rev 1604
Line 3... Line 3...
3
*  Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
3
*  Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
4
*
4
*
5
*  The majority of this is _NOT_ my code.  I simply ported it from the
5
*  The majority of this is _NOT_ my code.  I simply ported it from the
6
*  PERL Spreadsheet::WriteExcel module.
6
*  PERL Spreadsheet::WriteExcel module.
7
*
7
*
8
*  The author of the Spreadsheet::WriteExcel module is John McNamara 
8
*  The author of the Spreadsheet::WriteExcel module is John McNamara
9
*  <jmcnamara@cpan.org>
9
*  <jmcnamara@cpan.org>
10
*
10
*
11
*  I _DO_ maintain this code, and John McNamara has nothing to do with the
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
12
*  porting of this code to PHP.  Any questions directly related to this
13
*  class library should be directed to me.
13
*  class library should be directed to me.
Line 30... Line 30...
30
*    You should have received a copy of the GNU Lesser General Public
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
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
32
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
*/
33
*/
Line 34... Line 34...
34
 
34
 
Line 35... Line 35...
35
//require_once('PEAR.php');
35
require_once 'PEAR.php';
36
 
36
 
37
/**
37
/**
38
* Class for generating Excel XF records (formats)
38
* Class for generating Excel XF records (formats)
Line 243... Line 243...
243
    var $_right_color;
243
    var $_right_color;
Line 244... Line 244...
244
 
244
 
245
    /**
245
    /**
246
    * Constructor
246
    * Constructor
247
    *
247
    *
248
    * @access public
248
    * @access private
249
    * @param integer $index the XF index for the format.
249
    * @param integer $index the XF index for the format.
250
    * @param array   $properties array with properties to be set on initialization.
250
    * @param array   $properties array with properties to be set on initialization.
251
    */
251
    */
252
    function Spreadsheet_Excel_Writer_Format($index = 0,$properties =  array())
252
    function Spreadsheet_Excel_Writer_Format($BIFF_version, $index = 0, $properties =  array())
253
    {
253
    {
254
        $this->_xf_index       = $index;
-
 
-
 
254
        $this->_xf_index       = $index;
255
                               
255
        $this->_BIFF_version   = $BIFF_version;
256
        $this->font_index      = 0;
256
        $this->font_index      = 0;
257
        $this->_font_name      = 'Arial';
257
        $this->_font_name      = 'Arial';
258
        $this->_size           = 10;
258
        $this->_size           = 10;
259
        $this->_bold           = 0x0190;
259
        $this->_bold           = 0x0190;
Line 264... Line 264...
264
        $this->_font_outline   = 0;
264
        $this->_font_outline   = 0;
265
        $this->_font_shadow    = 0;
265
        $this->_font_shadow    = 0;
266
        $this->_font_script    = 0;
266
        $this->_font_script    = 0;
267
        $this->_font_family    = 0;
267
        $this->_font_family    = 0;
268
        $this->_font_charset   = 0;
268
        $this->_font_charset   = 0;
269
                               
269
 
270
        $this->_num_format     = 0;
270
        $this->_num_format     = 0;
271
                               
271
 
272
        $this->_hidden         = 0;
272
        $this->_hidden         = 0;
273
        $this->_locked         = 1;
273
        $this->_locked         = 0;
Line 274... Line 274...
274
 
274
 
275
        $this->_text_h_align   = 0;
275
        $this->_text_h_align   = 0;
276
        $this->_text_wrap      = 0;
276
        $this->_text_wrap      = 0;
277
        $this->_text_v_align   = 2;
277
        $this->_text_v_align   = 2;
Line 280... Line 280...
280
 
280
 
281
        $this->_fg_color       = 0x40;
281
        $this->_fg_color       = 0x40;
Line 282... Line 282...
282
        $this->_bg_color       = 0x41;
282
        $this->_bg_color       = 0x41;
283
 
283
 
284
        $this->_pattern        = 0;
284
        $this->_pattern        = 0;
285
                               
285
 
286
        $this->_bottom         = 0;
286
        $this->_bottom         = 0;
287
        $this->_top            = 0;
287
        $this->_top            = 0;
-
 
288
        $this->_left           = 0;
288
        $this->_left           = 0;
289
        $this->_right          = 0;
289
        $this->_right          = 0;
290
        $this->_diag           = 0;
290
                               
291
 
291
        $this->_bottom_color   = 0x40;
292
        $this->_bottom_color   = 0x40;
292
        $this->_top_color      = 0x40;
293
        $this->_top_color      = 0x40;
-
 
294
        $this->_left_color     = 0x40;
293
        $this->_left_color     = 0x40;
295
        $this->_right_color    = 0x40;
294
        $this->_right_color    = 0x40;
296
        $this->_diag_color     = 0x40;
295
    
297
 
296
        // Set properties passed to Spreadsheet_Excel_Writer_Workbook::addFormat()
298
        // Set properties passed to Spreadsheet_Excel_Writer_Workbook::addFormat()
297
        foreach($properties as $property => $value)
299
        foreach ($properties as $property => $value)
298
        {
-
 
299
            if(method_exists($this,'set'.ucwords($property)))
300
        {
300
            {
301
            if (method_exists($this, 'set'.ucwords($property))) {
301
                $method_name = 'set'.ucwords($property);
302
                $method_name = 'set'.ucwords($property);
302
                $this->$method_name($value);
303
                $this->$method_name($value);
303
            }
304
            }
Line 312... Line 313...
312
    * @return string The XF record
313
    * @return string The XF record
313
    */
314
    */
314
    function getXf($style)
315
    function getXf($style)
315
    {
316
    {
316
        // Set the type of the XF record and some of the attributes.
317
        // Set the type of the XF record and some of the attributes.
317
        if ($style == "style") {
318
        if ($style == 'style') {
318
            $style = 0xFFF5;
319
            $style = 0xFFF5;
319
        }
-
 
320
        else {
320
        } else {
321
            $style   = $this->_locked;
321
            $style   = $this->_locked;
322
            $style  |= $this->_hidden << 1;
322
            $style  |= $this->_hidden << 1;
323
        }
323
        }
324
    
324
 
325
        // Flags to indicate if attributes have been set.
325
        // Flags to indicate if attributes have been set.
326
        $atr_num     = ($this->_num_format != 0)?1:0;
326
        $atr_num     = ($this->_num_format != 0)?1:0;
327
        $atr_fnt     = ($this->font_index != 0)?1:0;
327
        $atr_fnt     = ($this->font_index != 0)?1:0;
328
        $atr_alc     = ($this->_text_wrap)?1:0;
328
        $atr_alc     = ($this->_text_wrap)?1:0;
329
        $atr_bdr     = ($this->_bottom   ||
329
        $atr_bdr     = ($this->_bottom   ||
Line 331... Line 331...
331
                        $this->_left     ||
331
                        $this->_left     ||
332
                        $this->_right)?1:0;
332
                        $this->_right)?1:0;
333
        $atr_pat     = (($this->_fg_color != 0x40) ||
333
        $atr_pat     = (($this->_fg_color != 0x40) ||
334
                        ($this->_bg_color != 0x41) ||
334
                        ($this->_bg_color != 0x41) ||
335
                        $this->_pattern)?1:0;
335
                        $this->_pattern)?1:0;
336
        $atr_prot    = 0;
336
        $atr_prot    = $this->_locked | $this->_hidden;
337
    
337
 
338
        // Zero the default border colour if the border has not been set.
338
        // Zero the default border colour if the border has not been set.
339
        if ($this->_bottom == 0) {
339
        if ($this->_bottom == 0) {
340
            $this->_bottom_color = 0;
340
            $this->_bottom_color = 0;
341
            }
341
        }
342
        if ($this->_top  == 0) {
342
        if ($this->_top  == 0) {
343
            $this->_top_color = 0;
343
            $this->_top_color = 0;
344
            }
344
        }
345
        if ($this->_right == 0) {
345
        if ($this->_right == 0) {
346
            $this->_right_color = 0;
346
            $this->_right_color = 0;
347
            }
347
        }
348
        if ($this->_left == 0) {
348
        if ($this->_left == 0) {
349
            $this->_left_color = 0;
349
            $this->_left_color = 0;
350
            }
350
        }
-
 
351
        if ($this->_diag == 0) {
-
 
352
            $this->_diag_color = 0;
-
 
353
        }
351
    
354
 
352
        $record         = 0x00E0;              // Record identifier
355
        $record         = 0x00E0;              // Record identifier
-
 
356
        if ($this->_BIFF_version == 0x0500) {
353
        $length         = 0x0010;              // Number of bytes to follow
357
            $length         = 0x0010;              // Number of bytes to follow
-
 
358
        }
-
 
359
        if ($this->_BIFF_version == 0x0600) {
-
 
360
            $length         = 0x0014;
-
 
361
        }
354
                                               
362
 
355
        $ifnt           = $this->font_index;   // Index to FONT record
363
        $ifnt           = $this->font_index;   // Index to FONT record
356
        $ifmt           = $this->_num_format;  // Index to FORMAT record
364
        $ifmt           = $this->_num_format;  // Index to FORMAT record
357
    
-
 
-
 
365
        if ($this->_BIFF_version == 0x0500) {
358
        $align          = $this->_text_h_align;       // Alignment
366
            $align          = $this->_text_h_align;       // Alignment
359
        $align         |= $this->_text_wrap     << 3;
367
            $align         |= $this->_text_wrap     << 3;
360
        $align         |= $this->_text_v_align  << 4;
368
            $align         |= $this->_text_v_align  << 4;
361
        $align         |= $this->_text_justlast << 7;
369
            $align         |= $this->_text_justlast << 7;
362
        $align         |= $this->_rotation      << 8;
370
            $align         |= $this->_rotation      << 8;
363
        $align         |= $atr_num                << 10;
371
            $align         |= $atr_num                << 10;
364
        $align         |= $atr_fnt                << 11;
372
            $align         |= $atr_fnt                << 11;
365
        $align         |= $atr_alc                << 12;
373
            $align         |= $atr_alc                << 12;
366
        $align         |= $atr_bdr                << 13;
374
            $align         |= $atr_bdr                << 13;
367
        $align         |= $atr_pat                << 14;
375
            $align         |= $atr_pat                << 14;
368
        $align         |= $atr_prot               << 15;
376
            $align         |= $atr_prot               << 15;
369
    
377
 
370
        $icv            = $this->_fg_color;           // fg and bg pattern colors
378
            $icv            = $this->_fg_color;       // fg and bg pattern colors
371
        $icv           |= $this->_bg_color      << 7;
379
            $icv           |= $this->_bg_color      << 7;
372
    
380
 
373
        $fill           = $this->_pattern;            // Fill and border line style
381
            $fill           = $this->_pattern;        // Fill and border line style
374
        $fill          |= $this->_bottom        << 6;
382
            $fill          |= $this->_bottom        << 6;
375
        $fill          |= $this->_bottom_color  << 9;
383
            $fill          |= $this->_bottom_color  << 9;
376
    
384
 
377
        $border1        = $this->_top;                // Border line style and color
385
            $border1        = $this->_top;            // Border line style and color
378
        $border1       |= $this->_left          << 3;
386
            $border1       |= $this->_left          << 3;
379
        $border1       |= $this->_right         << 6;
387
            $border1       |= $this->_right         << 6;
380
        $border1       |= $this->_top_color     << 9;
388
            $border1       |= $this->_top_color     << 9;
381
    
389
 
382
        $border2        = $this->_left_color;         // Border color
390
            $border2        = $this->_left_color;     // Border color
383
        $border2       |= $this->_right_color   << 7;
391
            $border2       |= $this->_right_color   << 7;
384
    
392
 
385
        $header      = pack("vv",       $record, $length);
393
            $header      = pack("vv",       $record, $length);
386
        $data        = pack("vvvvvvvv", $ifnt, $ifmt, $style, $align,
394
            $data        = pack("vvvvvvvv", $ifnt, $ifmt, $style, $align,
387
                                        $icv, $fill,
395
                                            $icv, $fill,
388
                                        $border1, $border2);
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
 
389
        return($header.$data);
439
        return($header . $data);
390
    }
440
    }
391
    
441
 
392
    /**
442
    /**
393
    * Generate an Excel BIFF FONT record.
443
    * Generate an Excel BIFF FONT record.
394
    *
444
    *
395
    * @return string The FONT record
445
    * @return string The FONT record
396
    */
446
    */
Line 401... Line 451...
401
        $bls        = $this->_bold;         // Bold style
451
        $bls        = $this->_bold;         // Bold style
402
        $sss        = $this->_font_script;  // Superscript/subscript
452
        $sss        = $this->_font_script;  // Superscript/subscript
403
        $uls        = $this->_underline;    // Underline
453
        $uls        = $this->_underline;    // Underline
404
        $bFamily    = $this->_font_family;  // Font family
454
        $bFamily    = $this->_font_family;  // Font family
405
        $bCharSet   = $this->_font_charset; // Character set
455
        $bCharSet   = $this->_font_charset; // Character set
406
        $rgch       = $this->_font_name;    // Font name
456
        $encoding   = 0;                    // TODO: Unicode support
407
    
457
 
408
        $cch        = strlen($rgch);       // Length of font name
458
        $cch        = strlen($this->_font_name); // Length of font name
409
        $record     = 0x31;                // Record identifier
459
        $record     = 0x31;                      // Record identifier
-
 
460
        if ($this->_BIFF_version == 0x0500) {
410
        $length     = 0x0F + $cch;         // Record length
461
            $length     = 0x0F + $cch;            // Record length
-
 
462
        } elseif ($this->_BIFF_version == 0x0600) {
-
 
463
            $length     = 0x10 + $cch;
-
 
464
        }
411
        $reserved   = 0x00;                // Reserved
465
        $reserved   = 0x00;                // Reserved
412
        $grbit      = 0x00;                // Font attributes
466
        $grbit      = 0x00;                // Font attributes
413
        if ($this->_italic) {
467
        if ($this->_italic) {
414
            $grbit     |= 0x02;
468
            $grbit     |= 0x02;
415
        }
469
        }
Line 420... Line 474...
420
            $grbit     |= 0x10;
474
            $grbit     |= 0x10;
421
        }
475
        }
422
        if ($this->_font_shadow) {
476
        if ($this->_font_shadow) {
423
            $grbit     |= 0x20;
477
            $grbit     |= 0x20;
424
        }
478
        }
425
    
479
 
426
        $header  = pack("vv",         $record, $length);
480
        $header  = pack("vv",         $record, $length);
-
 
481
        if ($this->_BIFF_version == 0x0500) {
427
        $data    = pack("vvvvvCCCCC", $dyHeight, $grbit, $icv, $bls,
482
            $data    = pack("vvvvvCCCCC", $dyHeight, $grbit, $icv, $bls,
428
                                      $sss, $uls, $bFamily,
483
                                          $sss, $uls, $bFamily,
429
                                      $bCharSet, $reserved, $cch);
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
        }
430
        return($header . $data. $this->_font_name);
490
        return($header . $data . $this->_font_name);
431
    }
491
    }
432
    
492
 
433
    /**
493
    /**
434
    * Returns a unique hash key for a font. 
494
    * Returns a unique hash key for a font.
435
    * Used by Spreadsheet_Excel_Writer_Workbook::_storeAllFonts()
495
    * Used by Spreadsheet_Excel_Writer_Workbook::_storeAllFonts()
436
    *
496
    *
437
    * The elements that form the key are arranged to increase the probability of
497
    * The elements that form the key are arranged to increase the probability of
438
    * generating a unique key. Elements that hold a large range of numbers
498
    * generating a unique key. Elements that hold a large range of numbers
439
    * (eg. _color) are placed between two binary elements such as _italic
499
    * (eg. _color) are placed between two binary elements such as _italic
Line 445... Line 505...
445
        $key  = "$this->_font_name$this->_size";
505
        $key  = "$this->_font_name$this->_size";
446
        $key .= "$this->_font_script$this->_underline";
506
        $key .= "$this->_font_script$this->_underline";
447
        $key .= "$this->_font_strikeout$this->_bold$this->_font_outline";
507
        $key .= "$this->_font_strikeout$this->_bold$this->_font_outline";
448
        $key .= "$this->_font_family$this->_font_charset";
508
        $key .= "$this->_font_family$this->_font_charset";
449
        $key .= "$this->_font_shadow$this->_color$this->_italic";
509
        $key .= "$this->_font_shadow$this->_color$this->_italic";
450
        $key  = str_replace(" ","_",$key);
510
        $key  = str_replace(' ', '_', $key);
451
        return ($key);
511
        return ($key);
452
    }
512
    }
453
    
513
 
454
    /**
514
    /**
455
    * Returns the index used by Spreadsheet_Excel_Writer_Worksheet::_XF()
515
    * Returns the index used by Spreadsheet_Excel_Writer_Worksheet::_XF()
456
    *
516
    *
457
    * @return integer The index for the XF record
517
    * @return integer The index for the XF record
458
    */
518
    */
459
    function getXfIndex()
519
    function getXfIndex()
460
    {
520
    {
461
        return($this->_xf_index);
521
        return($this->_xf_index);
462
    }
522
    }
463
    
523
 
464
    /**
524
    /**
465
    * Used in conjunction with the set_xxx_color methods to convert a color
525
    * Used in conjunction with the set_xxx_color methods to convert a color
466
    * string into a number. Color range is 0..63 but we will restrict it
526
    * string into a number. Color range is 0..63 but we will restrict it
467
    * to 8..63 to comply with Gnumeric. Colors 0..7 are repeated in 8..15.
527
    * to 8..63 to comply with Gnumeric. Colors 0..7 are repeated in 8..15.
468
    *
528
    *
Line 471... Line 531...
471
    * @return integer The color index
531
    * @return integer The color index
472
    */
532
    */
473
    function _getColor($name_color = '')
533
    function _getColor($name_color = '')
474
    {
534
    {
475
        $colors = array(
535
        $colors = array(
476
                        'aqua'    => 0x0F,
536
                          'aqua'    => 0x07,
477
                        'cyan'    => 0x0F,
537
                          'cyan'    => 0x07,
478
                        'black'   => 0x08,
538
                          'black'   => 0x00,
479
                        'blue'    => 0x0C,
539
                          'blue'    => 0x04,
480
                        'brown'   => 0x10,
540
                          'brown'   => 0x10,
481
                        'magenta' => 0x0E,
541
                          'magenta' => 0x06,
482
                        'fuchsia' => 0x0E,
542
                          'fuchsia' => 0x06,
483
                        'gray'    => 0x17,
543
                          'gray'    => 0x17,
484
                        'grey'    => 0x17,
544
                          'grey'    => 0x17,
485
                        'green'   => 0x11,
545
                          'green'   => 0x11,
486
                        'lime'    => 0x0B,
546
                          'lime'    => 0x03,
487
                        'navy'    => 0x12,
547
                          'navy'    => 0x12,
488
                        'orange'  => 0x35,
548
                          'orange'  => 0x35,
489
                        'purple'  => 0x14,
549
                          'purple'  => 0x14,
490
                        'red'     => 0x0A,
550
                          'red'     => 0x02,
491
                        'silver'  => 0x16,
551
                          'silver'  => 0x16,
492
                        'white'   => 0x09,
552
                          'white'   => 0x01,
493
                        'yellow'  => 0x0D
553
                          'yellow'  => 0x05
494
                       );
554
                       );
495
    
555
 
496
        // Return the default color, 0x7FFF, if undef,
556
        // Return the default color, 0x7FFF, if undef,
497
        if($name_color == '') {
557
        if ($name_color === '') {
498
            return(0x7FFF);
558
            return(0x7FFF);
499
        }
559
        }
500
    
560
 
501
        // or the color string converted to an integer,
561
        // or the color string converted to an integer,
502
        if(isset($colors[$name_color])) {
562
        if (isset($colors[$name_color])) {
503
            return($colors[$name_color]);
563
            return($colors[$name_color]);
504
        }
564
        }
505
    
565
 
506
        // or the default color if string is unrecognised,
566
        // or the default color if string is unrecognised,
507
        if(preg_match("/\D/",$name_color)) {
567
        if (preg_match("/\D/",$name_color)) {
508
            return(0x7FFF);
568
            return(0x7FFF);
509
        }
569
        }
510
    
570
 
511
        // or an index < 8 mapped into the correct range,
-
 
512
        if($name_color < 8) {
-
 
513
            return($name_color + 8);
-
 
514
        }
-
 
515
    
-
 
516
        // or the default color if arg is outside range,
571
        // or the default color if arg is outside range,
517
        if($name_color > 63) {
572
        if ($name_color > 63) {
518
            return(0x7FFF);
573
            return(0x7FFF);
519
        }
574
        }
520
    
575
 
521
        // or an integer in the valid range
576
        // or an integer in the valid range
522
        return($name_color);
577
        return($name_color);
523
    }
578
    }
524
    
579
 
525
    /**
580
    /**
526
    * Set cell alignment.
581
    * Set cell alignment.
527
    *
582
    *
528
    * @access public
583
    * @access public
529
    * @param string $location alignment for the cell ('left', 'right', etc...).
584
    * @param string $location alignment for the cell ('left', 'right', etc...).
Line 531... Line 586...
531
    function setAlign($location)
586
    function setAlign($location)
532
    {
587
    {
533
        if (preg_match("/\d/",$location)) {
588
        if (preg_match("/\d/",$location)) {
534
            return;                      // Ignore numbers
589
            return;                      // Ignore numbers
535
        }
590
        }
-
 
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
        }
Line 536... Line 649...
536
    
649
    
Line 537... Line 650...
537
        $location = strtolower($location);
650
        $location = strtolower($location);
538
    
651
    
539
        if ($location == 'left') {
652
        if ($location == 'left') {
540
            $this->_text_h_align = 1;
653
            $this->_text_h_align = 1;
541
            }
654
        }
542
        if ($location == 'centre') {
655
        if ($location == 'centre') {
543
            $this->_text_h_align = 2;
656
            $this->_text_h_align = 2;
544
            }
657
        }
545
        if ($location == 'center') {
658
        if ($location == 'center') {
546
            $this->_text_h_align = 2;
659
            $this->_text_h_align = 2;
547
            }
660
        }
548
        if ($location == 'right') {
661
        if ($location == 'right') {
549
            $this->_text_h_align = 3;
662
            $this->_text_h_align = 3;
550
            }
663
        }
551
        if ($location == 'fill') {
664
        if ($location == 'fill') {
552
            $this->_text_h_align = 4;
665
            $this->_text_h_align = 4;
553
            }
666
        }
554
        if ($location == 'justify') {
667
        if ($location == 'justify') {
555
            $this->_text_h_align = 5;
668
            $this->_text_h_align = 5;
556
            }
669
        }
557
        if ($location == 'merge') {
670
        if ($location == 'merge') {
558
            $this->_text_h_align = 6;
671
            $this->_text_h_align = 6;
559
            }
672
        }
560
        if ($location == 'equal_space') { // For T.K.
673
        if ($location == 'equal_space') { // For T.K.
-
 
674
            $this->_text_h_align = 7;
-
 
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
    
561
            $this->_text_h_align = 7;
690
        $location = strtolower($location);
562
            }
691
 
563
        if ($location == 'top') {
692
        if ($location == 'top') {
564
            $this->_text_v_align = 0;
693
            $this->_text_v_align = 0;
565
            }
694
        }
566
        if ($location == 'vcentre') {
695
        if ($location == 'vcentre') {
567
            $this->_text_v_align = 1;
696
            $this->_text_v_align = 1;
568
            }
697
        }
569
        if ($location == 'vcenter') {
698
        if ($location == 'vcenter') {
570
            $this->_text_v_align = 1;
699
            $this->_text_v_align = 1;
571
            }
700
        }
572
        if ($location == 'bottom') {
701
        if ($location == 'bottom') {
573
            $this->_text_v_align = 2;
702
            $this->_text_v_align = 2;
574
            }
703
        }
575
        if ($location == 'vjustify') {
704
        if ($location == 'vjustify') {
576
            $this->_text_v_align = 3;
705
            $this->_text_v_align = 3;
577
            }
706
        }
578
        if ($location == 'vequal_space') { // For T.K.
707
        if ($location == 'vequal_space') { // For T.K.
579
            $this->_text_v_align = 4;
708
            $this->_text_v_align = 4;
580
            }
709
        }
581
    }
710
    }
582
    
711
 
583
    /**
712
    /**
584
    * This is an alias for the unintuitive setAlign('merge')
713
    * This is an alias for the unintuitive setAlign('merge')
585
    *
714
    *
586
    * @access public
715
    * @access public
587
    */
716
    */
588
    function setMerge()
717
    function setMerge()
589
    {
718
    {
590
        $this->setAlign('merge');
719
        $this->setAlign('merge');
591
    }
720
    }
592
    
721
 
593
    /**
722
    /**
594
    * Sets the boldness of the text.
723
    * Sets the boldness of the text.
595
    * Bold has a range 100..1000.
724
    * Bold has a range 100..1000.
Line 600... Line 729...
600
                             1 maps to 700 (bold text). Valid range is: 100-1000.
729
                             1 maps to 700 (bold text). Valid range is: 100-1000.
601
                             It's Optional, default is 1 (bold).
730
                             It's Optional, default is 1 (bold).
602
    */
731
    */
603
    function setBold($weight = 1)
732
    function setBold($weight = 1)
604
    {
733
    {
605
        if($weight == 1) {
734
        if ($weight == 1) {
606
            $weight = 0x2BC;  // Bold text
735
            $weight = 0x2BC;  // Bold text
607
        }
736
        }
608
        if($weight == 0) {
737
        if ($weight == 0) {
609
            $weight = 0x190;  // Normal text
738
            $weight = 0x190;  // Normal text
610
        }
739
        }
611
        if($weight <  0x064) {
740
        if ($weight <  0x064) {
612
            $weight = 0x190;  // Lower bound
741
            $weight = 0x190;  // Lower bound
613
        }
742
        }
614
        if($weight >  0x3E8) {
743
        if ($weight >  0x3E8) {
615
            $weight = 0x190;  // Upper bound
744
            $weight = 0x190;  // Upper bound
616
        }
745
        }
617
        $this->_bold = $weight;
746
        $this->_bold = $weight;
618
    }
747
    }
619
    
748
 
620
    
749
 
621
    /************************************
750
    /************************************
622
    * FUNCTIONS FOR SETTING CELLS BORDERS
751
    * FUNCTIONS FOR SETTING CELLS BORDERS
623
    */
752
    */
624
    
753
 
625
    /**
754
    /**
626
    * Sets the width for the bottom border of the cell
755
    * Sets the width for the bottom border of the cell
627
    *
756
    *
628
    * @access public
757
    * @access public
629
    * @param integer $style style of the cell border. 1 => thin, 2 => thick.
758
    * @param integer $style style of the cell border. 1 => thin, 2 => thick.
630
    */
759
    */
631
    function setBottom($style)
760
    function setBottom($style)
632
    {
761
    {
633
        $this->_bottom = $style;
762
        $this->_bottom = $style;
634
    }
763
    }
635
    
764
 
636
    /**
765
    /**
637
    * Sets the width for the top border of the cell
766
    * Sets the width for the top border of the cell
638
    *
767
    *
639
    * @access public
768
    * @access public
640
    * @param integer $style style of the cell top border. 1 => thin, 2 => thick.
769
    * @param integer $style style of the cell top border. 1 => thin, 2 => thick.
641
    */
770
    */
642
    function setTop($style)
771
    function setTop($style)
643
    {
772
    {
644
        $this->_top = $style;
773
        $this->_top = $style;
645
    }
774
    }
646
    
775
 
647
    /**
776
    /**
648
    * Sets the width for the left border of the cell
777
    * Sets the width for the left border of the cell
649
    *
778
    *
650
    * @access public
779
    * @access public
651
    * @param integer $style style of the cell left border. 1 => thin, 2 => thick.
780
    * @param integer $style style of the cell left border. 1 => thin, 2 => thick.
652
    */
781
    */
653
    function setLeft($style)
782
    function setLeft($style)
654
    {
783
    {
655
        $this->_left = $style;
784
        $this->_left = $style;
656
    }
785
    }
657
    
786
 
658
    /**
787
    /**
659
    * Sets the width for the right border of the cell
788
    * Sets the width for the right border of the cell
660
    *
789
    *
661
    * @access public
790
    * @access public
662
    * @param integer $style style of the cell right border. 1 => thin, 2 => thick.
791
    * @param integer $style style of the cell right border. 1 => thin, 2 => thick.
663
    */
792
    */
664
    function setRight($style)
793
    function setRight($style)
665
    {
794
    {
666
        $this->_right = $style;
795
        $this->_right = $style;
667
    }
796
    }
668
    
797
 
669
    
798
 
670
    /**
799
    /**
671
    * Set cells borders to the same style
800
    * Set cells borders to the same style
672
    *
801
    *
673
    * @access public
802
    * @access public
674
    * @param integer $style style to apply for all cell borders. 1 => thin, 2 => thick.
803
    * @param integer $style style to apply for all cell borders. 1 => thin, 2 => thick.
Line 678... Line 807...
678
        $this->setBottom($style);
807
        $this->setBottom($style);
679
        $this->setTop($style);
808
        $this->setTop($style);
680
        $this->setLeft($style);
809
        $this->setLeft($style);
681
        $this->setRight($style);
810
        $this->setRight($style);
682
    }
811
    }
683
    
812
 
684
    
813
 
685
    /*******************************************
814
    /*******************************************
686
    * FUNCTIONS FOR SETTING CELLS BORDERS COLORS
815
    * FUNCTIONS FOR SETTING CELLS BORDERS COLORS
687
    */
816
    */
688
    
817
 
689
    /**
818
    /**
690
    * Sets all the cell's borders to the same color
819
    * Sets all the cell's borders to the same color
691
    *
820
    *
692
    * @access public
821
    * @access public
693
    * @param mixed $color The color we are setting. Either a string (like 'blue'), 
822
    * @param mixed $color The color we are setting. Either a string (like 'blue'),
694
    *                     or an integer (range is [8...63]).
823
    *                     or an integer (range is [8...63]).
695
    */
824
    */
696
    function setBorderColor($color)
825
    function setBorderColor($color)
697
    {
826
    {
698
        $this->setBottomColor($color);
827
        $this->setBottomColor($color);
699
        $this->setTopColor($color);
828
        $this->setTopColor($color);
700
        $this->setLeftColor($color);
829
        $this->setLeftColor($color);
701
        $this->setRightColor($color);
830
        $this->setRightColor($color);
702
    }
831
    }
703
    
832
 
704
    /**
833
    /**
705
    * Sets the cell's bottom border color
834
    * Sets the cell's bottom border color
706
    *
835
    *
707
    * @access public
836
    * @access public
708
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
837
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
Line 710... Line 839...
710
    function setBottomColor($color)
839
    function setBottomColor($color)
711
    {
840
    {
712
        $value = $this->_getColor($color);
841
        $value = $this->_getColor($color);
713
        $this->_bottom_color = $value;
842
        $this->_bottom_color = $value;
714
    }
843
    }
715
    
844
 
716
    /**
845
    /**
717
    * Sets the cell's top border color
846
    * Sets the cell's top border color
718
    *
847
    *
719
    * @access public
848
    * @access public
720
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
849
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
Line 722... Line 851...
722
    function setTopColor($color)
851
    function setTopColor($color)
723
    {
852
    {
724
        $value = $this->_getColor($color);
853
        $value = $this->_getColor($color);
725
        $this->_top_color = $value;
854
        $this->_top_color = $value;
726
    }
855
    }
727
    
856
 
728
    /**
857
    /**
729
    * Sets the cell's left border color
858
    * Sets the cell's left border color
730
    *
859
    *
731
    * @access public
860
    * @access public
732
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
861
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
Line 734... Line 863...
734
    function setLeftColor($color)
863
    function setLeftColor($color)
735
    {
864
    {
736
        $value = $this->_getColor($color);
865
        $value = $this->_getColor($color);
737
        $this->_left_color = $value;
866
        $this->_left_color = $value;
738
    }
867
    }
739
    
868
 
740
    /**
869
    /**
741
    * Sets the cell's right border color
870
    * Sets the cell's right border color
742
    *
871
    *
743
    * @access public
872
    * @access public
744
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
873
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
Line 746... Line 875...
746
    function setRightColor($color)
875
    function setRightColor($color)
747
    {
876
    {
748
        $value = $this->_getColor($color);
877
        $value = $this->_getColor($color);
749
        $this->_right_color = $value;
878
        $this->_right_color = $value;
750
    }
879
    }
751
    
880
 
752
    
881
 
753
    /**
882
    /**
754
    * Sets the cell's foreground color
883
    * Sets the cell's foreground color
755
    *
884
    *
756
    * @access public
885
    * @access public
757
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
886
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
758
    */
887
    */
759
    function setFgColor($color)
888
    function setFgColor($color)
760
    {
889
    {
761
        $value = $this->_getColor($color);
890
        $value = $this->_getColor($color);
762
        $this->_fg_color = $value;
891
        $this->_fg_color = $value;
-
 
892
        if ($this->_pattern == 0) { // force color to be seen
-
 
893
            $this->_pattern = 1;
-
 
894
        }
763
    }
895
    }
764
      
896
 
765
    /**
897
    /**
766
    * Sets the cell's background color
898
    * Sets the cell's background color
767
    *
899
    *
768
    * @access public
900
    * @access public
769
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
901
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
770
    */
902
    */
771
    function setBgColor($color)
903
    function setBgColor($color)
772
    {
904
    {
773
        $value = $this->_getColor($color);
905
        $value = $this->_getColor($color);
774
        $this->_bg_color = $value;
906
        $this->_bg_color = $value;
-
 
907
        if ($this->_pattern == 0) { // force color to be seen
-
 
908
            $this->_pattern = 1;
-
 
909
        }
775
    }
910
    }
776
    
911
 
777
    /**
912
    /**
778
    * Sets the cell's color
913
    * Sets the cell's color
779
    *
914
    *
780
    * @access public
915
    * @access public
781
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
916
    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
Line 783... Line 918...
783
    function setColor($color)
918
    function setColor($color)
784
    {
919
    {
785
        $value = $this->_getColor($color);
920
        $value = $this->_getColor($color);
786
        $this->_color = $value;
921
        $this->_color = $value;
787
    }
922
    }
788
    
923
 
789
    /**
924
    /**
790
    * Sets the fill pattern attribute of a cell
925
    * Sets the fill pattern attribute of a cell
791
    *
926
    *
792
    * @access public
927
    * @access public
793
    * @param integer $arg Optional. Defaults to 1. Meaningful values are: 0-18,
928
    * @param integer $arg Optional. Defaults to 1. Meaningful values are: 0-18,
Line 795... Line 930...
795
    */
930
    */
796
    function setPattern($arg = 1)
931
    function setPattern($arg = 1)
797
    {
932
    {
798
        $this->_pattern = $arg;
933
        $this->_pattern = $arg;
799
    }
934
    }
800
    
935
 
801
    /**
936
    /**
802
    * Sets the underline of the text
937
    * Sets the underline of the text
803
    *
938
    *
804
    * @access public
939
    * @access public
805
    * @param integer $underline The value for underline. Possible values are:
940
    * @param integer $underline The value for underline. Possible values are:
Line 807... Line 942...
807
    */
942
    */
808
    function setUnderline($underline)
943
    function setUnderline($underline)
809
    {
944
    {
810
        $this->_underline = $underline;
945
        $this->_underline = $underline;
811
    }
946
    }
812
 
947
 
813
    /**
948
    /**
814
    * Sets the font style as italic
949
    * Sets the font style as italic
815
    *
950
    *
816
    * @access public
951
    * @access public
817
    */
952
    */
Line 819... Line 954...
819
    {
954
    {
820
        $this->_italic = 1;
955
        $this->_italic = 1;
821
    }
956
    }
Line 822... Line 957...
822
 
957
 
823
    /**
958
    /**
824
    * Sets the font size 
959
    * Sets the font size
825
    *
960
    *
826
    * @access public
961
    * @access public
827
    * @param integer $size The font size (in pixels I think).
962
    * @param integer $size The font size (in pixels I think).
828
    */
963
    */
829
    function setSize($size)
964
    function setSize($size)
830
    {
965
    {
831
        $this->_size = $size;
966
        $this->_size = $size;
832
    }
967
    }
833
    
968
 
834
    /**
969
    /**
835
    * Sets text wrapping
970
    * Sets text wrapping
836
    *
971
    *
837
    * @access public
972
    * @access public
Line 854... Line 989...
854
        {
989
        {
855
            case 0:
990
            case 0:
856
                $this->_rotation = 0;
991
                $this->_rotation = 0;
857
                break;
992
                break;
858
            case 90:
993
            case 90:
-
 
994
                if ($this->_BIFF_version == 0x0500) {
859
                $this->_rotation = 3;
995
                $this->_rotation = 3;
-
 
996
                } elseif ($this->_BIFF_version == 0x0600) {
-
 
997
                    $this->_rotation = 180;
-
 
998
                }
860
                break;
999
                break;
861
            case 270:
1000
            case 270:
-
 
1001
                if ($this->_BIFF_version == 0x0500) {
862
                $this->_rotation = 2;
1002
                $this->_rotation = 2;
-
 
1003
                } elseif ($this->_BIFF_version == 0x0600) {
-
 
1004
                    $this->_rotation = 90;
-
 
1005
                }
863
                break;
1006
                break;
864
            case -1:
1007
            case -1:
-
 
1008
                if ($this->_BIFF_version == 0x0500) {
865
                $this->_rotation = 1;
1009
                $this->_rotation = 1;
-
 
1010
                } elseif ($this->_BIFF_version == 0x0600) {
-
 
1011
                    $this->_rotation = 255;
-
 
1012
                }
866
                break;
1013
                break;
867
            default :
1014
            default :
868
                $this->raiseError("Invalid value for angle.".
1015
                return $this->raiseError("Invalid value for angle.".
869
                                  " Possible values are: 0, 90, 270 and -1 ".
1016
                                  " Possible values are: 0, 90, 270 and -1 ".
870
                                  "for stacking top-to-bottom.");
1017
                                  "for stacking top-to-bottom.");
871
                $this->_rotation = 0;
1018
                $this->_rotation = 0;
872
                break;
1019
                break;
873
        }
1020
        }
Line 925... Line 1072...
925
    function setScript($script)
1072
    function setScript($script)
926
    {
1073
    {
927
        $this->_font_script = $script;
1074
        $this->_font_script = $script;
928
    }
1075
    }
Line -... Line 1076...
-
 
1076
 
-
 
1077
     /**
-
 
1078
     * Locks a cell.
-
 
1079
     *
-
 
1080
     * @access public
-
 
1081
     */
-
 
1082
     function setLocked()
-
 
1083
     {
-
 
1084
         $this->_locked = 1;
-
 
1085
     }
929
 
1086
 
930
    /**
1087
    /**
931
    * Unlocks a cell. Useful for unprotecting particular cells of a protected sheet.
1088
    * Unlocks a cell. Useful for unprotecting particular cells of a protected sheet.
932
    *
1089
    *
933
    * @access public
1090
    * @access public
934
    */
1091
    */
935
    function setUnLocked()
1092
    function setUnLocked()
936
    {
1093
    {
937
        $this->_locked = 0;
1094
        $this->_locked = 0;
-
 
1095
    }
-
 
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;
938
    }
1107
    }
939
}
1108
}