Subversion Repositories eFlore/Applications.cel

Rev

Rev 996 | Rev 1605 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 996 Rev 1604
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
 
35
require_once('Parser.php');
35
require_once 'Spreadsheet/Excel/Writer/Parser.php';
Line 36... Line 36...
36
require_once('BIFFwriter.php');
36
require_once 'Spreadsheet/Excel/Writer/BIFFwriter.php';
37
 
37
 
38
/**
38
/**
39
* Class for generating Excel Spreadsheets
39
* Class for generating Excel Spreadsheets
Line 100... Line 100...
100
    var $_xls_strmax;
100
    var $_xls_strmax;
Line 101... Line 101...
101
 
101
 
102
    /**
102
    /**
103
    * First row for the DIMENSIONS record
103
    * First row for the DIMENSIONS record
104
    * @var integer
104
    * @var integer
105
    * @see storeDimensions()
105
    * @see _storeDimensions()
106
    */
106
    */
Line 107... Line 107...
107
    var $_dim_rowmin;
107
    var $_dim_rowmin;
108
 
108
 
109
    /**
109
    /**
110
    * Last row for the DIMENSIONS record
110
    * Last row for the DIMENSIONS record
111
    * @var integer
111
    * @var integer
112
    * @see storeDimensions()
112
    * @see _storeDimensions()
Line 113... Line 113...
113
    */
113
    */
114
    var $_dim_rowmax;
114
    var $_dim_rowmax;
115
 
115
 
116
    /**
116
    /**
117
    * First column for the DIMENSIONS record
117
    * First column for the DIMENSIONS record
118
    * @var integer
118
    * @var integer
Line 119... Line 119...
119
    * @see storeDimensions()
119
    * @see _storeDimensions()
120
    */
120
    */
121
    var $_dim_colmin;
121
    var $_dim_colmin;
122
 
122
 
123
    /**
123
    /**
124
    * Last column for the DIMENSIONS record
124
    * Last column for the DIMENSIONS record
Line 125... Line 125...
125
    * @var integer
125
    * @var integer
126
    * @see storeDimensions()
126
    * @see _storeDimensions()
Line 276... Line 276...
276
    * @var integer
276
    * @var integer
277
    */
277
    */
278
    var $print_colmax;
278
    var $print_colmax;
Line 279... Line 279...
279
 
279
 
-
 
280
    /**
-
 
281
    * Whether to display RightToLeft.
-
 
282
    * @var integer
-
 
283
    */
-
 
284
    var $_Arabic;
-
 
285
 
-
 
286
    /**
-
 
287
    * Whether to use outline.
-
 
288
    * @var integer
-
 
289
    */
-
 
290
    var $_outline_on;
-
 
291
 
-
 
292
    /**
-
 
293
    * Auto outline styles.
-
 
294
    * @var bool
-
 
295
    */
-
 
296
    var $_outline_style;
-
 
297
 
-
 
298
    /**
-
 
299
    * Whether to have outline summary below.
-
 
300
    * @var bool
-
 
301
    */
-
 
302
    var $_outline_below;
-
 
303
 
-
 
304
    /**
-
 
305
    * Whether to have outline summary at the right.
-
 
306
    * @var bool
-
 
307
    */
-
 
308
    var $_outline_right;
-
 
309
 
-
 
310
    /**
-
 
311
    * Outline row level.
-
 
312
    * @var integer
-
 
313
    */
-
 
314
    var $_outline_row_level;
-
 
315
 
-
 
316
    /**
-
 
317
    * Whether to fit to page when printing or not.
-
 
318
    * @var bool
-
 
319
    */
-
 
320
    var $_fit_page;
-
 
321
 
-
 
322
    /**
-
 
323
    * Number of pages to fit wide
-
 
324
    * @var integer
-
 
325
    */
-
 
326
    var $_fit_width;
-
 
327
 
-
 
328
    /**
-
 
329
    * Number of pages to fit high
-
 
330
    * @var integer
-
 
331
    */
-
 
332
    var $_fit_height;
-
 
333
 
-
 
334
    /**
-
 
335
    * Reference to the total number of strings in the workbook
-
 
336
    * @var integer
-
 
337
    */
-
 
338
    var $_str_total;
-
 
339
 
-
 
340
    /**
-
 
341
    * Reference to the number of unique strings in the workbook
-
 
342
    * @var integer
-
 
343
    */
-
 
344
    var $_str_unique;
-
 
345
 
-
 
346
    /**
-
 
347
    * Reference to the array containing all the unique strings in the workbook
-
 
348
    * @var array
-
 
349
    */
-
 
350
    var $_str_table;
-
 
351
 
-
 
352
    /**
-
 
353
     * Number of merged cell ranges in actual record
-
 
354
     * @var int $_merged_cells_counter
-
 
355
     */
-
 
356
    var $_merged_cells_counter = 0;
-
 
357
 
-
 
358
    /**
-
 
359
     * Number of actual mergedcells record
-
 
360
     * @var int $_merged_cells_record
-
 
361
     */
-
 
362
    var $_merged_cells_record = 0;
-
 
363
 
-
 
364
    /**
-
 
365
    * Merged cell ranges
-
 
366
    * @var array
-
 
367
    */
-
 
368
    var $_merged_ranges;
-
 
369
 
-
 
370
    /**
-
 
371
    * Charset encoding currently used when calling writeString()
-
 
372
    * @var string
-
 
373
    */
-
 
374
    var $_input_encoding;
-
 
375
 
280
    /**
376
    /**
281
    * Constructor
377
    * Constructor
282
    *
378
    *
283
    * @param string  $name         The name of the new worksheet
379
    * @param string  $name         The name of the new worksheet
284
    * @param integer $index        The index of the new worksheet
380
    * @param integer $index        The index of the new worksheet
285
    * @param mixed   &$activesheet The current activesheet of the workbook we belong to
381
    * @param mixed   &$activesheet The current activesheet of the workbook we belong to
286
    * @param mixed   &$firstsheet  The first worksheet in the workbook we belong to 
382
    * @param mixed   &$firstsheet  The first worksheet in the workbook we belong to
287
    * @param mixed   &$url_format  The default format for hyperlinks
383
    * @param mixed   &$url_format  The default format for hyperlinks
-
 
384
    * @param mixed   &$parser      The formula parser created for the Workbook
-
 
385
    * @param string  $tmp_dir      The path to the directory for temporary files
288
    * @param mixed   &$parser      The formula parser created for the Workbook
386
    * @access private
289
    */
387
    */
-
 
388
    function Spreadsheet_Excel_Writer_Worksheet($BIFF_version, $name,
290
    function Spreadsheet_Excel_Writer_Worksheet($name, $index, &$activesheet,
389
                                                $index, &$activesheet,
-
 
390
                                                &$firstsheet, &$str_total,
-
 
391
                                                &$str_unique, &$str_table,
291
                                                &$firstsheet, &$url_format,
392
                                                &$url_format, &$parser,
292
                                                &$parser)
393
                                                $tmp_dir)
293
    {
394
    {
294
        // It needs to call its parent's constructor explicitly
395
        // It needs to call its parent's constructor explicitly
-
 
396
        $this->Spreadsheet_Excel_Writer_BIFFwriter();
295
        $this->Spreadsheet_Excel_Writer_BIFFwriter();
397
        $this->_BIFF_version   = $BIFF_version;
296
        $rowmax                = 65536; // 16384 in Excel 5
398
        $rowmax                = 65536; // 16384 in Excel 5
Line 297... Line 399...
297
        $colmax                = 256;
399
        $colmax                = 256;
298
    
400
 
299
        $this->name            = $name;
401
        $this->name            = $name;
300
        $this->index           = $index;
402
        $this->index           = $index;
-
 
403
        $this->activesheet     = &$activesheet;
-
 
404
        $this->firstsheet      = &$firstsheet;
-
 
405
        $this->_str_total      = &$str_total;
301
        $this->activesheet     = &$activesheet;
406
        $this->_str_unique     = &$str_unique;
302
        $this->firstsheet      = &$firstsheet;
407
        $this->_str_table      = &$str_table;
Line 303... Line 408...
303
        $this->_url_format     = &$url_format;
408
        $this->_url_format     = &$url_format;
304
        $this->_parser         = &$parser;
409
        $this->_parser         = &$parser;
305
    
410
 
306
        //$this->ext_sheets      = array();
411
        //$this->ext_sheets      = array();
307
        $this->_filehandle     = "";
412
        $this->_filehandle     = '';
308
        $this->_using_tmpfile  = true;
413
        $this->_using_tmpfile  = true;
309
        //$this->fileclosed      = 0;
414
        //$this->fileclosed      = 0;
Line 333... Line 438...
333
        $this->_margin_left     = 0.75;
438
        $this->_margin_left     = 0.75;
334
        $this->_margin_right    = 0.75;
439
        $this->_margin_right    = 0.75;
335
        $this->_margin_top      = 1.00;
440
        $this->_margin_top      = 1.00;
336
        $this->_margin_bottom   = 1.00;
441
        $this->_margin_bottom   = 1.00;
Line 337... Line 442...
337
    
442
 
338
        $this->title_rowmin     = NULL;
443
        $this->title_rowmin     = null;
339
        $this->title_rowmax     = NULL;
444
        $this->title_rowmax     = null;
340
        $this->title_colmin     = NULL;
445
        $this->title_colmin     = null;
341
        $this->title_colmax     = NULL;
446
        $this->title_colmax     = null;
342
        $this->print_rowmin     = NULL;
447
        $this->print_rowmin     = null;
343
        $this->print_rowmax     = NULL;
448
        $this->print_rowmax     = null;
344
        $this->print_colmin     = NULL;
449
        $this->print_colmin     = null;
Line 345... Line 450...
345
        $this->print_colmax     = NULL;
450
        $this->print_colmax     = null;
-
 
451
 
346
    
452
        $this->_print_gridlines  = 1;
Line 347... Line 453...
347
        $this->_print_gridlines = 1;
453
        $this->_screen_gridlines = 1;
348
        $this->_print_headers   = 0;
454
        $this->_print_headers    = 0;
349
    
455
 
Line 350... Line 456...
350
        $this->_fit_page        = 0;
456
        $this->_fit_page        = 0;
351
        $this->_fit_width       = 0;
457
        $this->_fit_width       = 0;
Line 352... Line 458...
352
        $this->_fit_height      = 0;
458
        $this->_fit_height      = 0;
353
    
459
 
Line 354... Line 460...
354
        $this->_hbreaks         = array();
460
        $this->_hbreaks         = array();
355
        $this->_vbreaks         = array();
461
        $this->_vbreaks         = array();
Line 356... Line 462...
356
    
462
 
357
        $this->_protect         = 0;
463
        $this->_protect         = 0;
Line -... Line 464...
-
 
464
        $this->_password        = null;
-
 
465
 
-
 
466
        $this->col_sizes        = array();
-
 
467
        $this->_row_sizes        = array();
-
 
468
 
-
 
469
        $this->_zoom            = 100;
-
 
470
        $this->_print_scale     = 100;
-
 
471
 
-
 
472
        $this->_outline_row_level = 0;
-
 
473
        $this->_outline_style     = 0;
-
 
474
        $this->_outline_below     = 1;
-
 
475
        $this->_outline_right     = 1;
-
 
476
        $this->_outline_on        = 1;
-
 
477
        $this->_Arabic            = 0;
-
 
478
 
-
 
479
        $this->_merged_ranges     = array();
358
        $this->_password        = NULL;
480
 
359
    
481
        $this->_input_encoding    = '';
Line 360... Line 482...
360
        $this->col_sizes        = array();
482
 
361
        $this->row_sizes        = array();
483
        $this->_dv                = array();
Line 373... Line 495...
373
    *
495
    *
374
    * @access private
496
    * @access private
375
    */
497
    */
376
    function _initialize()
498
    function _initialize()
377
    {
499
    {
-
 
500
        if ($this->_using_tmpfile == false) {
-
 
501
            return;
-
 
502
        }
-
 
503
 
-
 
504
        if ($this->_tmp_dir === '' && ini_get('open_basedir') === true) {
-
 
505
            // open_basedir restriction in effect - store data in memory
-
 
506
            // ToDo: Let the error actually have an effect somewhere
-
 
507
            $this->_using_tmpfile = false;  
-
 
508
            return new PEAR_Error('Temp file could not be opened since open_basedir restriction in effect - please use setTmpDir() - using memory storage instead');
-
 
509
        }
-
 
510
 
378
        // Open tmp file for storing Worksheet data
511
        // Open tmp file for storing Worksheet data
-
 
512
        if ($this->_tmp_dir === '') {
379
        $fh = tmpfile();
513
            $fh = tmpfile();
380
        if ( $fh) {
514
        } else {
381
            // Store filehandle
515
            // For people with open base dir restriction
-
 
516
            $this->_tmp_file = tempnam($this->_tmp_dir, "Spreadsheet_Excel_Writer");
382
            $this->_filehandle = $fh;
517
            $fh = @fopen($this->_tmp_file, "w+b");
383
        }
518
        }
-
 
519
 
384
        else {
520
        if ($fh === false) {
385
            // If tmpfile() fails store data in memory
521
            // If tmpfile() fails store data in memory
386
            $this->_using_tmpfile = false;
522
            $this->_using_tmpfile = false;
-
 
523
        } else {
-
 
524
            // Store filehandle
-
 
525
            $this->_filehandle = $fh;
387
        }
526
        }
388
    }
527
    }
Line 389... Line 528...
389
    
528
 
390
    /**
529
    /**
Line 403... Line 542...
403
        /***********************************************
542
        /***********************************************
404
        * Prepend in reverse order!!
543
        * Prepend in reverse order!!
405
        */
544
        */
Line 406... Line 545...
406
    
545
 
407
        // Prepend the sheet dimensions
546
        // Prepend the sheet dimensions
Line 408... Line 547...
408
        $this->storeDimensions();
547
        $this->_storeDimensions();
409
    
548
 
Line 410... Line 549...
410
        // Prepend the sheet password
549
        // Prepend the sheet password
411
        $this->_storePassword();
550
        $this->_storePassword();
Line 412... Line 551...
412
    
551
 
413
        // Prepend the sheet protection
552
        // Prepend the sheet protection
Line -... Line 553...
-
 
553
        $this->_storeProtect();
414
        $this->_storeProtect();
554
 
415
    
555
        // Prepend the page setup
Line 416... Line 556...
416
        // Prepend the page setup
556
        $this->_storeSetup();
417
        $this->_storeSetup();
557
 
Line 450... Line 590...
450
        $this->_storeWsbool();
590
        $this->_storeWsbool();
Line 451... Line 591...
451
    
591
 
452
        // Prepend GRIDSET
592
        // Prepend GRIDSET
Line -... Line 593...
-
 
593
        $this->_storeGridset();
-
 
594
 
-
 
595
         //  Prepend GUTS
-
 
596
        if ($this->_BIFF_version == 0x0500) {
-
 
597
            $this->_storeGuts();
453
        $this->_storeGridset();
598
        }
454
    
599
 
Line 455... Line 600...
455
        // Prepend PRINTGRIDLINES
600
        // Prepend PRINTGRIDLINES
456
        $this->_storePrintGridlines();
601
        $this->_storePrintGridlines();
Line 457... Line 602...
457
    
602
 
-
 
603
        // Prepend PRINTHEADERS
458
        // Prepend PRINTHEADERS
604
        $this->_storePrintHeaders();
459
        $this->_storePrintHeaders();
-
 
460
    
605
 
461
        // Prepend EXTERNSHEET references
606
        // Prepend EXTERNSHEET references
462
        for ($i = $num_sheets; $i > 0; $i--)
607
        if ($this->_BIFF_version == 0x0500) {
-
 
608
            for ($i = $num_sheets; $i > 0; $i--) {
Line 463... Line 609...
463
        {
609
                $sheetname = $sheetnames[$i-1];
-
 
610
                $this->_storeExternsheet($sheetname);
464
            $sheetname = $sheetnames[$i-1];
611
            }
-
 
612
        }
Line 465... Line 613...
465
            $this->_storeExternsheet($sheetname);
613
 
466
        }
614
        // Prepend the EXTERNCOUNT of external references.
467
    
615
        if ($this->_BIFF_version == 0x0500) {
468
        // Prepend the EXTERNCOUNT of external references.
616
            $this->_storeExterncount($num_sheets);
469
        $this->_storeExterncount($num_sheets);
617
        }
470
    
618
 
471
        // Prepend the COLINFO records if they exist
619
        // Prepend the COLINFO records if they exist
472
        if (!empty($this->_colinfo))
620
        if (!empty($this->_colinfo)) {
Line 489... Line 637...
489
        $this->_storeZoom();
637
        $this->_storeZoom();
490
        if (!empty($this->_panes)) {
638
        if (!empty($this->_panes)) {
491
            $this->_storePanes($this->_panes);
639
            $this->_storePanes($this->_panes);
492
        }
640
        }
493
        $this->_storeSelection($this->_selection);
641
        $this->_storeSelection($this->_selection);
-
 
642
        $this->_storeMergedCells();
-
 
643
        /* TODO: add data validity */
-
 
644
        /*if ($this->_BIFF_version == 0x0600) {
-
 
645
            $this->_storeDataValidity();
-
 
646
        }*/
494
        $this->_storeEof();
647
        $this->_storeEof();
-
 
648
 
-
 
649
        if ( $this->_tmp_file != '' ) {
-
 
650
          if ( $this->_filehandle ) {
-
 
651
            fclose($this->_filehandle);
-
 
652
            $this->_filehandle = '';
-
 
653
          }
-
 
654
          @unlink($this->_tmp_file);
-
 
655
          $this->_tmp_file      = '';
-
 
656
          $this->_using_tmpfile = true;
-
 
657
        }
495
    }
658
    }
Line 496... Line 659...
496
    
659
 
497
    /**
660
    /**
498
    * Retrieve the worksheet name.
661
    * Retrieve the worksheet name.
Line 515... Line 678...
515
    function getData()
678
    function getData()
516
    {
679
    {
517
        $buffer = 4096;
680
        $buffer = 4096;
Line 518... Line 681...
518
    
681
 
519
        // Return data stored in memory
682
        // Return data stored in memory
520
        if (isset($this->_data))
-
 
521
        {
683
        if (isset($this->_data)) {
522
            $tmp   = $this->_data;
684
            $tmp   = $this->_data;
523
            unset($this->_data);
685
            unset($this->_data);
524
            $fh    = $this->_filehandle;
686
            $fh    = $this->_filehandle;
525
            if ($this->_using_tmpfile) {
687
            if ($this->_using_tmpfile) {
526
                fseek($fh, 0);
688
                fseek($fh, 0);
527
            }
689
            }
528
            return($tmp);
690
            return $tmp;
529
        }
691
        }
530
        // Return data stored on disk
692
        // Return data stored on disk
531
        if ($this->_using_tmpfile)
-
 
532
        {
693
        if ($this->_using_tmpfile) {
533
            if ($tmp = fread($this->_filehandle, $buffer)) {
694
            if ($tmp = fread($this->_filehandle, $buffer)) {
534
                return($tmp);
695
                return $tmp;
535
            }
696
            }
Line 536... Line 697...
536
        }
697
        }
537
    
698
 
-
 
699
        // No data to return
-
 
700
        return '';
-
 
701
    }
-
 
702
 
-
 
703
    /**
-
 
704
    * Sets a merged cell range
-
 
705
    *
-
 
706
    * @access public
-
 
707
    * @param integer $first_row First row of the area to merge
-
 
708
    * @param integer $first_col First column of the area to merge
-
 
709
    * @param integer $last_row  Last row of the area to merge
-
 
710
    * @param integer $last_col  Last column of the area to merge
-
 
711
    */
-
 
712
    function setMerge($first_row, $first_col, $last_row, $last_col)
-
 
713
    {
-
 
714
        if (($last_row < $first_row) || ($last_col < $first_col)) {
-
 
715
            return;
-
 
716
        }
-
 
717
 
-
 
718
        $max_record_ranges = floor(($this->_limit - 6) / 8);
-
 
719
        if($this->_merged_cells_counter >= $max_record_ranges)
-
 
720
          {
-
 
721
            $this->_merged_cells_record++;
-
 
722
            $this->_merged_cells_counter = 0;
-
 
723
          }
-
 
724
 
-
 
725
        // don't check rowmin, rowmax, etc... because we don't know when this
-
 
726
        // is going to be called
538
        // No data to return
727
        $this->_merged_ranges[$this->_merged_cells_record][] = array($first_row, $first_col, $last_row, $last_col);
Line 539... Line 728...
539
        return('');
728
        $this->_merged_cells_counter++;
540
    }
729
    }
541
    
730
 
Line 596... Line 785...
596
    * @param integer $firstcol first column on the range
785
    * @param integer $firstcol first column on the range
597
    * @param integer $lastcol  last column on the range
786
    * @param integer $lastcol  last column on the range
598
    * @param integer $width    width to set
787
    * @param integer $width    width to set
599
    * @param mixed   $format   The optional XF format to apply to the columns
788
    * @param mixed   $format   The optional XF format to apply to the columns
600
    * @param integer $hidden   The optional hidden atribute
789
    * @param integer $hidden   The optional hidden atribute
-
 
790
    * @param integer $level    The optional outline level
601
    */
791
    */
602
    function setColumn($firstcol, $lastcol, $width, $format = 0, $hidden = 0)
792
    function setColumn($firstcol, $lastcol, $width, $format = null, $hidden = 0, $level = 0) 
-
 
793
    { // added by Dan Lynn <dan@spiderweblabs.com) on 2006-12-06 
-
 
794
        // look for any ranges this might overlap and remove, size or split where necessary 
-
 
795
        foreach ($this->_colinfo as $key => $colinfo) 
603
    {
796
        {
-
 
797
            $existing_start = $colinfo[0]; $existing_end = $colinfo[1]; 
-
 
798
            // if the new range starts within another range 
-
 
799
            if ($firstcol > $existing_start && $firstcol < $existing_end) 
-
 
800
            { // trim the existing range to the beginning of the new range 
-
 
801
                $this->_colinfo[$key][1] = $firstcol - 1; 
-
 
802
                // if the new range lies WITHIN the existing range 
-
 
803
                if ($lastcol < $existing_end) 
-
 
804
                { // split the existing range by adding a range after our new range 
-
 
805
                    $this->_colinfo[] = array($lastcol+1, $existing_end, $colinfo[2], &$colinfo[3], $colinfo[4], $colinfo[5]); 
-
 
806
                } 
-
 
807
            } // if the new range ends inside an existing range 
-
 
808
            elseif ($lastcol > $existing_start && $lastcol < $existing_end) 
-
 
809
            { // trim the existing range to the end of the new range 
-
 
810
                $this->_colinfo[$key][0] = $lastcol + 1; 
-
 
811
            } // if the new range completely overlaps the existing range 
-
 
812
            elseif ($firstcol <= $existing_start && $lastcol >= $existing_end) 
-
 
813
            { 
-
 
814
                unset($this->_colinfo[$key]); 
-
 
815
            } 
-
 
816
        } // added by Dan Lynn <dan@spiderweblabs.com) on 2006-12-06 
-
 
817
        // regenerate keys 
-
 
818
        $this->_colinfo = array_values($this->_colinfo); 
604
        $this->_colinfo[] = array($firstcol, $lastcol, $width, &$format, $hidden);
819
        $this->_colinfo[] = array($firstcol, $lastcol, $width, &$format, $hidden, $level); 
605
    
-
 
606
        // Set width to zero if column is hidden
820
        // Set width to zero if column is hidden 
607
        $width = ($hidden) ? 0 : $width;
821
        $width = ($hidden) ? 0 : $width; 
608
    
-
 
609
        for($col = $firstcol; $col <= $lastcol; $col++) {
822
        for ($col = $firstcol; $col <= $lastcol; $col++) 
-
 
823
        { 
610
            $this->col_sizes[$col] = $width;
824
            $this->col_sizes[$col] = $width; 
611
        }
825
        } 
612
    }
826
    }
Line 613... Line 827...
613
    
827
 
Line 834... Line 1048...
834
    *
1048
    *
835
    * @access public
1049
    * @access public
836
    * @param integer $first_row First row to repeat
1050
    * @param integer $first_row First row to repeat
837
    * @param integer $last_row  Last row to repeat. Optional.
1051
    * @param integer $last_row  Last row to repeat. Optional.
838
    */
1052
    */
839
    function repeatRows($first_row, $last_row = NULL)
1053
    function repeatRows($first_row, $last_row = null)
840
    {
1054
    {
841
        $this->title_rowmin  = $first_row;
1055
        $this->title_rowmin  = $first_row;
842
        if (isset($last_row)) { //Second row is optional
1056
        if (isset($last_row)) { //Second row is optional
843
            $this->title_rowmax  = $last_row;
1057
            $this->title_rowmax  = $last_row;
844
        }
-
 
845
        else {
1058
        } else {
846
            $this->title_rowmax  = $first_row;
1059
            $this->title_rowmax  = $first_row;
847
        }
1060
        }
848
    }
1061
    }
Line 849... Line 1062...
849
    
1062
 
Line 852... Line 1065...
852
    *
1065
    *
853
    * @access public
1066
    * @access public
854
    * @param integer $first_col First column to repeat
1067
    * @param integer $first_col First column to repeat
855
    * @param integer $last_col  Last column to repeat. Optional.
1068
    * @param integer $last_col  Last column to repeat. Optional.
856
    */
1069
    */
857
    function repeatColumns($first_col, $last_col = NULL)
1070
    function repeatColumns($first_col, $last_col = null)
858
    {
1071
    {
859
        $this->title_colmin  = $first_col;
1072
        $this->title_colmin  = $first_col;
860
        if (isset($last_col)) { // Second col is optional
1073
        if (isset($last_col)) { // Second col is optional
861
            $this->title_colmax  = $last_col;
1074
            $this->title_colmax  = $last_col;
862
        }
-
 
863
        else {
1075
        } else {
864
            $this->title_colmax  = $first_col;
1076
            $this->title_colmax  = $first_col;
865
        }
1077
        }
866
    }
1078
    }
Line 867... Line 1079...
867
    
1079
 
Line 892... Line 1104...
892
    {
1104
    {
893
        $this->_print_gridlines = 0;
1105
        $this->_print_gridlines = 0;
894
    }
1106
    }
Line 895... Line 1107...
895
    
1107
 
-
 
1108
    /**
-
 
1109
    * Set the option to hide gridlines on the worksheet (as seen on the screen).
-
 
1110
    *
-
 
1111
    * @access public
-
 
1112
    */
-
 
1113
    function hideScreenGridlines()
-
 
1114
    {
-
 
1115
        $this->_screen_gridlines = 0;
-
 
1116
    }
-
 
1117
 
896
    /**
1118
    /**
897
    * Set the option to print the row and column headers on the printed page.
1119
    * Set the option to print the row and column headers on the printed page.
898
    *
1120
    *
899
    * @access public
1121
    * @access public
900
    * @param integer $print Whether to print the headers or not. Defaults to 1 (print).
1122
    * @param integer $print Whether to print the headers or not. Defaults to 1 (print).
Line 956... Line 1178...
956
    * @param integer $scale The zoom factor
1178
    * @param integer $scale The zoom factor
957
    */
1179
    */
958
    function setZoom($scale = 100)
1180
    function setZoom($scale = 100)
959
    {
1181
    {
960
        // Confine the scale to Excel's range
1182
        // Confine the scale to Excel's range
961
        if ($scale < 10 or $scale > 400) 
1183
        if ($scale < 10 || $scale > 400) {
962
        {
-
 
963
            $this->raiseError("Zoom factor $scale outside range: 10 <= zoom <= 400");
1184
            $this->raiseError("Zoom factor $scale outside range: 10 <= zoom <= 400");
964
            $scale = 100;
1185
            $scale = 100;
965
        }
1186
        }
Line 966... Line 1187...
966
    
1187
 
Line 975... Line 1196...
975
    * @param integer $scale The optional scale factor. Defaults to 100
1196
    * @param integer $scale The optional scale factor. Defaults to 100
976
    */
1197
    */
977
    function setPrintScale($scale = 100)
1198
    function setPrintScale($scale = 100)
978
    {
1199
    {
979
        // Confine the scale to Excel's range
1200
        // Confine the scale to Excel's range
980
        if ($scale < 10 or $scale > 400)
1201
        if ($scale < 10 || $scale > 400) {
981
        {
-
 
982
            $this->raiseError("Print scale $scale outside range: 10 <= zoom <= 400");
1202
            $this->raiseError("Print scale $scale outside range: 10 <= zoom <= 400");
983
            $scale = 100;
1203
            $scale = 100;
984
        }
1204
        }
Line 985... Line 1205...
985
    
1205
 
Line 996... Line 1216...
996
    * @param integer $row    The row of the cell we are writing to
1216
    * @param integer $row    The row of the cell we are writing to
997
    * @param integer $col    The column of the cell we are writing to
1217
    * @param integer $col    The column of the cell we are writing to
998
    * @param mixed   $token  What we are writing
1218
    * @param mixed   $token  What we are writing
999
    * @param mixed   $format The optional format to apply to the cell
1219
    * @param mixed   $format The optional format to apply to the cell
1000
    */
1220
    */
1001
    function write($row, $col, $token, $format = 0)
1221
    function write($row, $col, $token, $format = null)
1002
    {
1222
    {
1003
        // Check for a cell reference in A1 notation and substitute row and column
1223
        // Check for a cell reference in A1 notation and substitute row and column
1004
        /*if ($_[0] =~ /^\D/) {
1224
        /*if ($_[0] =~ /^\D/) {
1005
            @_ = $this->_substituteCellref(@_);
1225
            @_ = $this->_substituteCellref(@_);
1006
    }*/
1226
    }*/
Line 1007... Line -...
1007
    
-
 
1008
    
-
 
1009
        // Match number
1227
 
-
 
1228
        if (preg_match("/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/", $token)) {
1010
        if (preg_match("/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/",$token)) {
1229
            // Match number
1011
            return $this->writeNumber($row,$col,$token,$format);
1230
            return $this->writeNumber($row, $col, $token, $format);
1012
        }
1231
        } elseif (preg_match("/^[fh]tt?p:\/\//", $token)) {
1013
        // Match http or ftp URL
-
 
1014
        elseif (preg_match("/^[fh]tt?p:\/\//",$token)) {
1232
            // Match http or ftp URL
1015
            return $this->writeUrl($row, $col, $token, $format);
1233
            return $this->writeUrl($row, $col, $token, '', $format);
1016
        }
1234
        } elseif (preg_match("/^mailto:/", $token)) {
1017
        // Match mailto:
-
 
1018
        elseif (preg_match("/^mailto:/",$token)) {
1235
            // Match mailto:
1019
            return $this->writeUrl($row, $col, $token, $format);
1236
            return $this->writeUrl($row, $col, $token, '', $format);
1020
        }
1237
        } elseif (preg_match("/^(?:in|ex)ternal:/", $token)) {
1021
        // Match internal or external sheet link
-
 
1022
        elseif (preg_match("/^(?:in|ex)ternal:/",$token)) {
1238
            // Match internal or external sheet link
1023
            return $this->writeUrl($row, $col, $token, $format);
1239
            return $this->writeUrl($row, $col, $token, '', $format);
1024
        }
1240
        } elseif (preg_match("/^=/", $token)) {
1025
        // Match formula
-
 
1026
        elseif (preg_match("/^=/",$token)) {
1241
            // Match formula
1027
            return $this->writeFormula($row, $col, $token, $format);
-
 
1028
        }
-
 
1029
        // Match formula
1242
            return $this->writeFormula($row, $col, $token, $format);
1030
        elseif (preg_match("/^@/",$token)) {
-
 
1031
            return $this->writeFormula($row, $col, $token, $format);
-
 
1032
        }
1243
        } elseif ($token == '') {
1033
        // Match blank
-
 
1034
        elseif ($token == '') {
1244
            // Match blank
1035
            return $this->writeBlank($row,$col,$format);
1245
            return $this->writeBlank($row, $col, $format);
1036
        }
1246
        } else {
1037
        // Default: match string
-
 
1038
        else {
1247
            // Default: match string
1039
            return $this->writeString($row,$col,$token,$format);
1248
            return $this->writeString($row, $col, $token, $format);
1040
        }
1249
        }
Line 1041... Line 1250...
1041
    }
1250
    }
1042
    
1251
 
1043
    /**
1252
    /**
1044
    * Write an array of values as a row
1253
    * Write an array of values as a row
1045
    *
1254
    *
-
 
1255
    * @access public
-
 
1256
    * @param integer $row    The row we are writing to
-
 
1257
    * @param integer $col    The first col (leftmost col) we are writing to
1046
    * @access public
1258
    * @param array   $val    The array of values to write
1047
    * @param
1259
    * @param mixed   $format The optional format to apply to the cell
Line 1048... Line 1260...
1048
    * @return 
1260
    * @return mixed PEAR_Error on failure
1049
    */
1261
    */
-
 
1262
 
1050
 
1263
    function writeRow($row, $col, $val, $format = null)
1051
    function writeRow($row, $col, $val, $format=0)
1264
    {
1052
    {   
1265
        $retval = '';
1053
        if (is_array($val)) {
1266
        if (is_array($val)) {
1054
            foreach($val as $v) {
1267
            foreach ($val as $v) {
Line 1067... Line 1280...
1067
      
1280
 
1068
    /**
1281
    /**
1069
    * Write an array of values as a column
1282
    * Write an array of values as a column
1070
    *
1283
    *
-
 
1284
    * @access public
1071
    * @access public
1285
    * @param integer $row    The first row (uppermost row) we are writing to
-
 
1286
    * @param integer $col    The col we are writing to
-
 
1287
    * @param array   $val    The array of values to write
1072
    * @param
1288
    * @param mixed   $format The optional format to apply to the cell
1073
    * @return 
1289
    * @return mixed PEAR_Error on failure
Line 1074... Line 1290...
1074
    */
1290
    */
1075
    
1291
 
-
 
1292
    function writeCol($row, $col, $val, $format = null)
1076
    function writeCol($row, $col, $val, $format=0)
1293
    {
1077
    {
1294
        $retval = '';
1078
        if (is_array($val)) {
1295
        if (is_array($val)) {
1079
            foreach($val as $v) { 
1296
            foreach ($val as $v) {
1080
                $this->write($row, $col, $v, $format);
1297
                $this->write($row, $col, $v, $format);
Line 1093... Line 1310...
1093
    * @param mixed &$format The optional XF format
1310
    * @param mixed &$format The optional XF format
1094
    * @return integer The XF record index
1311
    * @return integer The XF record index
1095
    */
1312
    */
1096
    function _XF(&$format)
1313
    function _XF(&$format)
1097
    {
1314
    {
1098
        if ($format != 0) {
1315
        if ($format) {
1099
            return($format->getXfIndex());
1316
            return($format->getXfIndex());
1100
        }
-
 
1101
        else {
1317
        } else {
1102
            return(0x0F);
1318
            return(0x0F);
1103
        }
1319
        }
1104
    }
1320
    }
Line 1118... Line 1334...
1118
    * @access private
1334
    * @access private
1119
    * @param string $data The binary data to append
1335
    * @param string $data The binary data to append
1120
    */
1336
    */
1121
    function _append($data)
1337
    function _append($data)
1122
    {
1338
    {
1123
        if ($this->_using_tmpfile)
1339
        if ($this->_using_tmpfile) {
1124
        {
-
 
1125
            // Add CONTINUE records if necessary
1340
            // Add CONTINUE records if necessary
1126
            if (strlen($data) > $this->_limit) {
1341
            if (strlen($data) > $this->_limit) {
1127
                $data = $this->_addContinue($data);
1342
                $data = $this->_addContinue($data);
1128
            }
1343
            }
1129
            fwrite($this->_filehandle,$data);
1344
            fwrite($this->_filehandle, $data);
1130
            $this->_datasize += strlen($data);
1345
            $this->_datasize += strlen($data);
1131
        }
-
 
1132
        else {
1346
        } else {
1133
            parent::_append($data);
1347
            parent::_append($data);
1134
        }
1348
        }
1135
    }
1349
    }
Line 1136... Line 1350...
1136
    
1350
 
Line 1216... Line 1430...
1216
        $password = 0x0000;
1430
        $password = 0x0000;
1217
        $i        = 1;       // char position
1431
        $i        = 1;       // char position
Line 1218... Line 1432...
1218
 
1432
 
1219
        // split the plain text password in its component characters
1433
        // split the plain text password in its component characters
1220
        $chars = preg_split('//', $plaintext, -1, PREG_SPLIT_NO_EMPTY);
1434
        $chars = preg_split('//', $plaintext, -1, PREG_SPLIT_NO_EMPTY);
1221
        foreach($chars as $char)
-
 
1222
        {
1435
        foreach ($chars as $char) {
1223
            $value        = ord($char) << $i;   // shifted ASCII value 
1436
            $value        = ord($char) << $i;   // shifted ASCII value
1224
            $rotated_bits = $value >> 15;       // rotated bits beyond bit 15
1437
            $rotated_bits = $value >> 15;       // rotated bits beyond bit 15
1225
            $value       &= 0x7fff;             // first 15 bits
1438
            $value       &= 0x7fff;             // first 15 bits
1226
            $password    ^= ($value | $rotated_bits);
1439
            $password    ^= ($value | $rotated_bits);
Line 1231... Line 1444...
1231
        $password ^= 0xCE4B;
1444
        $password ^= 0xCE4B;
Line 1232... Line 1445...
1232
 
1445
 
1233
        return($password);
1446
        return($password);
Line -... Line 1447...
-
 
1447
    }
-
 
1448
 
-
 
1449
    /**
-
 
1450
    * This method sets the properties for outlining and grouping. The defaults
-
 
1451
    * correspond to Excel's defaults.
-
 
1452
    *
-
 
1453
    * @param bool $visible
-
 
1454
    * @param bool $symbols_below
-
 
1455
    * @param bool $symbols_right
-
 
1456
    * @param bool $auto_style
-
 
1457
    */
-
 
1458
    function setOutline($visible = true, $symbols_below = true, $symbols_right = true, $auto_style = false)
-
 
1459
    {
-
 
1460
        $this->_outline_on    = $visible;
-
 
1461
        $this->_outline_below = $symbols_below;
-
 
1462
        $this->_outline_right = $symbols_right;
-
 
1463
        $this->_outline_style = $auto_style;
-
 
1464
 
-
 
1465
        // Ensure this is a boolean vale for Window2
-
 
1466
        if ($this->_outline_on) {
-
 
1467
            $this->_outline_on = 1;
-
 
1468
        }
-
 
1469
     }
-
 
1470
 
-
 
1471
    /**
-
 
1472
    * This method sets the worksheet direction to right-to-left (RTL)
-
 
1473
    *
-
 
1474
    * @param bool $rtl
-
 
1475
    */
-
 
1476
    function setRTL($rtl = true)
-
 
1477
    {
Line 1234... Line 1478...
1234
    }
1478
        $this->_Arabic = ($rtl ? 1 : 0);
1235
 
1479
     }
1236
    
1480
 
1237
    /******************************************************************************
1481
    /******************************************************************************
Line 1254... Line 1498...
1254
    * @param integer $col    Zero indexed column
1498
    * @param integer $col    Zero indexed column
1255
    * @param float   $num    The number to write
1499
    * @param float   $num    The number to write
1256
    * @param mixed   $format The optional XF format
1500
    * @param mixed   $format The optional XF format
1257
    * @return integer
1501
    * @return integer
1258
    */
1502
    */
1259
    function writeNumber($row, $col, $num, $format = 0)
1503
    function writeNumber($row, $col, $num, $format = null)
1260
    {
1504
    {
1261
        $record    = 0x0203;                 // Record identifier
1505
        $record    = 0x0203;                 // Record identifier
1262
        $length    = 0x000E;                 // Number of bytes to follow
1506
        $length    = 0x000E;                 // Number of bytes to follow
Line 1263... Line 1507...
1263
    
1507
 
Line 1264... Line 1508...
1264
        $xf        = $this->_XF($format);    // The cell format
1508
        $xf        = $this->_XF($format);    // The cell format
1265
    
1509
 
1266
        // Check that row and col are valid and store max and min values
-
 
1267
        if ($row >= $this->_xls_rowmax)
1510
        // Check that row and col are valid and store max and min values
1268
        {
1511
        if ($row >= $this->_xls_rowmax) {
1269
            return(-2);
1512
            return(-2);
1270
        }
-
 
1271
        if ($col >= $this->_xls_colmax)
1513
        }
1272
        {
1514
        if ($col >= $this->_xls_colmax) {
1273
            return(-2);
1515
            return(-2);
1274
        }
-
 
1275
        if ($row <  $this->_dim_rowmin) 
1516
        }
1276
        {
1517
        if ($row <  $this->_dim_rowmin)  {
1277
            $this->_dim_rowmin = $row;
1518
            $this->_dim_rowmin = $row;
1278
        }
-
 
1279
        if ($row >  $this->_dim_rowmax) 
1519
        }
1280
        {
1520
        if ($row >  $this->_dim_rowmax)  {
1281
            $this->_dim_rowmax = $row;
1521
            $this->_dim_rowmax = $row;
1282
        }
-
 
1283
        if ($col <  $this->_dim_colmin) 
1522
        }
1284
        {
1523
        if ($col <  $this->_dim_colmin)  {
1285
            $this->_dim_colmin = $col;
1524
            $this->_dim_colmin = $col;
1286
        }
-
 
1287
        if ($col >  $this->_dim_colmax) 
1525
        }
1288
        {
1526
        if ($col >  $this->_dim_colmax)  {
Line 1289... Line 1527...
1289
            $this->_dim_colmax = $col;
1527
            $this->_dim_colmax = $col;
1290
        }
1528
        }
1291
    
1529
 
1292
        $header    = pack("vv",  $record, $length);
1530
        $header    = pack("vv",  $record, $length);
1293
        $data      = pack("vvv", $row, $col, $xf);
-
 
1294
        $xl_double = pack("d",   $num);
1531
        $data      = pack("vvv", $row, $col, $xf);
1295
        if ($this->_byte_order) // if it's Big Endian
1532
        $xl_double = pack("d",   $num);
Line 1296... Line 1533...
1296
        {
1533
        if ($this->_byte_order) { // if it's Big Endian
1297
            $xl_double = strrev($xl_double);
1534
            $xl_double = strrev($xl_double);
Line 1314... Line 1551...
1314
    * @param integer $col    Zero indexed column
1551
    * @param integer $col    Zero indexed column
1315
    * @param string  $str    The string to write
1552
    * @param string  $str    The string to write
1316
    * @param mixed   $format The XF format for the cell
1553
    * @param mixed   $format The XF format for the cell
1317
    * @return integer
1554
    * @return integer
1318
    */
1555
    */
1319
    function writeString($row, $col, $str, $format = 0)
1556
    function writeString($row, $col, $str, $format = null)
1320
    {
1557
    {
-
 
1558
        if ($this->_BIFF_version == 0x0600) {
-
 
1559
            return $this->writeStringBIFF8($row, $col, $str, $format);
-
 
1560
        }
1321
        $strlen    = strlen($str);
1561
        $strlen    = strlen($str);
1322
        $record    = 0x0204;                   // Record identifier
1562
        $record    = 0x0204;                   // Record identifier
1323
        $length    = 0x0008 + $strlen;         // Bytes to follow
1563
        $length    = 0x0008 + $strlen;         // Bytes to follow
1324
        $xf        = $this->_XF($format);      // The cell format
1564
        $xf        = $this->_XF($format);      // The cell format
Line 1325... Line 1565...
1325
        
1565
 
Line 1326... Line 1566...
1326
        $str_error = 0;
1566
        $str_error = 0;
1327
    
1567
 
1328
        // Check that row and col are valid and store max and min values
-
 
1329
        if ($row >= $this->_xls_rowmax) 
1568
        // Check that row and col are valid and store max and min values
1330
        {
1569
        if ($row >= $this->_xls_rowmax) {
1331
            return(-2);
1570
            return(-2);
1332
        }
-
 
1333
        if ($col >= $this->_xls_colmax) 
1571
        }
1334
        {
1572
        if ($col >= $this->_xls_colmax) {
1335
            return(-2);
1573
            return(-2);
1336
        }
-
 
1337
        if ($row <  $this->_dim_rowmin) 
1574
        }
1338
        {
1575
        if ($row <  $this->_dim_rowmin) {
1339
            $this->_dim_rowmin = $row;
1576
            $this->_dim_rowmin = $row;
1340
        }
-
 
1341
        if ($row >  $this->_dim_rowmax) 
1577
        }
1342
        {
1578
        if ($row >  $this->_dim_rowmax) {
1343
            $this->_dim_rowmax = $row;
1579
            $this->_dim_rowmax = $row;
1344
        }
-
 
1345
        if ($col <  $this->_dim_colmin) 
1580
        }
1346
        {
1581
        if ($col <  $this->_dim_colmin) {
1347
            $this->_dim_colmin = $col;
1582
            $this->_dim_colmin = $col;
1348
        }
-
 
1349
        if ($col >  $this->_dim_colmax) 
1583
        }
1350
        {
1584
        if ($col >  $this->_dim_colmax) {
Line 1351... Line 1585...
1351
            $this->_dim_colmax = $col;
1585
            $this->_dim_colmax = $col;
1352
        }
-
 
1353
    
1586
        }
1354
        if ($strlen > $this->_xls_strmax)  // LABEL must be < 255 chars
1587
 
1355
        {
1588
        if ($strlen > $this->_xls_strmax) { // LABEL must be < 255 chars
1356
            $str       = substr($str, 0, $this->_xls_strmax);
1589
            $str       = substr($str, 0, $this->_xls_strmax);
1357
            $length    = 0x0008 + $this->_xls_strmax;
1590
            $length    = 0x0008 + $this->_xls_strmax;
Line 1364... Line 1597...
1364
        $this->_append($header.$data.$str);
1597
        $this->_append($header . $data . $str);
1365
        return($str_error);
1598
        return($str_error);
1366
    }
1599
    }
Line 1367... Line 1600...
1367
 
1600
 
-
 
1601
    /**
-
 
1602
    * Sets Input Encoding for writing strings
-
 
1603
    *
-
 
1604
    * @access public
-
 
1605
    * @param string $encoding The encoding. Ex: 'UTF-16LE', 'utf-8', 'ISO-859-7'
-
 
1606
    */
-
 
1607
    function setInputEncoding($encoding)
-
 
1608
    {
-
 
1609
         if ($encoding != 'UTF-16LE' && !function_exists('iconv')) {
-
 
1610
             $this->raiseError("Using an input encoding other than UTF-16LE requires PHP support for iconv");
-
 
1611
         }
-
 
1612
         $this->_input_encoding = $encoding;
-
 
1613
    }
-
 
1614
 
-
 
1615
    /**
-
 
1616
    * Write a string to the specified row and column (zero indexed).
-
 
1617
    * This is the BIFF8 version (no 255 chars limit).
-
 
1618
    * $format is optional.
-
 
1619
    * Returns  0 : normal termination
-
 
1620
    *         -2 : row or column out of range
-
 
1621
    *         -3 : long string truncated to 255 chars
-
 
1622
    *
-
 
1623
    * @access public
-
 
1624
    * @param integer $row    Zero indexed row
-
 
1625
    * @param integer $col    Zero indexed column
-
 
1626
    * @param string  $str    The string to write
-
 
1627
    * @param mixed   $format The XF format for the cell
-
 
1628
    * @return integer
-
 
1629
    */
-
 
1630
    function writeStringBIFF8($row, $col, $str, $format = null)
-
 
1631
    {
-
 
1632
        if ($this->_input_encoding == 'UTF-16LE')
-
 
1633
        {
-
 
1634
            $strlen = function_exists('mb_strlen') ? mb_strlen($str, 'UTF-16LE') : (strlen($str) / 2);
-
 
1635
            $encoding  = 0x1;
-
 
1636
        }
-
 
1637
        elseif ($this->_input_encoding != '')
-
 
1638
        {
-
 
1639
            $str = iconv($this->_input_encoding, 'UTF-16LE', $str);
-
 
1640
            $strlen = function_exists('mb_strlen') ? mb_strlen($str, 'UTF-16LE') : (strlen($str) / 2);
-
 
1641
            $encoding  = 0x1;
-
 
1642
        }
-
 
1643
        else
-
 
1644
        {
-
 
1645
            $strlen    = strlen($str);
-
 
1646
            $encoding  = 0x0;
-
 
1647
        }
-
 
1648
        $record    = 0x00FD;                   // Record identifier
-
 
1649
        $length    = 0x000A;                   // Bytes to follow
-
 
1650
        $xf        = $this->_XF($format);      // The cell format
-
 
1651
 
-
 
1652
        $str_error = 0;
-
 
1653
 
-
 
1654
        // Check that row and col are valid and store max and min values
-
 
1655
        if ($this->_checkRowCol($row, $col) == false) {
-
 
1656
            return -2;
-
 
1657
        }
-
 
1658
 
-
 
1659
        $str = pack('vC', $strlen, $encoding).$str;
-
 
1660
 
-
 
1661
        /* check if string is already present */
-
 
1662
        if (!isset($this->_str_table[$str])) {
-
 
1663
            $this->_str_table[$str] = $this->_str_unique++;
-
 
1664
        }
-
 
1665
        $this->_str_total++;
-
 
1666
 
-
 
1667
        $header    = pack('vv',   $record, $length);
-
 
1668
        $data      = pack('vvvV', $row, $col, $xf, $this->_str_table[$str]);
-
 
1669
        $this->_append($header.$data);
-
 
1670
        return $str_error;
-
 
1671
    }
-
 
1672
 
-
 
1673
    /**
-
 
1674
    * Check row and col before writing to a cell, and update the sheet's
-
 
1675
    * dimensions accordingly
-
 
1676
    *
-
 
1677
    * @access private
-
 
1678
    * @param integer $row    Zero indexed row
-
 
1679
    * @param integer $col    Zero indexed column
-
 
1680
    * @return boolean true for success, false if row and/or col are grester
-
 
1681
    *                 then maximums allowed.
-
 
1682
    */
-
 
1683
    function _checkRowCol($row, $col)
-
 
1684
    {
-
 
1685
        if ($row >= $this->_xls_rowmax) {
-
 
1686
            return false;
-
 
1687
        }
-
 
1688
        if ($col >= $this->_xls_colmax) {
-
 
1689
            return false;
-
 
1690
        }
-
 
1691
        if ($row <  $this->_dim_rowmin) {
-
 
1692
            $this->_dim_rowmin = $row;
-
 
1693
        }
-
 
1694
        if ($row >  $this->_dim_rowmax) {
-
 
1695
            $this->_dim_rowmax = $row;
-
 
1696
        }
-
 
1697
        if ($col <  $this->_dim_colmin) {
-
 
1698
            $this->_dim_colmin = $col;
-
 
1699
        }
-
 
1700
        if ($col >  $this->_dim_colmax) {
-
 
1701
            $this->_dim_colmax = $col;
-
 
1702
        }
-
 
1703
        return true;
-
 
1704
    }
-
 
1705
 
1368
    /**
1706
    /**
1369
    * Writes a note associated with the cell given by the row and column.
1707
    * Writes a note associated with the cell given by the row and column.
1370
    * NOTE records don't have a length limit.
1708
    * NOTE records don't have a length limit.
1371
    *
1709
    *
1372
    * @access public
1710
    * @access public
Line 1380... Line 1718...
1380
        $record         = 0x001C;                // Record identifier
1718
        $record         = 0x001C;                // Record identifier
1381
        $max_length     = 2048;                  // Maximun length for a NOTE record
1719
        $max_length     = 2048;                  // Maximun length for a NOTE record
1382
        //$length      = 0x0006 + $note_length;    // Bytes to follow
1720
        //$length      = 0x0006 + $note_length;    // Bytes to follow
Line 1383... Line 1721...
1383
 
1721
 
1384
        // Check that row and col are valid and store max and min values
1722
        // Check that row and col are valid and store max and min values
1385
        if ($row >= $this->_xls_rowmax) 
-
 
1386
        {
1723
        if ($row >= $this->_xls_rowmax) {
1387
            return(-2);
1724
            return(-2);
1388
        }
1725
        }
1389
        if ($col >= $this->_xls_colmax) 
-
 
1390
        {
1726
        if ($col >= $this->_xls_colmax) {
1391
            return(-2);
1727
            return(-2);
1392
        }
1728
        }
1393
        if ($row <  $this->_dim_rowmin) 
-
 
1394
        {
1729
        if ($row <  $this->_dim_rowmin) {
1395
            $this->_dim_rowmin = $row;
1730
            $this->_dim_rowmin = $row;
1396
        }
1731
        }
1397
        if ($row >  $this->_dim_rowmax) 
-
 
1398
        {
1732
        if ($row >  $this->_dim_rowmax) {
1399
            $this->_dim_rowmax = $row;
1733
            $this->_dim_rowmax = $row;
1400
        }
1734
        }
1401
        if ($col <  $this->_dim_colmin) 
-
 
1402
        {
1735
        if ($col <  $this->_dim_colmin) {
1403
            $this->_dim_colmin = $col;
1736
            $this->_dim_colmin = $col;
1404
        }
1737
        }
1405
        if ($col >  $this->_dim_colmax) 
-
 
1406
        {
1738
        if ($col >  $this->_dim_colmax) {
1407
            $this->_dim_colmax = $col;
1739
            $this->_dim_colmax = $col;
Line 1408... Line 1740...
1408
        }
1740
        }
1409
 
1741
 
1410
        // Length for this record is no more than 2048 + 6
1742
        // Length for this record is no more than 2048 + 6
1411
        $length    = 0x0006 + min($note_length, 2048);
1743
        $length    = 0x0006 + min($note_length, 2048);
1412
        $header    = pack("vv",   $record, $length);
1744
        $header    = pack("vv",   $record, $length);
Line 1413... Line 1745...
1413
        $data      = pack("vvv", $row, $col, $note_length);
1745
        $data      = pack("vvv", $row, $col, $note_length);
1414
        $this->_append($header.$data.substr($note, 0, 2048));
-
 
1415
 
1746
        $this->_append($header . $data . substr($note, 0, 2048));
1416
        for($i = $max_length; $i < $note_length; $i += $max_length)
1747
 
1417
        {
1748
        for ($i = $max_length; $i < $note_length; $i += $max_length) {
1418
            $chunk  = substr($note, $i, $max_length);
1749
            $chunk  = substr($note, $i, $max_length);
1419
            $length = 0x0006 + strlen($chunk);
1750
            $length = 0x0006 + strlen($chunk);
Line 1442... Line 1773...
1442
    * @param mixed   $format The XF format
1773
    * @param mixed   $format The XF format
1443
    */
1774
    */
1444
    function writeBlank($row, $col, $format)
1775
    function writeBlank($row, $col, $format)
1445
    {
1776
    {
1446
        // Don't write a blank cell unless it has a format
1777
        // Don't write a blank cell unless it has a format
1447
        if ($format == 0)
1778
        if (!$format) {
1448
        {
-
 
1449
            return(0);
1779
            return(0);
1450
        }
1780
        }
Line 1451... Line 1781...
1451
    
1781
 
1452
        $record    = 0x0201;                 // Record identifier
1782
        $record    = 0x0201;                 // Record identifier
1453
        $length    = 0x0006;                 // Number of bytes to follow
1783
        $length    = 0x0006;                 // Number of bytes to follow
Line 1454... Line 1784...
1454
        $xf        = $this->_XF($format);    // The cell format
1784
        $xf        = $this->_XF($format);    // The cell format
1455
    
1785
 
1456
        // Check that row and col are valid and store max and min values
-
 
1457
        if ($row >= $this->_xls_rowmax) 
1786
        // Check that row and col are valid and store max and min values
1458
        {
1787
        if ($row >= $this->_xls_rowmax) {
1459
            return(-2);
1788
            return(-2);
1460
        }
-
 
1461
        if ($col >= $this->_xls_colmax) 
1789
        }
1462
        {
1790
        if ($col >= $this->_xls_colmax) {
1463
            return(-2);
1791
            return(-2);
1464
        }
-
 
1465
        if ($row <  $this->_dim_rowmin) 
1792
        }
1466
        {
1793
        if ($row <  $this->_dim_rowmin) {
1467
            $this->_dim_rowmin = $row;
1794
            $this->_dim_rowmin = $row;
1468
        }
-
 
1469
        if ($row >  $this->_dim_rowmax) 
1795
        }
1470
        {
1796
        if ($row >  $this->_dim_rowmax) {
1471
            $this->_dim_rowmax = $row;
1797
            $this->_dim_rowmax = $row;
1472
        }
-
 
1473
        if ($col <  $this->_dim_colmin) 
1798
        }
1474
        {
1799
        if ($col <  $this->_dim_colmin) {
1475
            $this->_dim_colmin = $col;
1800
            $this->_dim_colmin = $col;
1476
        }
-
 
1477
        if ($col >  $this->_dim_colmax) 
1801
        }
1478
        {
1802
        if ($col >  $this->_dim_colmax) {
Line 1479... Line 1803...
1479
            $this->_dim_colmax = $col;
1803
            $this->_dim_colmax = $col;
1480
        }
1804
        }
Line 1499... Line 1823...
1499
    * @param integer $col     Zero indexed column
1823
    * @param integer $col     Zero indexed column
1500
    * @param string  $formula The formula text string
1824
    * @param string  $formula The formula text string
1501
    * @param mixed   $format  The optional XF format
1825
    * @param mixed   $format  The optional XF format
1502
    * @return integer
1826
    * @return integer
1503
    */
1827
    */
1504
    function writeFormula($row, $col, $formula, $format = 0)
1828
    function writeFormula($row, $col, $formula, $format = null)
1505
    {
1829
    {
1506
        $record    = 0x0006;     // Record identifier
1830
        $record    = 0x0006;     // Record identifier
Line 1507... Line 1831...
1507
    
1831
 
1508
        // Excel normally stores the last calculated value of the formula in $num.
1832
        // Excel normally stores the last calculated value of the formula in $num.
Line 1511... Line 1835...
1511
        // automatic calculation of the formula when the file is opened.
1835
        // automatic calculation of the formula when the file is opened.
1512
        //
1836
        //
1513
        $xf        = $this->_XF($format); // The cell format
1837
        $xf        = $this->_XF($format); // The cell format
1514
        $num       = 0x00;                // Current value of formula
1838
        $num       = 0x00;                // Current value of formula
1515
        $grbit     = 0x03;                // Option flags
1839
        $grbit     = 0x03;                // Option flags
1516
        $chn       = 0x0000;              // Must be zero
1840
        $unknown   = 0x0000;              // Must be zero
Line 1517... Line 1841...
1517
    
1841
 
1518
    
1842
 
1519
        // Check that row and col are valid and store max and min values
-
 
1520
        if ($row >= $this->_xls_rowmax)
1843
        // Check that row and col are valid and store max and min values
1521
        {
-
 
1522
            return(-2);
-
 
1523
        }
-
 
1524
        if ($col >= $this->_xls_colmax)
-
 
1525
        {
-
 
1526
            return(-2);
-
 
1527
        }
-
 
1528
        if ($row <  $this->_dim_rowmin) 
-
 
1529
        {
-
 
1530
            $this->_dim_rowmin = $row;
-
 
1531
        }
-
 
1532
        if ($row >  $this->_dim_rowmax) 
-
 
1533
        {
-
 
1534
            $this->_dim_rowmax = $row;
-
 
1535
        }
-
 
1536
        if ($col <  $this->_dim_colmin) 
-
 
1537
        {
-
 
1538
            $this->_dim_colmin = $col;
-
 
1539
        }
-
 
1540
        if ($col >  $this->_dim_colmax) 
-
 
1541
        {
1844
        if ($this->_checkRowCol($row, $col) == false) {
Line 1542... Line 1845...
1542
            $this->_dim_colmax = $col;
1845
            return -2;
1543
        }
1846
        }
1544
    
1847
 
1545
        // Strip the '=' or '@' sign at the beginning of the formula string
-
 
1546
        if (preg_match("/^=/",$formula)) {
1848
        // Strip the '=' or '@' sign at the beginning of the formula string
1547
            $formula = preg_replace("/(^=)/","",$formula);
1849
        if (preg_match("/^=/", $formula)) {
1548
        }
-
 
1549
        elseif (preg_match("/^@/",$formula)) {
1850
            $formula = preg_replace("/(^=)/", "", $formula);
1550
            $formula = preg_replace("/(^@)/","",$formula);
-
 
1551
        }
1851
        } elseif (preg_match("/^@/", $formula)) {
1552
        else
1852
            $formula = preg_replace("/(^@)/", "", $formula);
1553
        {
1853
        } else {
1554
            // Error handling
1854
            // Error handling
Line 1555... Line 1855...
1555
            $this->writeString($row, $col, 'Unrecognised character for formula');
1855
            $this->writeString($row, $col, 'Unrecognised character for formula');
1556
            return -1;
1856
            return -1;
1557
        }
1857
        }
1558
    
-
 
1559
        // Parse the formula using the parser in Parser.php
1858
 
1560
        $error = $this->_parser->parse($formula);
1859
        // Parse the formula using the parser in Parser.php
1561
        if ($this->isError($error))
1860
        $error = $this->_parser->parse($formula);
Line 1562... Line 1861...
1562
        {
1861
        if ($this->isError($error)) {
1563
            $this->writeString($row, $col, $error->getMessage()); 
1862
            $this->writeString($row, $col, $error->getMessage());
1564
            return -1;
-
 
1565
        }
1863
            return -1;
1566
    
1864
        }
1567
        $formula = $this->_parser->toReversePolish();
1865
 
Line 1568... Line 1866...
1568
        if ($this->isError($formula))
1866
        $formula = $this->_parser->toReversePolish();
1569
        {
1867
        if ($this->isError($formula)) {
Line 1570... Line 1868...
1570
            $this->writeString($row, $col, $formula->getMessage());
1868
            $this->writeString($row, $col, $formula->getMessage());
1571
            return -1;
1869
            return -1;
1572
        }
1870
        }
Line 1573... Line 1871...
1573
    
1871
 
1574
        $formlen    = strlen($formula);    // Length of the binary string
1872
        $formlen    = strlen($formula);    // Length of the binary string
1575
        $length     = 0x16 + $formlen;     // Length of the record data
1873
        $length     = 0x16 + $formlen;     // Length of the record data
Line 1603... Line 1901...
1603
    * @param string  $url    URL string
1901
    * @param string  $url    URL string
1604
    * @param string  $string Alternative label
1902
    * @param string  $string Alternative label
1605
    * @param mixed   $format The cell format
1903
    * @param mixed   $format The cell format
1606
    * @return integer
1904
    * @return integer
1607
    */
1905
    */
1608
    function writeUrl($row, $col, $url, $string = '', $format = 0)
1906
    function writeUrl($row, $col, $url, $string = '', $format = null)
1609
    {
1907
    {
1610
        // Add start row and col to arg list
1908
        // Add start row and col to arg list
1611
        return($this->_writeUrl_range($row, $col, $row, $col, $url, $string, $format));
1909
        return($this->_writeUrlRange($row, $col, $row, $col, $url, $string, $format));
1612
    }
1910
    }
Line 1613... Line 1911...
1613
    
1911
 
1614
    /**
1912
    /**
1615
    * This is the more general form of writeUrl(). It allows a hyperlink to be
1913
    * This is the more general form of writeUrl(). It allows a hyperlink to be
Line 1627... Line 1925...
1627
    * @param string  $string Alternative label
1925
    * @param string  $string Alternative label
1628
    * @param mixed   $format The cell format
1926
    * @param mixed   $format The cell format
1629
    * @return integer
1927
    * @return integer
1630
    */
1928
    */
Line 1631... Line 1929...
1631
    
1929
 
1632
    function _writeUrl_range($row1, $col1, $row2, $col2, $url, $string = '', $format = 0)
1930
    function _writeUrlRange($row1, $col1, $row2, $col2, $url, $string = '', $format = null)
Line 1633... Line 1931...
1633
    {
1931
    {
1634
    
1932
 
1635
        // Check for internal/external sheet links or default to web link
1933
        // Check for internal/external sheet links or default to web link
Line 1657... Line 1955...
1657
    * @param string  $url    URL string
1955
    * @param string  $url    URL string
1658
    * @param string  $str    Alternative label
1956
    * @param string  $str    Alternative label
1659
    * @param mixed   $format The cell format
1957
    * @param mixed   $format The cell format
1660
    * @return integer
1958
    * @return integer
1661
    */
1959
    */
1662
    function _writeUrlWeb($row1, $col1, $row2, $col2, $url, $str, $format = 0)
1960
    function _writeUrlWeb($row1, $col1, $row2, $col2, $url, $str, $format = null)
1663
    {
1961
    {
1664
        $record      = 0x01B8;                       // Record identifier
1962
        $record      = 0x01B8;                       // Record identifier
1665
        $length      = 0x00000;                      // Bytes to follow
1963
        $length      = 0x00000;                      // Bytes to follow
Line 1666... Line 1964...
1666
    
1964
 
1667
        if ($format == 0) {
1965
        if (!$format) {
1668
            $format = $this->_url_format;
1966
            $format = $this->_url_format;
Line 1669... Line 1967...
1669
        }
1967
        }
1670
    
1968
 
1671
        // Write the visible label using the writeString() method.
1969
        // Write the visible label using the writeString() method.
1672
        if ($str == '') {
1970
        if ($str == '') {
1673
            $str = $url;
1971
            $str = $url;
1674
        }
1972
        }
1675
        $str_error = $this->writeString($row1, $col1, $str, $format);
1973
        $str_error = is_numeric($str) ? $this->writeNumber($row1, $col1, $str, $format) : $this->writeString($row1, $col1, $str, $format);
1676
        if (($str_error == -2) or ($str_error == -3)) {
1974
        if (($str_error == -2) || ($str_error == -3)) {
Line 1677... Line 1975...
1677
            return $str_error;
1975
            return $str_error;
1678
        }
1976
        }
Line 1717... Line 2015...
1717
    * @param string  $url    URL string
2015
    * @param string  $url    URL string
1718
    * @param string  $str    Alternative label
2016
    * @param string  $str    Alternative label
1719
    * @param mixed   $format The cell format
2017
    * @param mixed   $format The cell format
1720
    * @return integer
2018
    * @return integer
1721
    */
2019
    */
1722
    function _writeUrlInternal($row1, $col1, $row2, $col2, $url, $str, $format = 0)
2020
    function _writeUrlInternal($row1, $col1, $row2, $col2, $url, $str, $format = null)
1723
    {
2021
    {
1724
        $record      = 0x01B8;                       // Record identifier
2022
        $record      = 0x01B8;                       // Record identifier
1725
        $length      = 0x00000;                      // Bytes to follow
2023
        $length      = 0x00000;                      // Bytes to follow
Line 1726... Line 2024...
1726
    
2024
 
1727
        if ($format == 0) {
2025
        if (!$format) {
1728
            $format = $this->_url_format;
2026
            $format = $this->_url_format;
Line 1729... Line 2027...
1729
        }
2027
        }
1730
    
2028
 
Line 1731... Line 2029...
1731
        // Strip URL type
2029
        // Strip URL type
1732
        $url = preg_replace('s[^internal:]', '', $url);
2030
        $url = preg_replace('/^internal:/', '', $url);
1733
    
2031
 
1734
        // Write the visible label
2032
        // Write the visible label
1735
        if ($str == '') {
2033
        if ($str == '') {
1736
            $str = $url;
2034
            $str = $url;
1737
        }
2035
        }
1738
        $str_error = $this->writeString($row1, $col1, $str, $format);
2036
        $str_error = is_numeric($str) ? $this->writeNumber($row1, $col1, $str, $format) : $this->writeString($row1, $col1, $str, $format);
Line 1739... Line 2037...
1739
        if (($str_error == -2) or ($str_error == -3)) {
2037
        if (($str_error == -2) || ($str_error == -3)) {
1740
            return $str_error;
2038
            return $str_error;
Line 1783... Line 2081...
1783
    * @param string  $url    URL string
2081
    * @param string  $url    URL string
1784
    * @param string  $str    Alternative label
2082
    * @param string  $str    Alternative label
1785
    * @param mixed   $format The cell format
2083
    * @param mixed   $format The cell format
1786
    * @return integer
2084
    * @return integer
1787
    */
2085
    */
1788
    function _writeUrlExternal($row1, $col1, $row2, $col2, $url, $str, $format = 0)
2086
    function _writeUrlExternal($row1, $col1, $row2, $col2, $url, $str, $format = null)
1789
    {
2087
    {
1790
        // Network drives are different. We will handle them separately
2088
        // Network drives are different. We will handle them separately
1791
        // MS/Novell network drives and shares start with \\
2089
        // MS/Novell network drives and shares start with \\
1792
        if (preg_match('[^external:\\\\]', $url)) {
2090
        if (preg_match('[^external:\\\\]', $url)) {
1793
            return; //($this->_writeUrlExternal_net($row1, $col1, $row2, $col2, $url, $str, $format));
2091
            return; //($this->_writeUrlExternal_net($row1, $col1, $row2, $col2, $url, $str, $format));
1794
        }
2092
        }
Line 1795... Line 2093...
1795
    
2093
    
1796
        $record      = 0x01B8;                       // Record identifier
2094
        $record      = 0x01B8;                       // Record identifier
Line 1797... Line 2095...
1797
        $length      = 0x00000;                      // Bytes to follow
2095
        $length      = 0x00000;                      // Bytes to follow
1798
    
2096
    
1799
        if ($format == 0) {
2097
        if (!$format) {
Line 1800... Line 2098...
1800
            $format = $this->_url_format;
2098
            $format = $this->_url_format;
1801
        }
2099
        }
1802
    
2100
    
1803
        // Strip URL type and change Unix dir separator to Dos style (if needed)
2101
        // Strip URL type and change Unix dir separator to Dos style (if needed)
Line 1804... Line 2102...
1804
        //
2102
        //
1805
        $url = preg_replace('[^external:]', '', $url);
2103
        $url = preg_replace('/^external:/', '', $url);
1806
        $url = preg_replace('[/]', "\\", $url);
2104
        $url = preg_replace('/\//', "\\", $url);
1807
    
2105
    
1808
        // Write the visible label
2106
        // Write the visible label
1809
        if ($str == '') {
2107
        if ($str == '') {
1810
            $str = preg_replace('[\#]', ' - ', $url);
2108
            $str = preg_replace('/\#/', ' - ', $url);
1811
        }
2109
        }
Line 1812... Line 2110...
1812
        $str_error = $this->writeString($row1, $col1, $str, $format);
2110
        $str_error = is_numeric($str) ? $this->writeNumber($row1, $col1, $str, $format) : $this->writeString($row1, $col1, $str, $format);
1813
        if (($str_error == -2) or ($str_error == -3)) {
2111
        if (($str_error == -2) or ($str_error == -3)) {
1814
            return $str_error;
2112
            return $str_error;
1815
        }
2113
        }
Line 1816... Line 2114...
1816
    
2114
    
1817
        // Determine if the link is relative or absolute:
2115
        // Determine if the link is relative or absolute:
1818
        //   relative if link contains no dir separator, "somefile.xls"
2116
        //   relative if link contains no dir separator, "somefile.xls"
1819
        //   relative if link starts with up-dir, "..\..\somefile.xls"
2117
        //   relative if link starts with up-dir, "..\..\somefile.xls"
1820
        //   otherwise, absolute
2118
        //   otherwise, absolute
1821
        
2119
        
1822
        $absolute    = 0x02; // Bit mask
2120
        $absolute    = 0x02; // Bit mask
-
 
2121
        if (!preg_match("/\\\/", $url)) {
Line 1823... Line 2122...
1823
        if (!preg_match('[\\]', $url)) {
2122
            $absolute    = 0x00;
1824
            $absolute    = 0x00;
2123
        }
1825
        }
2124
        if (preg_match("/^\.\.\\\/", $url)) {
-
 
2125
            $absolute    = 0x00;
1826
        if (preg_match('[^\.\.\\]', $url)) {
2126
        }
-
 
2127
        $link_type               = 0x01 | $absolute;
1827
            $absolute    = 0x00;
2128
    
-
 
2129
        // Determine if the link contains a sheet reference and change some of the
Line 1828... Line 2130...
1828
        }
2130
        // parameters accordingly.
1829
    
2131
        // Split the dir name and sheet name (if it exists)
1830
        // Determine if the link contains a sheet reference and change some of the
2132
        /*if (preg_match("/\#/", $url)) {
1831
        // parameters accordingly.
2133
            list($dir_long, $sheet) = split("\#", $url);
1832
        // Split the dir name and sheet name (if it exists)
2134
        } else {
1833
        list($dir_long , $sheet) = explode('/\#/', $url);
-
 
1834
        $link_type               = 0x01 | $absolute;
2135
            $dir_long = $url;
1835
    
2136
        }
1836
        if (isset($sheet)) {
2137
    
-
 
2138
        if (isset($sheet)) {
-
 
2139
            $link_type |= 0x08;
-
 
2140
            $sheet_len  = pack("V", strlen($sheet) + 0x01);
-
 
2141
            $sheet      = join("\0", split('', $sheet));
1837
            $link_type |= 0x08;
2142
            $sheet     .= "\0\0\0";
Line -... Line 2143...
-
 
2143
        } else {
-
 
2144
            $sheet_len   = '';
1838
            $sheet_len  = pack("V", strlen($sheet) + 0x01);
2145
            $sheet       = '';
1839
            $sheet      = join("\0", explode('', $sheet));
2146
        }*/
Line 1840... Line 2147...
1840
            $sheet     .= "\0\0\0";
2147
        $dir_long = $url;
1841
        }
2148
        if (preg_match("/\#/", $url)) {
1842
        else {
2149
            $link_type |= 0x08;
Line 1843... Line 2150...
1843
            $sheet_len   = '';
2150
        }
1844
            $sheet       = '';
2151
 
Line 1845... Line 2152...
1845
        }
2152
 
1846
    
2153
    
1847
        // Pack the link type
2154
        // Pack the link type
Line 1848... Line 2155...
1848
        $link_type   = pack("V", $link_type);
2155
        $link_type   = pack("V", $link_type);
1849
    
2156
    
1850
        // Calculate the up-level dir count e.g.. (..\..\..\ == 3)
2157
        // Calculate the up-level dir count e.g.. (..\..\..\ == 3)
1851
        $up_count    = preg_match_all("/\.\.\\/", $dir_long, $useless);
2158
        $up_count    = preg_match_all("/\.\.\\\/", $dir_long, $useless);
Line 1852... Line 2159...
1852
        $up_count    = pack("v", $up_count);
2159
        $up_count    = pack("v", $up_count);
1853
    
2160
    
1854
        // Store the short dos dir name (null terminated)
2161
        // Store the short dos dir name (null terminated)
1855
        $dir_short   = preg_replace('/\.\.\\/', '', $dir_long) . "\0";
2162
        $dir_short   = preg_replace("/\.\.\\\/", '', $dir_long) . "\0";
Line 1876... Line 2183...
1876
                          $unknown2     .
2183
                          $unknown2     .
1877
                          $up_count     .
2184
                          $up_count     .
1878
                          $dir_short_len.
2185
                          $dir_short_len.
1879
                          $dir_short    .
2186
                          $dir_short    .
1880
                          $unknown3     .
2187
                          $unknown3     .
1881
                          $stream_len   .
2188
                          $stream_len   ;/*.
1882
                          $dir_long_len .
2189
                          $dir_long_len .
1883
                          $unknown4     .
2190
                          $unknown4     .
1884
                          $dir_long     .
2191
                          $dir_long     .
1885
                          $sheet_len    .
2192
                          $sheet_len    .
1886
                          $sheet        ;
2193
                          $sheet        ;*/
Line 1887... Line 2194...
1887
    
2194
    
1888
        // Pack the header data
2195
        // Pack the header data
1889
        $length   = strlen($data);
2196
        $length   = strlen($data);
Line 1899... Line 2206...
1899
    * This method is used to set the height and format for a row.
2206
    * This method is used to set the height and format for a row.
1900
    *
2207
    *
1901
    * @access public
2208
    * @access public
1902
    * @param integer $row    The row to set
2209
    * @param integer $row    The row to set
1903
    * @param integer $height Height we are giving to the row. 
2210
    * @param integer $height Height we are giving to the row.
1904
    *                        Use NULL to set XF without setting height
2211
    *                        Use null to set XF without setting height
1905
    * @param mixed   $format XF format we are giving to the row
2212
    * @param mixed   $format XF format we are giving to the row
-
 
2213
    * @param bool    $hidden The optional hidden attribute
-
 
2214
    * @param integer $level  The optional outline level for row, in range [0,7]
1906
    */
2215
    */
1907
    function setRow($row, $height, $format = 0)
2216
    function setRow($row, $height, $format = null, $hidden = false, $level = 0)
1908
    {
2217
    {
1909
        $record      = 0x0208;               // Record identifier
2218
        $record      = 0x0208;               // Record identifier
1910
        $length      = 0x0010;               // Number of bytes to follow
2219
        $length      = 0x0010;               // Number of bytes to follow
Line 1911... Line 2220...
1911
    
2220
 
1912
        $colMic      = 0x0000;               // First defined column
2221
        $colMic      = 0x0000;               // First defined column
1913
        $colMac      = 0x0000;               // Last defined column
2222
        $colMac      = 0x0000;               // Last defined column
1914
        $irwMac      = 0x0000;               // Used by Excel to optimise loading
2223
        $irwMac      = 0x0000;               // Used by Excel to optimise loading
1915
        $reserved    = 0x0000;               // Reserved
2224
        $reserved    = 0x0000;               // Reserved
1916
        $grbit       = 0x01C0;               // Option flags. (monkey) see $1 do
2225
        $grbit       = 0x0000;               // Option flags
Line -... Line 2226...
-
 
2226
        $ixfe        = $this->_XF($format);  // XF index
-
 
2227
 
-
 
2228
        // set _row_sizes so _sizeRow() can use it
1917
        $ixfe        = $this->_XF($format);  // XF index
2229
        $this->_row_sizes[$row] = $height;
1918
    
2230
 
1919
        // Use setRow($row, NULL, $XF) to set XF format without setting height
2231
        // Use setRow($row, null, $XF) to set XF format without setting height
1920
        if ($height != NULL) {
-
 
1921
            $miyRw = $height * 20;  // row height
2232
        if ($height != null) {
1922
        }
2233
            $miyRw = $height * 20;  // row height
1923
        else {
2234
        } else {
Line -... Line 2235...
-
 
2235
            $miyRw = 0xff;          // default row height is 256
-
 
2236
        }
-
 
2237
 
-
 
2238
        $level = max(0, min($level, 7));  // level should be between 0 and 7
-
 
2239
        $this->_outline_row_level = max($level, $this->_outline_row_level);
-
 
2240
 
-
 
2241
 
-
 
2242
        // Set the options flags. fUnsynced is used to show that the font and row
-
 
2243
        // heights are not compatible. This is usually the case for WriteExcel.
-
 
2244
        // The collapsed flag 0x10 doesn't seem to be used to indicate that a row
-
 
2245
        // is collapsed. Instead it is used to indicate that the previous row is
-
 
2246
        // collapsed. The zero height flag, 0x20, is used to collapse a row.
-
 
2247
 
-
 
2248
        $grbit |= $level;
-
 
2249
        if ($hidden) {
-
 
2250
            $grbit |= 0x0020;
-
 
2251
        }
-
 
2252
        $grbit |= 0x0040; // fUnsynced
-
 
2253
        if ($format) {
-
 
2254
            $grbit |= 0x0080;
1924
            $miyRw = 0xff;          // default row height is 256
2255
        }
1925
        }
2256
        $grbit |= 0x0100;
1926
    
2257
 
1927
        $header   = pack("vv",       $record, $length);
2258
        $header   = pack("vv",       $record, $length);
1928
        $data     = pack("vvvvvvvv", $row, $colMic, $colMac, $miyRw,
2259
        $data     = pack("vvvvvvvv", $row, $colMic, $colMac, $miyRw,
Line 1933... Line 2264...
1933
    /**
2264
    /**
1934
    * Writes Excel DIMENSIONS to define the area in which there is data.
2265
    * Writes Excel DIMENSIONS to define the area in which there is data.
1935
    *
2266
    *
1936
    * @access private
2267
    * @access private
1937
    */
2268
    */
1938
    function storeDimensions()
2269
    function _storeDimensions()
1939
    {
2270
    {
1940
        $record    = 0x0000;               // Record identifier
2271
        $record    = 0x0200;                 // Record identifier
1941
        $length    = 0x000A;               // Number of bytes to follow
-
 
1942
        $row_min   = $this->_dim_rowmin;   // First row
2272
        $row_min   = $this->_dim_rowmin;     // First row
1943
        $row_max   = $this->_dim_rowmax;   // Last row plus 1
2273
        $row_max   = $this->_dim_rowmax + 1; // Last row plus 1
1944
        $col_min   = $this->_dim_colmin;   // First column
2274
        $col_min   = $this->_dim_colmin;     // First column
1945
        $col_max   = $this->_dim_colmax;   // Last column plus 1
2275
        $col_max   = $this->_dim_colmax + 1; // Last column plus 1
1946
        $reserved  = 0x0000;               // Reserved by Excel
2276
        $reserved  = 0x0000;                 // Reserved by Excel
Line -... Line 2277...
-
 
2277
 
1947
    
2278
        if ($this->_BIFF_version == 0x0500) {
1948
        $header    = pack("vv",    $record, $length);
2279
            $length    = 0x000A;               // Number of bytes to follow
1949
        $data      = pack("vvvvv", $row_min, $row_max,
2280
            $data      = pack("vvvvv", $row_min, $row_max,
-
 
2281
                                       $col_min, $col_max, $reserved);
-
 
2282
        } elseif ($this->_BIFF_version == 0x0600) {
-
 
2283
            $length    = 0x000E;
-
 
2284
            $data      = pack("VVvvv", $row_min, $row_max,
-
 
2285
                                       $col_min, $col_max, $reserved);
-
 
2286
        }
1950
                                   $col_min, $col_max, $reserved);
2287
        $header = pack("vv", $record, $length);
1951
        $this->_prepend($header.$data);
2288
        $this->_prepend($header.$data);
Line 1952... Line 2289...
1952
    }
2289
    }
1953
    
2290
 
Line 1957... Line 2294...
1957
    * @access private
2294
    * @access private
1958
    */
2295
    */
1959
    function _storeWindow2()
2296
    function _storeWindow2()
1960
    {
2297
    {
1961
        $record         = 0x023E;     // Record identifier
2298
        $record         = 0x023E;     // Record identifier
-
 
2299
        if ($this->_BIFF_version == 0x0500) {
1962
        $length         = 0x000A;     // Number of bytes to follow
2300
            $length         = 0x000A;     // Number of bytes to follow
-
 
2301
        } elseif ($this->_BIFF_version == 0x0600) {
-
 
2302
            $length         = 0x0012;
-
 
2303
        }
Line 1963... Line 2304...
1963
    
2304
 
1964
        $grbit          = 0x00B6;     // Option flags
2305
        $grbit          = 0x00B6;     // Option flags
1965
        $rwTop          = 0x0000;     // Top row visible in window
2306
        $rwTop          = 0x0000;     // Top row visible in window
1966
        $colLeft        = 0x0000;     // Leftmost column visible in window
-
 
-
 
2307
        $colLeft        = 0x0000;     // Leftmost column visible in window
Line 1967... Line 2308...
1967
        $rgbHdr         = 0x00000000; // Row/column heading and gridline color
2308
 
1968
    
2309
 
1969
        // The options flags that comprise $grbit
2310
        // The options flags that comprise $grbit
1970
        $fDspFmla       = 0;                     // 0 - bit
2311
        $fDspFmla       = 0;                     // 0 - bit
1971
        $fDspGrid       = 1;                     // 1
2312
        $fDspGrid       = $this->_screen_gridlines; // 1
1972
        $fDspRwCol      = 1;                     // 2
2313
        $fDspRwCol      = 1;                     // 2
1973
        $fFrozen        = $this->_frozen;        // 3
2314
        $fFrozen        = $this->_frozen;        // 3
1974
        $fDspZeros      = 1;                     // 4
2315
        $fDspZeros      = 1;                     // 4
1975
        $fDefaultHdr    = 1;                     // 5
2316
        $fDefaultHdr    = 1;                     // 5
1976
        $fArabic        = 0;                     // 6
2317
        $fArabic        = $this->_Arabic;        // 6
1977
        $fDspGuts       = 1;                     // 7
2318
        $fDspGuts       = $this->_outline_on;    // 7
1978
        $fFrozenNoSplit = 0;                     // 0 - bit
2319
        $fFrozenNoSplit = 0;                     // 0 - bit
Line 1979... Line 2320...
1979
        $fSelected      = $this->selected;       // 1
2320
        $fSelected      = $this->selected;       // 1
Line 1990... Line 2331...
1990
        $grbit            |= $fFrozenNoSplit << 8;
2331
        $grbit            |= $fFrozenNoSplit << 8;
1991
        $grbit            |= $fSelected      << 9;
2332
        $grbit            |= $fSelected      << 9;
1992
        $grbit            |= $fPaged         << 10;
2333
        $grbit            |= $fPaged         << 10;
Line 1993... Line 2334...
1993
    
2334
 
1994
        $header  = pack("vv",   $record, $length);
2335
        $header  = pack("vv",   $record, $length);
-
 
2336
        $data    = pack("vvv", $grbit, $rwTop, $colLeft);
-
 
2337
        // FIXME !!!
-
 
2338
        if ($this->_BIFF_version == 0x0500) {
-
 
2339
            $rgbHdr         = 0x00000000; // Row/column heading and gridline color
-
 
2340
            $data .= pack("V", $rgbHdr);
-
 
2341
        } elseif ($this->_BIFF_version == 0x0600) {
-
 
2342
            $rgbHdr       = 0x0040; // Row/column heading and gridline color index
-
 
2343
            $zoom_factor_page_break = 0x0000;
-
 
2344
            $zoom_factor_normal     = 0x0000;
-
 
2345
            $data .= pack("vvvvV", $rgbHdr, 0x0000, $zoom_factor_page_break, $zoom_factor_normal, 0x00000000);
1995
        $data    = pack("vvvV", $grbit, $rwTop, $colLeft, $rgbHdr);
2346
        }
1996
        $this->_append($header.$data);
2347
        $this->_append($header.$data);
Line 1997... Line 2348...
1997
    }
2348
    }
1998
    
2349
 
Line 2023... Line 2374...
2023
    *                0 => First formatted column,
2374
    *                0 => First formatted column,
2024
    *                1 => Last formatted column,
2375
    *                1 => Last formatted column,
2025
    *                2 => Col width (8.43 is Excel default),
2376
    *                2 => Col width (8.43 is Excel default),
2026
    *                3 => The optional XF format of the column,
2377
    *                3 => The optional XF format of the column,
2027
    *                4 => Option flags.
2378
    *                4 => Option flags.
-
 
2379
    *                5 => Optional outline level
2028
    */
2380
    */
2029
    function _storeColinfo($col_array)
2381
    function _storeColinfo($col_array)
2030
    {
2382
    {
2031
        if (isset($col_array[0])) {
2383
        if (isset($col_array[0])) {
2032
            $colFirst = $col_array[0];
2384
            $colFirst = $col_array[0];
Line 2034... Line 2386...
2034
        if (isset($col_array[1])) {
2386
        if (isset($col_array[1])) {
2035
            $colLast = $col_array[1];
2387
            $colLast = $col_array[1];
2036
        }
2388
        }
2037
        if (isset($col_array[2])) {
2389
        if (isset($col_array[2])) {
2038
            $coldx = $col_array[2];
2390
            $coldx = $col_array[2];
2039
        }
-
 
2040
        else {
2391
        } else {
2041
            $coldx = 8.43;
2392
            $coldx = 8.43;
2042
        }
2393
        }
2043
        if (isset($col_array[3])) {
2394
        if (isset($col_array[3])) {
2044
            $format = $col_array[3];
2395
            $format = $col_array[3];
2045
        }
-
 
2046
        else {
2396
        } else {
2047
            $format = 0;
2397
            $format = 0;
2048
        }
2398
        }
2049
        if (isset($col_array[4])) {
2399
        if (isset($col_array[4])) {
2050
            $grbit = $col_array[4];
2400
            $grbit = $col_array[4];
2051
        }
-
 
2052
        else {
2401
        } else {
2053
            $grbit = 0;
2402
            $grbit = 0;
2054
        }
2403
        }
-
 
2404
        if (isset($col_array[5])) {
-
 
2405
            $level = $col_array[5];
-
 
2406
        } else {
-
 
2407
            $level = 0;
-
 
2408
        }
2055
        $record   = 0x007D;          // Record identifier
2409
        $record   = 0x007D;          // Record identifier
2056
        $length   = 0x000B;          // Number of bytes to follow
2410
        $length   = 0x000B;          // Number of bytes to follow
Line 2057... Line 2411...
2057
    
2411
 
2058
        $coldx   += 0.72;            // Fudge. Excel subtracts 0.72 !?
2412
        $coldx   += 0.72;            // Fudge. Excel subtracts 0.72 !?
Line 2059... Line 2413...
2059
        $coldx   *= 256;             // Convert to units of 1/256 of a char
2413
        $coldx   *= 256;             // Convert to units of 1/256 of a char
2060
    
2414
 
Line -... Line 2415...
-
 
2415
        $ixfe     = $this->_XF($format);
-
 
2416
        $reserved = 0x00;            // Reserved
-
 
2417
 
2061
        $ixfe     = $this->_XF($format);
2418
        $level = max(0, min($level, 7));
2062
        $reserved = 0x00;            // Reserved
2419
        $grbit |= $level << 8;
2063
    
2420
 
2064
        $header   = pack("vv",     $record, $length);
2421
        $header   = pack("vv",     $record, $length);
2065
        $data     = pack("vvvvvC", $colFirst, $colLast, $coldx,
2422
        $data     = pack("vvvvvC", $colFirst, $colLast, $coldx,
Line 2092... Line 2449...
2092
        if (!isset($colLast)) {
2449
        if (!isset($colLast)) {
2093
            $colLast  = $colFirst;      // Last  col in reference
2450
            $colLast  = $colFirst;      // Last  col in reference
2094
        }
2451
        }
Line 2095... Line 2452...
2095
    
2452
 
2096
        // Swap last row/col for first row/col as necessary
2453
        // Swap last row/col for first row/col as necessary
2097
        if ($rwFirst > $rwLast)
-
 
2098
        {
2454
        if ($rwFirst > $rwLast) {
2099
            list($rwFirst, $rwLast) = array($rwLast, $rwFirst);
2455
            list($rwFirst, $rwLast) = array($rwLast, $rwFirst);
Line 2100... Line 2456...
2100
        }
2456
        }
2101
    
-
 
2102
        if ($colFirst > $colLast)
2457
 
2103
        {
2458
        if ($colFirst > $colLast) {
Line 2104... Line 2459...
2104
            list($colFirst, $colLast) = array($colLast, $colFirst);
2459
            list($colFirst, $colLast) = array($colLast, $colFirst);
2105
        }
2460
        }
Line 2110... Line 2465...
2110
                                       $rwFirst, $rwLast,
2465
                                       $rwFirst, $rwLast,
2111
                                       $colFirst, $colLast);
2466
                                       $colFirst, $colLast);
2112
        $this->_append($header.$data);
2467
        $this->_append($header . $data);
2113
    }
2468
    }
Line -... Line 2469...
-
 
2469
 
-
 
2470
    /**
-
 
2471
    * Store the MERGEDCELLS record for all ranges of merged cells
-
 
2472
    *
-
 
2473
    * @access private
-
 
2474
    */
-
 
2475
    function _storeMergedCells()
-
 
2476
    {
-
 
2477
        // if there are no merged cell ranges set, return
-
 
2478
        if (count($this->_merged_ranges) == 0) {
-
 
2479
            return;
-
 
2480
        }
-
 
2481
        $record   = 0x00E5;
-
 
2482
        foreach($this->_merged_ranges as $ranges)
-
 
2483
          {
-
 
2484
            $length   = 2 + count($ranges) * 8; 
-
 
2485
            $header   = pack('vv', $record, $length);
-
 
2486
            $data     = pack('v',  count($ranges));
-
 
2487
            foreach($ranges as $range) 
-
 
2488
              $data .= pack('vvvv', $range[0], $range[2], $range[1], $range[3]);
-
 
2489
            $string=$header.$data;
-
 
2490
            $this->_append(&$string, true);
-
 
2491
          }
Line 2114... Line 2492...
2114
    
2492
    }
2115
    
2493
 
2116
    /**
2494
    /**
2117
    * Write BIFF record EXTERNCOUNT to indicate the number of external sheet
2495
    * Write BIFF record EXTERNCOUNT to indicate the number of external sheet
Line 2155... Line 2533...
2155
        if ($this->name == $sheetname) {
2533
        if ($this->name == $sheetname) {
2156
            $sheetname = '';
2534
            $sheetname = '';
2157
            $length    = 0x02;  // The following 2 bytes
2535
            $length    = 0x02;  // The following 2 bytes
2158
            $cch       = 1;     // The following byte
2536
            $cch       = 1;     // The following byte
2159
            $rgch      = 0x02;  // Self reference
2537
            $rgch      = 0x02;  // Self reference
2160
        }
-
 
2161
        else {
2538
        } else {
2162
            $length    = 0x02 + strlen($sheetname);
2539
            $length    = 0x02 + strlen($sheetname);
2163
            $cch       = strlen($sheetname);
2540
            $cch       = strlen($sheetname);
2164
            $rgch      = 0x03;  // Reference to a sheet in the current workbook
2541
            $rgch      = 0x03;  // Reference to a sheet in the current workbook
2165
        }
2542
        }
Line 2189... Line 2566...
2189
        $x       = $panes[1];
2566
        $x       = $panes[1];
2190
        $rwTop   = $panes[2];
2567
        $rwTop   = $panes[2];
2191
        $colLeft = $panes[3];
2568
        $colLeft = $panes[3];
2192
        if (count($panes) > 4) { // if Active pane was received
2569
        if (count($panes) > 4) { // if Active pane was received
2193
            $pnnAct = $panes[4];
2570
            $pnnAct = $panes[4];
2194
        }
-
 
2195
        else {
2571
        } else {
2196
            $pnnAct = NULL;
2572
            $pnnAct = null;
2197
        }
2573
        }
2198
        $record  = 0x0041;       // Record identifier
2574
        $record  = 0x0041;       // Record identifier
2199
        $length  = 0x000A;       // Number of bytes to follow
2575
        $length  = 0x000A;       // Number of bytes to follow
Line 2200... Line 2576...
2200
    
2576
 
2201
        // Code specific to frozen or thawed panes.
2577
        // Code specific to frozen or thawed panes.
2202
        if ($this->_frozen)
-
 
2203
        {
2578
        if ($this->_frozen) {
2204
            // Set default values for $rwTop and $colLeft
2579
            // Set default values for $rwTop and $colLeft
2205
            if (!isset($rwTop)) {
2580
            if (!isset($rwTop)) {
2206
                $rwTop   = $y;
2581
                $rwTop   = $y;
2207
            }
2582
            }
2208
            if (!isset($colLeft)) {
2583
            if (!isset($colLeft)) {
2209
                $colLeft = $x;
2584
                $colLeft = $x;
2210
            }
-
 
2211
        }
2585
            }
2212
        else
-
 
2213
        {
2586
        } else {
2214
            // Set default values for $rwTop and $colLeft
2587
            // Set default values for $rwTop and $colLeft
2215
            if (!isset($rwTop)) {
2588
            if (!isset($rwTop)) {
2216
                $rwTop   = 0;
2589
                $rwTop   = 0;
2217
            }
2590
            }
Line 2230... Line 2603...
2230
    
2603
 
2231
    
2604
 
2232
        // Determine which pane should be active. There is also the undocumented
2605
        // Determine which pane should be active. There is also the undocumented
2233
        // option to override this should it be necessary: may be removed later.
2606
        // option to override this should it be necessary: may be removed later.
2234
        //
-
 
2235
        if (!isset($pnnAct))
2607
        //
2236
        {
2608
        if (!isset($pnnAct)) {
-
 
2609
            if ($x != 0 && $y != 0) {
2237
            if ($x != 0 and $y != 0)
2610
                $pnnAct = 0; // Bottom right
2238
                $pnnAct = 0; // Bottom right
2611
            }
-
 
2612
            if ($x != 0 && $y == 0) {
2239
            if ($x != 0 and $y == 0)
2613
                $pnnAct = 1; // Top right
2240
                $pnnAct = 1; // Top right
2614
            }
-
 
2615
            if ($x == 0 && $y != 0) {
2241
            if ($x == 0 and $y != 0)
2616
                $pnnAct = 2; // Bottom left
2242
                $pnnAct = 2; // Bottom left
2617
            }
2243
            if ($x == 0 and $y == 0)
2618
            if ($x == 0 && $y == 0) {
-
 
2619
                $pnnAct = 3; // Top left
Line 2244... Line 2620...
2244
                $pnnAct = 3; // Top left
2620
            }
Line 2245... Line 2621...
2245
        }
2621
        }
2246
    
2622
 
Line 2291... Line 2667...
2291
        $grbit          |= $fNoOrient     << 6;
2667
        $grbit          |= $fNoOrient     << 6;
2292
        $grbit          |= $fUsePage      << 7;
2668
        $grbit          |= $fUsePage      << 7;
Line 2293... Line 2669...
2293
    
2669
 
2294
        $numHdr = pack("d", $numHdr);
2670
        $numHdr = pack("d", $numHdr);
2295
        $numFtr = pack("d", $numFtr);
2671
        $numFtr = pack("d", $numFtr);
2296
        if ($this->_byte_order) // if it's Big Endian
-
 
2297
        {
2672
        if ($this->_byte_order) { // if it's Big Endian
2298
            $numHdr = strrev($numHdr);
2673
            $numHdr = strrev($numHdr);
2299
            $numFtr = strrev($numFtr);
2674
            $numFtr = strrev($numFtr);
Line 2300... Line 2675...
2300
        }
2675
        }
Line 2322... Line 2697...
2322
    {
2697
    {
2323
        $record  = 0x0014;               // Record identifier
2698
        $record  = 0x0014;               // Record identifier
Line 2324... Line 2699...
2324
    
2699
 
2325
        $str     = $this->_header;       // header string
2700
        $str      = $this->_header;       // header string
-
 
2701
        $cch      = strlen($str);         // Length of header string
-
 
2702
        if ($this->_BIFF_version == 0x0600) {
-
 
2703
            $encoding = 0x0;                  // TODO: Unicode support
-
 
2704
            $length   = 3 + $cch;             // Bytes to follow
2326
        $cch     = strlen($str);         // Length of header string
2705
        } else {
-
 
2706
            $length  = 1 + $cch;             // Bytes to follow
Line 2327... Line 2707...
2327
        $length  = 1 + $cch;             // Bytes to follow
2707
        }
-
 
2708
 
-
 
2709
        $header   = pack("vv", $record, $length);
-
 
2710
        if ($this->_BIFF_version == 0x0600) {
2328
    
2711
            $data     = pack("vC",  $cch, $encoding);
-
 
2712
        } else {
Line 2329... Line 2713...
2329
        $header    = pack("vv", $record, $length);
2713
            $data      = pack("C",  $cch);
2330
        $data      = pack("C",  $cch);
2714
        }
Line 2331... Line 2715...
2331
    
2715
 
2332
        $this->_append($header.$data.$str);
2716
        $this->_prepend($header.$data.$str);
2333
    }
2717
    }
Line 2341... Line 2725...
2341
    {
2725
    {
2342
        $record  = 0x0015;               // Record identifier
2726
        $record  = 0x0015;               // Record identifier
Line 2343... Line 2727...
2343
    
2727
 
2344
        $str     = $this->_footer;       // Footer string
2728
        $str      = $this->_footer;       // Footer string
-
 
2729
        $cch      = strlen($str);         // Length of footer string
-
 
2730
        if ($this->_BIFF_version == 0x0600) {
2345
        $cch     = strlen($str);         // Length of footer string
2731
            $encoding = 0x0;                  // TODO: Unicode support
-
 
2732
            $length   = 3 + $cch;             // Bytes to follow
-
 
2733
        } else {
-
 
2734
            $length  = 1 + $cch;
Line 2346... Line 2735...
2346
        $length  = 1 + $cch;             // Bytes to follow
2735
        }
-
 
2736
 
-
 
2737
        $header    = pack("vv", $record, $length);
-
 
2738
        if ($this->_BIFF_version == 0x0600) {
2347
    
2739
            $data      = pack("vC",  $cch, $encoding);
-
 
2740
        } else {
Line 2348... Line 2741...
2348
        $header    = pack("vv", $record, $length);
2741
            $data      = pack("C",  $cch);
2349
        $data      = pack("C",  $cch);
2742
        }
Line 2350... Line 2743...
2350
    
2743
 
2351
        $this->_append($header.$data.$str);
2744
        $this->_prepend($header . $data . $str);
2352
    }
2745
    }
Line 2364... Line 2757...
2364
        $fHCenter = $this->_hcenter;     // Horizontal centering
2757
        $fHCenter = $this->_hcenter;     // Horizontal centering
Line 2365... Line 2758...
2365
    
2758
 
2366
        $header    = pack("vv", $record, $length);
2759
        $header    = pack("vv", $record, $length);
Line 2367... Line 2760...
2367
        $data      = pack("v",  $fHCenter);
2760
        $data      = pack("v",  $fHCenter);
2368
    
2761
 
Line 2369... Line 2762...
2369
        $this->_append($header.$data);
2762
        $this->_prepend($header.$data);
2370
    }
2763
    }
2371
    
2764
 
Line 2381... Line 2774...
2381
    
2774
 
Line 2382... Line 2775...
2382
        $fVCenter = $this->_vcenter;     // Horizontal centering
2775
        $fVCenter = $this->_vcenter;     // Horizontal centering
2383
    
2776
 
2384
        $header    = pack("vv", $record, $length);
2777
        $header    = pack("vv", $record, $length);
2385
        $data      = pack("v",  $fVCenter);
2778
        $data      = pack("v",  $fVCenter);
Line 2386... Line 2779...
2386
        $this->_append($header.$data);
2779
        $this->_prepend($header . $data);
2387
    }
2780
    }
2388
    
2781
 
Line 2398... Line 2791...
2398
    
2791
 
Line 2399... Line 2792...
2399
        $margin  = $this->_margin_left;       // Margin in inches
2792
        $margin  = $this->_margin_left;       // Margin in inches
2400
    
2793
 
2401
        $header    = pack("vv",  $record, $length);
2794
        $header    = pack("vv",  $record, $length);
2402
        $data      = pack("d",   $margin);
-
 
2403
        if ($this->_byte_order) // if it's Big Endian
2795
        $data      = pack("d",   $margin);
2404
        { 
2796
        if ($this->_byte_order) { // if it's Big Endian
Line 2405... Line 2797...
2405
            $data = strrev($data);
2797
            $data = strrev($data);
2406
        }
2798
        }
Line 2407... Line 2799...
2407
    
2799
 
2408
        $this->_append($header.$data);
2800
        $this->_prepend($header . $data);
2409
    }
2801
    }
Line 2420... Line 2812...
2420
    
2812
 
Line 2421... Line 2813...
2421
        $margin  = $this->_margin_right;      // Margin in inches
2813
        $margin  = $this->_margin_right;      // Margin in inches
2422
    
2814
 
2423
        $header    = pack("vv",  $record, $length);
2815
        $header    = pack("vv",  $record, $length);
2424
        $data      = pack("d",   $margin);
-
 
2425
        if ($this->_byte_order) // if it's Big Endian
2816
        $data      = pack("d",   $margin);
2426
        { 
2817
        if ($this->_byte_order) { // if it's Big Endian
Line 2427... Line 2818...
2427
            $data = strrev($data);
2818
            $data = strrev($data);
2428
        }
2819
        }
Line 2429... Line 2820...
2429
    
2820
 
2430
        $this->_append($header.$data);
2821
        $this->_prepend($header . $data);
2431
    }
2822
    }
Line 2442... Line 2833...
2442
    
2833
 
Line 2443... Line 2834...
2443
        $margin  = $this->_margin_top;        // Margin in inches
2834
        $margin  = $this->_margin_top;        // Margin in inches
2444
    
2835
 
2445
        $header    = pack("vv",  $record, $length);
2836
        $header    = pack("vv",  $record, $length);
2446
        $data      = pack("d",   $margin);
-
 
2447
        if ($this->_byte_order) // if it's Big Endian
2837
        $data      = pack("d",   $margin);
2448
        { 
2838
        if ($this->_byte_order) { // if it's Big Endian
Line 2449... Line 2839...
2449
            $data = strrev($data);
2839
            $data = strrev($data);
2450
        }
2840
        }
Line 2451... Line 2841...
2451
    
2841
 
2452
        $this->_append($header.$data);
2842
        $this->_prepend($header . $data);
2453
    }
2843
    }
Line 2464... Line 2854...
2464
    
2854
 
Line 2465... Line 2855...
2465
        $margin  = $this->_margin_bottom;     // Margin in inches
2855
        $margin  = $this->_margin_bottom;     // Margin in inches
2466
    
2856
 
2467
        $header    = pack("vv",  $record, $length);
2857
        $header    = pack("vv",  $record, $length);
2468
        $data      = pack("d",   $margin);
-
 
2469
        if ($this->_byte_order) // if it's Big Endian
2858
        $data      = pack("d",   $margin);
2470
        { 
2859
        if ($this->_byte_order) { // if it's Big Endian
Line 2471... Line 2860...
2471
            $data = strrev($data);
2860
            $data = strrev($data);
2472
        }
2861
        }
Line 2473... Line 2862...
2473
    
2862
 
2474
        $this->_append($header.$data);
2863
        $this->_prepend($header . $data);
2475
    }
2864
    }
Line 2559... Line 2948...
2559
        $data        = pack("v",   $fGridSet);
2948
        $data        = pack("v",   $fGridSet);
2560
        $this->_prepend($header.$data);
2949
        $this->_prepend($header . $data);
2561
    }
2950
    }
Line 2562... Line 2951...
2562
    
2951
 
-
 
2952
    /**
-
 
2953
    * Write the GUTS BIFF record. This is used to configure the gutter margins
-
 
2954
    * where Excel outline symbols are displayed. The visibility of the gutters is
-
 
2955
    * controlled by a flag in WSBOOL.
-
 
2956
    *
-
 
2957
    * @see _storeWsbool()
-
 
2958
    * @access private
-
 
2959
    */
-
 
2960
    function _storeGuts()
-
 
2961
    {
-
 
2962
        $record      = 0x0080;   // Record identifier
-
 
2963
        $length      = 0x0008;   // Bytes to follow
-
 
2964
 
-
 
2965
        $dxRwGut     = 0x0000;   // Size of row gutter
-
 
2966
        $dxColGut    = 0x0000;   // Size of col gutter
-
 
2967
 
-
 
2968
        $row_level   = $this->_outline_row_level;
-
 
2969
        $col_level   = 0;
-
 
2970
 
-
 
2971
        // Calculate the maximum column outline level. The equivalent calculation
-
 
2972
        // for the row outline level is carried out in setRow().
-
 
2973
        $colcount = count($this->_colinfo);
-
 
2974
        for ($i = 0; $i < $colcount; $i++) {
-
 
2975
           // Skip cols without outline level info.
-
 
2976
           if (count($this->_colinfo[$i]) >= 6) {
-
 
2977
              $col_level = max($this->_colinfo[$i][5], $col_level);
-
 
2978
           }
-
 
2979
        }
-
 
2980
 
-
 
2981
        // Set the limits for the outline levels (0 <= x <= 7).
-
 
2982
        $col_level = max(0, min($col_level, 7));
-
 
2983
 
-
 
2984
        // The displayed level is one greater than the max outline levels
-
 
2985
        if ($row_level) {
-
 
2986
            $row_level++;
-
 
2987
        }
-
 
2988
        if ($col_level) {
-
 
2989
            $col_level++;
-
 
2990
        }
-
 
2991
 
-
 
2992
        $header = pack("vv",   $record, $length);
-
 
2993
        $data   = pack("vvvv", $dxRwGut, $dxColGut, $row_level, $col_level);
-
 
2994
 
-
 
2995
        $this->_prepend($header.$data);
-
 
2996
    }
-
 
2997
 
-
 
2998
 
2563
    /**
2999
    /**
2564
    * Write the WSBOOL BIFF record, mainly for fit-to-page. Used in conjunction
3000
    * Write the WSBOOL BIFF record, mainly for fit-to-page. Used in conjunction
2565
    * with the SETUP record.
3001
    * with the SETUP record.
2566
    *
3002
    *
2567
    * @access private
3003
    * @access private
2568
    */
3004
    */
2569
    function _storeWsbool()
3005
    function _storeWsbool()
2570
    {
3006
    {
2571
        $record      = 0x0081;   // Record identifier
3007
        $record      = 0x0081;   // Record identifier
-
 
3008
        $length      = 0x0002;   // Bytes to follow
Line 2572... Line 3009...
2572
        $length      = 0x0002;   // Bytes to follow
3009
        $grbit       = 0x0000;
2573
    
3010
 
2574
        // The only option that is of interest is the flag for fit to page. So we
3011
        // The only option that is of interest is the flag for fit to page. So we
2575
        // set all the options in one go.
3012
        // set all the options in one go.
2576
        //
3013
        //
2577
        if ($this->_fit_page) {
-
 
2578
            $grbit = 0x05c1;
3014
        /*if ($this->_fit_page) {
2579
        }
3015
            $grbit = 0x05c1;
-
 
3016
        } else {
-
 
3017
            $grbit = 0x04c1;
-
 
3018
        }*/
-
 
3019
        // Set the option flags
-
 
3020
        $grbit |= 0x0001;                           // Auto page breaks visible
-
 
3021
        if ($this->_outline_style) {
-
 
3022
            $grbit |= 0x0020; // Auto outline styles
-
 
3023
        }
-
 
3024
        if ($this->_outline_below) {
-
 
3025
            $grbit |= 0x0040; // Outline summary below
-
 
3026
        }
-
 
3027
        if ($this->_outline_right) {
-
 
3028
            $grbit |= 0x0080; // Outline summary right
-
 
3029
        }
-
 
3030
        if ($this->_fit_page) {
-
 
3031
            $grbit |= 0x0100; // Page setup fit to page
-
 
3032
        }
2580
        else {
3033
        if ($this->_outline_on) {
Line 2581... Line 3034...
2581
            $grbit = 0x04c1;
3034
            $grbit |= 0x0400; // Outline symbols displayed
2582
        }
3035
        }
2583
    
3036
 
2584
        $header      = pack("vv", $record, $length);
3037
        $header = pack("vv", $record, $length);
Line 2585... Line -...
2585
        $data        = pack("v",  $grbit);
-
 
2586
        $this->_prepend($header.$data);
3038
        $data   = pack("v",  $grbit);
2587
    }
3039
        $this->_prepend($header . $data);
2588
    
3040
    }
2589
    
3041
 
2590
    /**
3042
    /**
Line 2606... Line 3058...
2606
            array_shift($breaks);
3058
            array_shift($breaks);
2607
        }
3059
        }
Line 2608... Line 3060...
2608
    
3060
 
2609
        $record  = 0x001b;               // Record identifier
3061
        $record  = 0x001b;               // Record identifier
-
 
3062
        $cbrk    = count($breaks);       // Number of page breaks
-
 
3063
        if ($this->_BIFF_version == 0x0600) {
-
 
3064
            $length  = 2 + 6*$cbrk;      // Bytes to follow
2610
        $cbrk    = count($breaks);       // Number of page breaks
3065
        } else {
-
 
3066
            $length  = 2 + 2*$cbrk;      // Bytes to follow
Line 2611... Line 3067...
2611
        $length  = ($cbrk + 1) * 2;      // Bytes to follow
3067
        }
2612
    
3068
 
Line 2613... Line 3069...
2613
        $header  = pack("vv", $record, $length);
3069
        $header  = pack("vv", $record, $length);
2614
        $data    = pack("v",  $cbrk);
3070
        $data    = pack("v",  $cbrk);
-
 
3071
 
-
 
3072
        // Append each page break
-
 
3073
        foreach ($breaks as $break) {
2615
    
3074
            if ($this->_BIFF_version == 0x0600) {
2616
        // Append each page break
3075
                $data .= pack("vvv", $break, 0x0000, 0x00ff);
-
 
3076
            } else {
Line 2617... Line 3077...
2617
        foreach($breaks as $break) {
3077
                $data .= pack("v", $break);
2618
            $data .= pack("v", $break);
3078
            }
Line 2644... Line 3104...
2644
            array_shift($breaks);
3104
            array_shift($breaks);
2645
        }
3105
        }
Line 2646... Line 3106...
2646
    
3106
 
2647
        $record  = 0x001a;               // Record identifier
3107
        $record  = 0x001a;               // Record identifier
-
 
3108
        $cbrk    = count($breaks);       // Number of page breaks
-
 
3109
        if ($this->_BIFF_version == 0x0600) {
-
 
3110
            $length  = 2 + 6*$cbrk;      // Bytes to follow
2648
        $cbrk    = count($breaks);       // Number of page breaks
3111
        } else {
-
 
3112
            $length  = 2 + 2*$cbrk;      // Bytes to follow
Line 2649... Line 3113...
2649
        $length  = ($cbrk + 1) * 2;      // Bytes to follow
3113
        }
2650
    
3114
 
Line 2651... Line 3115...
2651
        $header  = pack("vv",  $record, $length);
3115
        $header  = pack("vv",  $record, $length);
2652
        $data    = pack("v",   $cbrk);
3116
        $data    = pack("v",   $cbrk);
-
 
3117
 
-
 
3118
        // Append each page break
-
 
3119
        foreach ($breaks as $break) {
2653
    
3120
            if ($this->_BIFF_version == 0x0600) {
2654
        // Append each page break
3121
                $data .= pack("vvv", $break, 0x0000, 0xffff);
-
 
3122
            } else {
Line 2655... Line 3123...
2655
        foreach ($breaks as $break) {
3123
                $data .= pack("v", $break);
2656
            $data .= pack("v", $break);
3124
            }
Line 2657... Line 3125...
2657
        }
3125
        }
Line 2688... Line 3156...
2688
    * @access private
3156
    * @access private
2689
    */
3157
    */
2690
    function _storePassword()
3158
    function _storePassword()
2691
    {
3159
    {
2692
        // Exit unless sheet protection and password have been specified
3160
        // Exit unless sheet protection and password have been specified
2693
        if (($this->_protect == 0) or (!isset($this->_password))) {
3161
        if (($this->_protect == 0) || (!isset($this->_password))) {
2694
            return;
3162
            return;
2695
        }
3163
        }
Line 2696... Line 3164...
2696
    
3164
 
2697
        $record      = 0x0013;               // Record identifier
3165
        $record      = 0x0013;               // Record identifier
Line 2719... Line 3187...
2719
    * @param integer $scale_y The vertical scale
3187
    * @param integer $scale_y The vertical scale
2720
    */
3188
    */
2721
    function insertBitmap($row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1, $scale_y = 1)
3189
    function insertBitmap($row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1, $scale_y = 1)
2722
    {
3190
    {
2723
        $bitmap_array = $this->_processBitmap($bitmap);
3191
        $bitmap_array = $this->_processBitmap($bitmap);
2724
        if ($this->isError($bitmap_array))
3192
        if ($this->isError($bitmap_array)) {
2725
        {
-
 
2726
            $this->writeString($row, $col, $bitmap_array->getMessage());
3193
            $this->writeString($row, $col, $bitmap_array->getMessage());
2727
            return;
3194
            return;
2728
        }
3195
        }
2729
        list($width, $height, $size, $data) = $bitmap_array; //$this->_processBitmap($bitmap);
3196
        list($width, $height, $size, $data) = $bitmap_array; //$this->_processBitmap($bitmap);
Line 2802... Line 3269...
2802
        // Initialise end cell to the same as the start cell
3269
        // Initialise end cell to the same as the start cell
2803
        $col_end    = $col_start;  // Col containing lower right corner of object
3270
        $col_end    = $col_start;  // Col containing lower right corner of object
2804
        $row_end    = $row_start;  // Row containing bottom right corner of object
3271
        $row_end    = $row_start;  // Row containing bottom right corner of object
Line 2805... Line 3272...
2805
    
3272
 
2806
        // Zero the specified offset if greater than the cell dimensions
3273
        // Zero the specified offset if greater than the cell dimensions
2807
        if ($x1 >= $this->_sizeCol($col_start))
-
 
2808
        {
3274
        if ($x1 >= $this->_sizeCol($col_start)) {
2809
            $x1 = 0;
3275
            $x1 = 0;
2810
        }
3276
        }
2811
        if ($y1 >= $this->_sizeRow($row_start))
-
 
2812
        {
3277
        if ($y1 >= $this->_sizeRow($row_start)) {
2813
            $y1 = 0;
3278
            $y1 = 0;
Line 2814... Line 3279...
2814
        }
3279
        }
2815
    
3280
 
Line 2829... Line 3294...
2829
        }
3294
        }
Line 2830... Line 3295...
2830
    
3295
 
2831
        // Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell
3296
        // Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell
2832
        // with zero eight or width.
3297
        // with zero eight or width.
2833
        //
3298
        //
2834
        if ($this->_sizeCol($col_start) == 0)
3299
        if ($this->_sizeCol($col_start) == 0) {
-
 
3300
            return;
2835
            return;
3301
        }
2836
        if ($this->_sizeCol($col_end)   == 0)
3302
        if ($this->_sizeCol($col_end)   == 0) {
-
 
3303
            return;
2837
            return;
3304
        }
2838
        if ($this->_sizeRow($row_start) == 0)
3305
        if ($this->_sizeRow($row_start) == 0) {
-
 
3306
            return;
2839
            return;
3307
        }
2840
        if ($this->_sizeRow($row_end)   == 0)
3308
        if ($this->_sizeRow($row_end)   == 0) {
-
 
3309
            return;
Line 2841... Line 3310...
2841
            return;
3310
        }
2842
    
3311
 
2843
        // Convert the pixel values to the percentage value expected by Excel
3312
        // Convert the pixel values to the percentage value expected by Excel
2844
        $x1 = $x1     / $this->_sizeCol($col_start)   * 1024;
3313
        $x1 = $x1     / $this->_sizeCol($col_start)   * 1024;
2845
        $y1 = $y1     / $this->_sizeRow($row_start)   *  256;
3314
        $y1 = $y1     / $this->_sizeRow($row_start)   *  256;
Line 2846... Line 3315...
2846
        $x2 = $width  / $this->_sizeCol($col_end)     * 1024; // Distance to right side of object
3315
        $x2 = $width  / $this->_sizeCol($col_end)     * 1024; // Distance to right side of object
2847
        $y2 = $height / $this->_sizeRow($row_end)     *  256; // Distance to bottom of object
3316
        $y2 = $height / $this->_sizeRow($row_end)     *  256; // Distance to bottom of object
2848
    
3317
 
2849
        $this->_storeObjPicture( $col_start, $x1,
3318
        $this->_storeObjPicture($col_start, $x1,
2850
                                  $row_start, $y1,
-
 
2851
                                  $col_end, $x2,
3319
                                 $row_start, $y1,
Line 2852... Line 3320...
2852
                                  $row_end, $y2
3320
                                 $col_end, $x2,
2853
                                );
3321
                                 $row_end, $y2);
2854
    }
3322
    }
Line 2866... Line 3334...
2866
    {
3334
    {
2867
        // Look up the cell value to see if it has been changed
3335
        // Look up the cell value to see if it has been changed
2868
        if (isset($this->col_sizes[$col])) {
3336
        if (isset($this->col_sizes[$col])) {
2869
            if ($this->col_sizes[$col] == 0) {
3337
            if ($this->col_sizes[$col] == 0) {
2870
                return(0);
3338
                return(0);
2871
            }
-
 
2872
            else {
3339
            } else {
2873
                return(floor(7 * $this->col_sizes[$col] + 5));
3340
                return(floor(7 * $this->col_sizes[$col] + 5));
2874
            }
3341
            }
2875
        }
-
 
2876
        else {
3342
        } else {
2877
            return(64);
3343
            return(64);
2878
        }
3344
        }
2879
    }
3345
    }
Line 2880... Line 3346...
2880
    
3346
 
Line 2889... Line 3355...
2889
    * @return integer The width in pixels
3355
    * @return integer The width in pixels
2890
    */
3356
    */
2891
    function _sizeRow($row)
3357
    function _sizeRow($row)
2892
    {
3358
    {
2893
        // Look up the cell value to see if it has been changed
3359
        // Look up the cell value to see if it has been changed
2894
        if (isset($this->row_sizes[$row])) {
3360
        if (isset($this->_row_sizes[$row])) {
2895
            if ($this->row_sizes[$row] == 0) {
3361
            if ($this->_row_sizes[$row] == 0) {
2896
                return(0);
3362
                return(0);
-
 
3363
            } else {
-
 
3364
                return(floor(4/3 * $this->_row_sizes[$row]));
2897
            }
3365
            }
2898
            else {
-
 
2899
                return(floor(4/3 * $this->row_sizes[$row]));
-
 
2900
            }
-
 
2901
        }
-
 
2902
        else {
3366
        } else {
2903
            return(17);
3367
            return(17);
2904
        }
3368
        }
2905
    }
3369
    }
Line 2906... Line 3370...
2906
    
3370
 
Line 2996... Line 3460...
2996
    function _processBitmap($bitmap)
3460
    function _processBitmap($bitmap)
2997
    {
3461
    {
2998
        // Open file.
3462
        // Open file.
2999
        $bmp_fd = @fopen($bitmap,"rb");
3463
        $bmp_fd = @fopen($bitmap,"rb");
3000
        if (!$bmp_fd) {
3464
        if (!$bmp_fd) {
3001
            return($this->raiseError("Couldn't import $bitmap"));
3465
            $this->raiseError("Couldn't import $bitmap");
3002
        }
3466
        }
Line 3003... Line 3467...
3003
            
3467
 
3004
        // Slurp the file into a string.
3468
        // Slurp the file into a string.
Line 3005... Line 3469...
3005
        $data = fread($bmp_fd, filesize($bitmap));
3469
        $data = fread($bmp_fd, filesize($bitmap));
3006
    
3470
 
3007
        // Check that the file is big enough to be a bitmap.
3471
        // Check that the file is big enough to be a bitmap.
3008
        if (strlen($data) <= 0x36) {
3472
        if (strlen($data) <= 0x36) {
Line 3009... Line 3473...
3009
            return($this->raiseError("$bitmap doesn't contain enough data.\n"));
3473
            $this->raiseError("$bitmap doesn't contain enough data.\n");
3010
        }
3474
        }
3011
    
3475
 
3012
        // The first 2 bytes are used to identify the bitmap.
3476
        // The first 2 bytes are used to identify the bitmap.
3013
        $identity = unpack("A2", $data);
3477
        $identity = unpack("A2ident", $data);
Line 3014... Line 3478...
3014
        if ($identity[''] != "BM") {
3478
        if ($identity['ident'] != "BM") {
3015
            return($this->raiseError("$bitmap doesn't appear to be a valid bitmap image.\n"));
3479
            $this->raiseError("$bitmap doesn't appear to be a valid bitmap image.\n");
Line 3016... Line 3480...
3016
        }
3480
        }
3017
    
3481
 
3018
        // Remove bitmap data: ID.
3482
        // Remove bitmap data: ID.
3019
        $data = substr($data, 2);
3483
        $data = substr($data, 2);
3020
    
3484
 
3021
        // Read and remove the bitmap size. This is more reliable than reading
3485
        // Read and remove the bitmap size. This is more reliable than reading
3022
        // the data size at offset 0x22.
3486
        // the data size at offset 0x22.
3023
        //
3487
        //
Line 3024... Line 3488...
3024
        $size_array   = unpack("V", substr($data, 0, 4));
3488
        $size_array   = unpack("Vsa", substr($data, 0, 4));
Line 3034... Line 3498...
3034
        $width_and_height = unpack("V2", substr($data, 0, 8));
3498
        $width_and_height = unpack("V2", substr($data, 0, 8));
3035
        $width  = $width_and_height[1];
3499
        $width  = $width_and_height[1];
3036
        $height = $width_and_height[2];
3500
        $height = $width_and_height[2];
3037
        $data   = substr($data, 8);
3501
        $data   = substr($data, 8);
3038
        if ($width > 0xFFFF) { 
3502
        if ($width > 0xFFFF) {
3039
            return($this->raiseError("$bitmap: largest image width supported is 65k.\n"));
3503
            $this->raiseError("$bitmap: largest image width supported is 65k.\n");
3040
        }
3504
        }
3041
        if ($height > 0xFFFF) { 
3505
        if ($height > 0xFFFF) {
3042
            return($this->raiseError("$bitmap: largest image height supported is 65k.\n"));
3506
            $this->raiseError("$bitmap: largest image height supported is 65k.\n");
3043
        }
3507
        }
Line 3044... Line 3508...
3044
    
3508
 
3045
        // Read and remove the bitmap planes and bpp data. Verify them.
3509
        // Read and remove the bitmap planes and bpp data. Verify them.
3046
        $planes_and_bitcount = unpack("v2", substr($data, 0, 4));
3510
        $planes_and_bitcount = unpack("v2", substr($data, 0, 4));
3047
        $data = substr($data, 4);
3511
        $data = substr($data, 4);
3048
        if ($planes_and_bitcount[2] != 24) { // Bitcount
3512
        if ($planes_and_bitcount[2] != 24) { // Bitcount
3049
            return($this->raiseError("$bitmap isn't a 24bit true color bitmap.\n"));
3513
            $this->raiseError("$bitmap isn't a 24bit true color bitmap.\n");
3050
        }
3514
        }
3051
        if ($planes_and_bitcount[1] != 1) {
3515
        if ($planes_and_bitcount[1] != 1) {
3052
            return($this->raiseError("$bitmap: only 1 plane nupported in bitmap image.\n"));
3516
            $this->raiseError("$bitmap: only 1 plane supported in bitmap image.\n");
Line 3053... Line 3517...
3053
        }
3517
        }
3054
    
3518
 
3055
        // Read and remove the bitmap compression. Verify compression.
3519
        // Read and remove the bitmap compression. Verify compression.
Line 3056... Line 3520...
3056
        $compression = unpack("V", substr($data, 0, 4));
3520
        $compression = unpack("Vcomp", substr($data, 0, 4));
3057
        $data = substr($data, 4);
3521
        $data = substr($data, 4);
3058
      
3522
 
3059
        //$compression = 0;
3523
        //$compression = 0;
Line 3060... Line 3524...
3060
        if ($compression[""] != 0) {
3524
        if ($compression['comp'] != 0) {
3061
            return($this->raiseError("$bitmap: compression not supported in bitmap image.\n"));
3525
            $this->raiseError("$bitmap: compression not supported in bitmap image.\n");
Line 3089... Line 3553...
3089
    
3553
 
3090
        $header      = pack("vv", $record, $length);
3554
        $header      = pack("vv", $record, $length);
3091
        $data        = pack("vv", $this->_zoom, 100);
3555
        $data        = pack("vv", $this->_zoom, 100);
3092
        $this->_append($header.$data);
3556
        $this->_append($header . $data);
-
 
3557
    }
-
 
3558
 
-
 
3559
    /**
-
 
3560
    * FIXME: add comments
-
 
3561
    */
-
 
3562
    function setValidation($row1, $col1, $row2, $col2, &$validator)
-
 
3563
    {
-
 
3564
        $this->_dv[] = $validator->_getData() .
-
 
3565
                       pack("vvvvv", 1, $row1, $row2, $col1, $col2);
-
 
3566
    }
-
 
3567
 
-
 
3568
    /**
-
 
3569
    * Store the DVAL and DV records.
-
 
3570
    *
-
 
3571
    * @access private
-
 
3572
    */
-
 
3573
    function _storeDataValidity()
-
 
3574
    {
-
 
3575
        $record      = 0x01b2;      // Record identifier
-
 
3576
        $length      = 0x0012;      // Bytes to follow
-
 
3577
 
-
 
3578
        $grbit       = 0x0002;      // Prompt box at cell, no cached validity data at DV records
-
 
3579
        $horPos      = 0x00000000;  // Horizontal position of prompt box, if fixed position
-
 
3580
        $verPos      = 0x00000000;  // Vertical position of prompt box, if fixed position
-
 
3581
        $objId       = 0xffffffff;  // Object identifier of drop down arrow object, or -1 if not visible
-
 
3582
 
-
 
3583
        $header      = pack('vv', $record, $length);
-
 
3584
        $data        = pack('vVVVV', $grbit, $horPos, $verPos, $objId,
-
 
3585
                                     count($this->_dv));
-
 
3586
        $this->_append($header.$data);
-
 
3587
 
-
 
3588
        $record = 0x01be;              // Record identifier
-
 
3589
        foreach ($this->_dv as $dv) {
-
 
3590
            $length = strlen($dv);      // Bytes to follow
-
 
3591
            $header = pack("vv", $record, $length);
-
 
3592
            $this->_append($header . $dv);
-
 
3593
        }
3093
    }
3594
    }
3094
}
3595
}