Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 996 Rev 1604
Line 3... Line 3...
3
*  Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
3
*  Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
4
*
4
*
5
*  The majority of this is _NOT_ my code.  I simply ported it from the
5
*  The majority of this is _NOT_ my code.  I simply ported it from the
6
*  PERL Spreadsheet::WriteExcel module.
6
*  PERL Spreadsheet::WriteExcel module.
7
*
7
*
8
*  The author of the Spreadsheet::WriteExcel module is John McNamara 
8
*  The author of the Spreadsheet::WriteExcel module is John McNamara
9
*  <jmcnamara@cpan.org>
9
*  <jmcnamara@cpan.org>
10
*
10
*
11
*  I _DO_ maintain this code, and John McNamara has nothing to do with the
11
*  I _DO_ maintain this code, and John McNamara has nothing to do with the
12
*  porting of this code to PHP.  Any questions directly related to this
12
*  porting of this code to PHP.  Any questions directly related to this
13
*  class library should be directed to me.
13
*  class library should be directed to me.
Line 30... Line 30...
30
*    You should have received a copy of the GNU Lesser General Public
30
*    You should have received a copy of the GNU Lesser General Public
31
*    License along with this library; if not, write to the Free Software
31
*    License along with this library; if not, write to the Free Software
32
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
*/
33
*/
Line 34... Line 34...
34
 
34
 
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
297
        $colmax                = 256;
399
        $colmax                = 256;
298
    
400
 
299
        $this->name            = $name;
401
        $this->name            = $name;
300
        $this->index           = $index;
402
        $this->index           = $index;
301
        $this->activesheet     = &$activesheet;
403
        $this->activesheet     = &$activesheet;
-
 
404
        $this->firstsheet      = &$firstsheet;
-
 
405
        $this->_str_total      = &$str_total;
-
 
406
        $this->_str_unique     = &$str_unique;
302
        $this->firstsheet      = &$firstsheet;
407
        $this->_str_table      = &$str_table;
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;
310
        //$this->offset          = 0;
415
        //$this->offset          = 0;
311
        $this->_xls_rowmax     = $rowmax;
416
        $this->_xls_rowmax     = $rowmax;
Line 319... Line 424...
319
        $this->_selection      = array(0,0,0,0);
424
        $this->_selection      = array(0,0,0,0);
320
        $this->_panes          = array();
425
        $this->_panes          = array();
321
        $this->_active_pane    = 3;
426
        $this->_active_pane    = 3;
322
        $this->_frozen         = 0;
427
        $this->_frozen         = 0;
323
        $this->selected        = 0;
428
        $this->selected        = 0;
324
    
429
 
325
        $this->_paper_size      = 0x0;
430
        $this->_paper_size      = 0x0;
326
        $this->_orientation     = 0x1;
431
        $this->_orientation     = 0x1;
327
        $this->_header          = '';
432
        $this->_header          = '';
328
        $this->_footer          = '';
433
        $this->_footer          = '';
329
        $this->_hcenter         = 0;
434
        $this->_hcenter         = 0;
Line 332... Line 437...
332
        $this->_margin_foot     = 0.50;
437
        $this->_margin_foot     = 0.50;
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;
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;
345
        $this->print_colmax     = NULL;
450
        $this->print_colmax     = null;
346
    
451
 
347
        $this->_print_gridlines = 1;
452
        $this->_print_gridlines  = 1;
-
 
453
        $this->_screen_gridlines = 1;
348
        $this->_print_headers   = 0;
454
        $this->_print_headers    = 0;
349
    
455
 
350
        $this->_fit_page        = 0;
456
        $this->_fit_page        = 0;
351
        $this->_fit_width       = 0;
457
        $this->_fit_width       = 0;
352
        $this->_fit_height      = 0;
458
        $this->_fit_height      = 0;
353
    
459
 
354
        $this->_hbreaks         = array();
460
        $this->_hbreaks         = array();
355
        $this->_vbreaks         = array();
461
        $this->_vbreaks         = array();
356
    
462
 
357
        $this->_protect         = 0;
463
        $this->_protect         = 0;
358
        $this->_password        = NULL;
464
        $this->_password        = null;
359
    
465
 
360
        $this->col_sizes        = array();
466
        $this->col_sizes        = array();
361
        $this->row_sizes        = array();
467
        $this->_row_sizes        = array();
362
    
468
 
363
        $this->_zoom            = 100;
469
        $this->_zoom            = 100;
364
        $this->_print_scale     = 100;
470
        $this->_print_scale     = 100;
365
    
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();
-
 
480
 
-
 
481
        $this->_input_encoding    = '';
-
 
482
 
-
 
483
        $this->_dv                = array();
-
 
484
        
-
 
485
        $this->_tmp_dir           = $tmp_dir;
-
 
486
        $this->_tmp_file          = '';
-
 
487
 
366
        $this->_initialize();
488
        $this->_initialize();
367
    }
489
    }
368
    
490
 
369
    /**
491
    /**
370
    * Open a tmp file to store the majority of the Worksheet data. If this fails,
492
    * Open a tmp file to store the majority of the Worksheet data. If this fails,
371
    * for example due to write permissions, store the data in memory. This can be
493
    * for example due to write permissions, store the data in memory. This can be
372
    * slow for large files.
494
    * slow for large files.
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
    }
389
    
528
 
390
    /**
529
    /**
391
    * Add data to the beginning of the workbook (note the reverse order)
530
    * Add data to the beginning of the workbook (note the reverse order)
392
    * and to the end of the workbook.
531
    * and to the end of the workbook.
393
    *
532
    *
394
    * @access public 
533
    * @access public
395
    * @see Spreadsheet_Excel_Writer_Workbook::storeWorkbook()
534
    * @see Spreadsheet_Excel_Writer_Workbook::storeWorkbook()
396
    * @param array $sheetnames The array of sheetnames from the Workbook this 
535
    * @param array $sheetnames The array of sheetnames from the Workbook this
397
    *                          worksheet belongs to
536
    *                          worksheet belongs to
398
    */
537
    */
399
    function close($sheetnames)
538
    function close($sheetnames)
400
    {
539
    {
401
        $num_sheets = count($sheetnames);
540
        $num_sheets = count($sheetnames);
402
    
541
 
403
        /***********************************************
542
        /***********************************************
404
        * Prepend in reverse order!!
543
        * Prepend in reverse order!!
405
        */
544
        */
406
    
545
 
407
        // Prepend the sheet dimensions
546
        // Prepend the sheet dimensions
408
        $this->storeDimensions();
547
        $this->_storeDimensions();
409
    
548
 
410
        // Prepend the sheet password
549
        // Prepend the sheet password
411
        $this->_storePassword();
550
        $this->_storePassword();
412
    
551
 
413
        // Prepend the sheet protection
552
        // Prepend the sheet protection
414
        $this->_storeProtect();
553
        $this->_storeProtect();
415
    
554
 
416
        // Prepend the page setup
555
        // Prepend the page setup
417
        $this->_storeSetup();
556
        $this->_storeSetup();
418
    
557
 
-
 
558
        /* FIXME: margins are actually appended */
419
        // Prepend the bottom margin
559
        // Prepend the bottom margin
420
        $this->_storeMarginBottom();
560
        $this->_storeMarginBottom();
421
    
561
 
422
        // Prepend the top margin
562
        // Prepend the top margin
423
        $this->_storeMarginTop();
563
        $this->_storeMarginTop();
424
    
564
 
425
        // Prepend the right margin
565
        // Prepend the right margin
426
        $this->_storeMarginRight();
566
        $this->_storeMarginRight();
427
    
567
 
428
        // Prepend the left margin
568
        // Prepend the left margin
429
        $this->_storeMarginLeft();
569
        $this->_storeMarginLeft();
430
    
570
 
431
        // Prepend the page vertical centering
571
        // Prepend the page vertical centering
432
        $this->_storeVcenter();
572
        $this->_storeVcenter();
433
    
573
 
434
        // Prepend the page horizontal centering
574
        // Prepend the page horizontal centering
435
        $this->_storeHcenter();
575
        $this->_storeHcenter();
436
    
576
 
437
        // Prepend the page footer
577
        // Prepend the page footer
438
        $this->_storeFooter();
578
        $this->_storeFooter();
439
    
579
 
440
        // Prepend the page header
580
        // Prepend the page header
441
        $this->_storeHeader();
581
        $this->_storeHeader();
442
    
582
 
443
        // Prepend the vertical page breaks
583
        // Prepend the vertical page breaks
444
        $this->_storeVbreak();
584
        $this->_storeVbreak();
445
    
585
 
446
        // Prepend the horizontal page breaks
586
        // Prepend the horizontal page breaks
447
        $this->_storeHbreak();
587
        $this->_storeHbreak();
448
    
588
 
449
        // Prepend WSBOOL
589
        // Prepend WSBOOL
450
        $this->_storeWsbool();
590
        $this->_storeWsbool();
451
    
591
 
452
        // Prepend GRIDSET
592
        // Prepend GRIDSET
453
        $this->_storeGridset();
593
        $this->_storeGridset();
454
    
594
 
-
 
595
         //  Prepend GUTS
-
 
596
        if ($this->_BIFF_version == 0x0500) {
-
 
597
            $this->_storeGuts();
-
 
598
        }
-
 
599
 
455
        // Prepend PRINTGRIDLINES
600
        // Prepend PRINTGRIDLINES
456
        $this->_storePrintGridlines();
601
        $this->_storePrintGridlines();
457
    
602
 
458
        // Prepend PRINTHEADERS
603
        // Prepend PRINTHEADERS
459
        $this->_storePrintHeaders();
604
        $this->_storePrintHeaders();
460
    
605
 
461
        // Prepend EXTERNSHEET references
606
        // Prepend EXTERNSHEET references
-
 
607
        if ($this->_BIFF_version == 0x0500) {
462
        for ($i = $num_sheets; $i > 0; $i--)
608
            for ($i = $num_sheets; $i > 0; $i--) {
463
        {
-
 
464
            $sheetname = $sheetnames[$i-1];
609
                $sheetname = $sheetnames[$i-1];
465
            $this->_storeExternsheet($sheetname);
610
                $this->_storeExternsheet($sheetname);
-
 
611
            }
466
        }
612
        }
467
    
613
 
468
        // Prepend the EXTERNCOUNT of external references.
614
        // Prepend the EXTERNCOUNT of external references.
-
 
615
        if ($this->_BIFF_version == 0x0500) {
469
        $this->_storeExterncount($num_sheets);
616
            $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)) {
473
        {
621
            $colcount = count($this->_colinfo);
474
            for($i=0; $i < count($this->_colinfo); $i++) {
622
            for ($i = 0; $i < $colcount; $i++) {
475
                $this->_storeColinfo($this->_colinfo[$i]);
623
                $this->_storeColinfo($this->_colinfo[$i]);
476
            }
624
            }
477
            $this->_storeDefcol();
625
            $this->_storeDefcol();
478
        }
626
        }
479
    
627
 
480
        // Prepend the BOF record
628
        // Prepend the BOF record
481
        $this->_storeBof(0x0010);
629
        $this->_storeBof(0x0010);
482
    
630
 
483
        /*
631
        /*
484
        * End of prepend. Read upwards from here.
632
        * End of prepend. Read upwards from here.
485
        ***********************************************/
633
        ***********************************************/
486
    
634
 
487
        // Append
635
        // Append
488
        $this->_storeWindow2();
636
        $this->_storeWindow2();
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
    }
496
    
659
 
497
    /**
660
    /**
498
    * Retrieve the worksheet name.
661
    * Retrieve the worksheet name.
499
    * This is usefull when creating worksheets without a name.
662
    * This is usefull when creating worksheets without a name.
500
    *
663
    *
501
    * @access public
664
    * @access public
Line 503... Line 666...
503
    */
666
    */
504
    function getName()
667
    function getName()
505
    {
668
    {
506
        return $this->name;
669
        return $this->name;
507
    }
670
    }
508
    
671
 
509
    /**
672
    /**
510
    * Retrieves data from memory in one chunk, or from disk in $buffer
673
    * Retrieves data from memory in one chunk, or from disk in $buffer
511
    * sized chunks.
674
    * sized chunks.
512
    *
675
    *
513
    * @return string The data
676
    * @return string The data
514
    */
677
    */
515
    function getData()
678
    function getData()
516
    {
679
    {
517
        $buffer = 4096;
680
        $buffer = 4096;
518
    
681
 
519
        // Return data stored in memory
682
        // Return data stored in memory
520
        if (isset($this->_data))
683
        if (isset($this->_data)) {
521
        {
-
 
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)
693
        if ($this->_using_tmpfile) {
532
        {
-
 
533
            if ($tmp = fread($this->_filehandle, $buffer)) {
694
            if ($tmp = fread($this->_filehandle, $buffer)) {
534
                return($tmp);
695
                return $tmp;
535
            }
696
            }
536
        }
697
        }
537
    
698
 
538
        // No data to return
699
        // No data to return
539
        return('');
700
        return '';
540
    }
701
    }
541
    
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
-
 
727
        $this->_merged_ranges[$this->_merged_cells_record][] = array($first_row, $first_col, $last_row, $last_col);
-
 
728
        $this->_merged_cells_counter++;
-
 
729
    }
-
 
730
 
542
    /**
731
    /**
543
    * Set this worksheet as a selected worksheet,
732
    * Set this worksheet as a selected worksheet,
544
    * i.e. the worksheet has its tab highlighted.
733
    * i.e. the worksheet has its tab highlighted.
545
    *
734
    *
546
    * @access public
735
    * @access public
547
    */
736
    */
548
    function select()
737
    function select()
549
    {
738
    {
550
        $this->selected = 1;
739
        $this->selected = 1;
551
    }
740
    }
552
    
741
 
553
    /**
742
    /**
554
    * Set this worksheet as the active worksheet,
743
    * Set this worksheet as the active worksheet,
555
    * i.e. the worksheet that is displayed when the workbook is opened.
744
    * i.e. the worksheet that is displayed when the workbook is opened.
556
    * Also set it as selected.
745
    * Also set it as selected.
557
    *
746
    *
Line 560... Line 749...
560
    function activate()
749
    function activate()
561
    {
750
    {
562
        $this->selected = 1;
751
        $this->selected = 1;
563
        $this->activesheet = $this->index;
752
        $this->activesheet = $this->index;
564
    }
753
    }
565
    
754
 
566
    /**
755
    /**
567
    * Set this worksheet as the first visible sheet.
756
    * Set this worksheet as the first visible sheet.
568
    * This is necessary when there are a large number of worksheets and the
757
    * This is necessary when there are a large number of worksheets and the
569
    * activated worksheet is not visible on the screen.
758
    * activated worksheet is not visible on the screen.
570
    *
759
    *
Line 572... Line 761...
572
    */
761
    */
573
    function setFirstSheet()
762
    function setFirstSheet()
574
    {
763
    {
575
        $this->firstsheet = $this->index;
764
        $this->firstsheet = $this->index;
576
    }
765
    }
577
 
766
 
578
    /**
767
    /**
579
    * Set the worksheet protection flag
768
    * Set the worksheet protection flag
580
    * to prevent accidental modification and to
769
    * to prevent accidental modification and to
581
    * hide formulas if the locked and hidden format properties have been set.
770
    * hide formulas if the locked and hidden format properties have been set.
582
    *
771
    *
Line 586... Line 775...
586
    function protect($password)
775
    function protect($password)
587
    {
776
    {
588
        $this->_protect   = 1;
777
        $this->_protect   = 1;
589
        $this->_password  = $this->_encodePassword($password);
778
        $this->_password  = $this->_encodePassword($password);
590
    }
779
    }
591
 
780
 
592
    /**
781
    /**
593
    * Set the width of a single column or a range of columns.
782
    * Set the width of a single column or a range of columns.
594
    *
783
    *
595
    * @access public
784
    * @access public
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
    }
613
    
827
 
614
    /**
828
    /**
615
    * Set which cell or cells are selected in a worksheet
829
    * Set which cell or cells are selected in a worksheet
616
    *
830
    *
617
    * @access public
831
    * @access public
618
    * @param integer $first_row    first row in the selected quadrant
832
    * @param integer $first_row    first row in the selected quadrant
Line 622... Line 836...
622
    */
836
    */
623
    function setSelection($first_row,$first_column,$last_row,$last_column)
837
    function setSelection($first_row,$first_column,$last_row,$last_column)
624
    {
838
    {
625
        $this->_selection = array($first_row,$first_column,$last_row,$last_column);
839
        $this->_selection = array($first_row,$first_column,$last_row,$last_column);
626
    }
840
    }
627
    
841
 
628
    /**
842
    /**
629
    * Set panes and mark them as frozen.
843
    * Set panes and mark them as frozen.
630
    *
844
    *
631
    * @access public
845
    * @access public
632
    * @param array $panes This is the only parameter received and is composed of the following:
846
    * @param array $panes This is the only parameter received and is composed of the following:
Line 639... Line 853...
639
    function freezePanes($panes)
853
    function freezePanes($panes)
640
    {
854
    {
641
        $this->_frozen = 1;
855
        $this->_frozen = 1;
642
        $this->_panes  = $panes;
856
        $this->_panes  = $panes;
643
    }
857
    }
644
    
858
 
645
    /**
859
    /**
646
    * Set panes and mark them as unfrozen.
860
    * Set panes and mark them as unfrozen.
647
    *
861
    *
648
    * @access public
862
    * @access public
649
    * @param array $panes This is the only parameter received and is composed of the following:
863
    * @param array $panes This is the only parameter received and is composed of the following:
Line 656... Line 870...
656
    function thawPanes($panes)
870
    function thawPanes($panes)
657
    {
871
    {
658
        $this->_frozen = 0;
872
        $this->_frozen = 0;
659
        $this->_panes  = $panes;
873
        $this->_panes  = $panes;
660
    }
874
    }
661
    
875
 
662
    /**
876
    /**
663
    * Set the page orientation as portrait.
877
    * Set the page orientation as portrait.
664
    *
878
    *
665
    * @access public
879
    * @access public
666
    */
880
    */
667
    function setPortrait()
881
    function setPortrait()
668
    {
882
    {
669
        $this->_orientation = 1;
883
        $this->_orientation = 1;
670
    }
884
    }
671
    
885
 
672
    /**
886
    /**
673
    * Set the page orientation as landscape.
887
    * Set the page orientation as landscape.
674
    *
888
    *
675
    * @access public
889
    * @access public
676
    */
890
    */
677
    function setLandscape()
891
    function setLandscape()
678
    {
892
    {
679
        $this->_orientation = 0;
893
        $this->_orientation = 0;
680
    }
894
    }
681
    
895
 
682
    /**
896
    /**
683
    * Set the paper type. Ex. 1 = US Letter, 9 = A4
897
    * Set the paper type. Ex. 1 = US Letter, 9 = A4
684
    *
898
    *
685
    * @access public
899
    * @access public
686
    * @param integer $size The type of paper size to use
900
    * @param integer $size The type of paper size to use
687
    */
901
    */
688
    function setPaper($size = 0)
902
    function setPaper($size = 0)
689
    {
903
    {
690
        $this->_paper_size = $size;
904
        $this->_paper_size = $size;
691
    }
905
    }
692
    
906
 
693
    
907
 
694
    /**
908
    /**
695
    * Set the page header caption and optional margin.
909
    * Set the page header caption and optional margin.
696
    *
910
    *
697
    * @access public
911
    * @access public
698
    * @param string $string The header text
912
    * @param string $string The header text
Line 705... Line 919...
705
            return;
919
            return;
706
        }
920
        }
707
        $this->_header      = $string;
921
        $this->_header      = $string;
708
        $this->_margin_head = $margin;
922
        $this->_margin_head = $margin;
709
    }
923
    }
710
    
924
 
711
    /**
925
    /**
712
    * Set the page footer caption and optional margin.
926
    * Set the page footer caption and optional margin.
713
    *
927
    *
714
    * @access public
928
    * @access public
715
    * @param string $string The footer text
929
    * @param string $string The footer text
Line 722... Line 936...
722
            return;
936
            return;
723
        }
937
        }
724
        $this->_footer      = $string;
938
        $this->_footer      = $string;
725
        $this->_margin_foot = $margin;
939
        $this->_margin_foot = $margin;
726
    }
940
    }
727
    
941
 
728
    /**
942
    /**
729
    * Center the page horinzontally.
943
    * Center the page horinzontally.
730
    *
944
    *
731
    * @access public
945
    * @access public
732
    * @param integer $center the optional value for centering. Defaults to 1 (center).
946
    * @param integer $center the optional value for centering. Defaults to 1 (center).
733
    */
947
    */
734
    function centerHorizontally($center = 1)
948
    function centerHorizontally($center = 1)
735
    {
949
    {
736
        $this->_hcenter = $center;
950
        $this->_hcenter = $center;
737
    }
951
    }
738
    
952
 
739
    /**
953
    /**
740
    * Center the page vertically.
954
    * Center the page vertically.
741
    *
955
    *
742
    * @access public
956
    * @access public
743
    * @param integer $center the optional value for centering. Defaults to 1 (center).
957
    * @param integer $center the optional value for centering. Defaults to 1 (center).
744
    */
958
    */
745
    function centerVertically($center = 1)
959
    function centerVertically($center = 1)
746
    {
960
    {
747
        $this->_vcenter = $center;
961
        $this->_vcenter = $center;
748
    }
962
    }
749
    
963
 
750
    /**
964
    /**
751
    * Set all the page margins to the same value in inches.
965
    * Set all the page margins to the same value in inches.
752
    *
966
    *
753
    * @access public
967
    * @access public
754
    * @param float $margin The margin to set in inches
968
    * @param float $margin The margin to set in inches
Line 758... Line 972...
758
        $this->setMarginLeft($margin);
972
        $this->setMarginLeft($margin);
759
        $this->setMarginRight($margin);
973
        $this->setMarginRight($margin);
760
        $this->setMarginTop($margin);
974
        $this->setMarginTop($margin);
761
        $this->setMarginBottom($margin);
975
        $this->setMarginBottom($margin);
762
    }
976
    }
763
    
977
 
764
    /**
978
    /**
765
    * Set the left and right margins to the same value in inches.
979
    * Set the left and right margins to the same value in inches.
766
    *
980
    *
767
    * @access public
981
    * @access public
768
    * @param float $margin The margin to set in inches
982
    * @param float $margin The margin to set in inches
Line 770... Line 984...
770
    function setMargins_LR($margin)
984
    function setMargins_LR($margin)
771
    {
985
    {
772
        $this->setMarginLeft($margin);
986
        $this->setMarginLeft($margin);
773
        $this->setMarginRight($margin);
987
        $this->setMarginRight($margin);
774
    }
988
    }
775
    
989
 
776
    /**
990
    /**
777
    * Set the top and bottom margins to the same value in inches.
991
    * Set the top and bottom margins to the same value in inches.
778
    *
992
    *
779
    * @access public
993
    * @access public
780
    * @param float $margin The margin to set in inches
994
    * @param float $margin The margin to set in inches
Line 782... Line 996...
782
    function setMargins_TB($margin)
996
    function setMargins_TB($margin)
783
    {
997
    {
784
        $this->setMarginTop($margin);
998
        $this->setMarginTop($margin);
785
        $this->setMarginBottom($margin);
999
        $this->setMarginBottom($margin);
786
    }
1000
    }
787
    
1001
 
788
    /**
1002
    /**
789
    * Set the left margin in inches.
1003
    * Set the left margin in inches.
790
    *
1004
    *
791
    * @access public
1005
    * @access public
792
    * @param float $margin The margin to set in inches
1006
    * @param float $margin The margin to set in inches
793
    */
1007
    */
794
    function setMarginLeft($margin = 0.75)
1008
    function setMarginLeft($margin = 0.75)
795
    {
1009
    {
796
        $this->_margin_left = $margin;
1010
        $this->_margin_left = $margin;
797
    }
1011
    }
798
    
1012
 
799
    /**
1013
    /**
800
    * Set the right margin in inches.
1014
    * Set the right margin in inches.
801
    *
1015
    *
802
    * @access public
1016
    * @access public
803
    * @param float $margin The margin to set in inches
1017
    * @param float $margin The margin to set in inches
804
    */
1018
    */
805
    function setMarginRight($margin = 0.75)
1019
    function setMarginRight($margin = 0.75)
806
    {
1020
    {
807
        $this->_margin_right = $margin;
1021
        $this->_margin_right = $margin;
808
    }
1022
    }
809
    
1023
 
810
    /**
1024
    /**
811
    * Set the top margin in inches.
1025
    * Set the top margin in inches.
812
    *
1026
    *
813
    * @access public
1027
    * @access public
814
    * @param float $margin The margin to set in inches
1028
    * @param float $margin The margin to set in inches
815
    */
1029
    */
816
    function setMarginTop($margin = 1.00)
1030
    function setMarginTop($margin = 1.00)
817
    {
1031
    {
818
        $this->_margin_top = $margin;
1032
        $this->_margin_top = $margin;
819
    }
1033
    }
820
    
1034
 
821
    /**
1035
    /**
822
    * Set the bottom margin in inches.
1036
    * Set the bottom margin in inches.
823
    *
1037
    *
824
    * @access public
1038
    * @access public
825
    * @param float $margin The margin to set in inches
1039
    * @param float $margin The margin to set in inches
826
    */
1040
    */
827
    function setMarginBottom($margin = 1.00)
1041
    function setMarginBottom($margin = 1.00)
828
    {
1042
    {
829
        $this->_margin_bottom = $margin;
1043
        $this->_margin_bottom = $margin;
830
    }
1044
    }
831
    
1045
 
832
    /**
1046
    /**
833
    * Set the rows to repeat at the top of each printed page.
1047
    * Set the rows to repeat at the top of each printed page.
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
    }
849
    
1062
 
850
    /**
1063
    /**
851
    * Set the columns to repeat at the left hand side of each printed page.
1064
    * Set the columns to repeat at the left hand side of each printed page.
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
    }
867
    
1079
 
868
    /**
1080
    /**
869
    * Set the area of each worksheet that will be printed.
1081
    * Set the area of each worksheet that will be printed.
870
    *
1082
    *
871
    * @access public
1083
    * @access public
872
    * @param integer $first_row First row of the area to print
1084
    * @param integer $first_row First row of the area to print
Line 879... Line 1091...
879
        $this->print_rowmin  = $first_row;
1091
        $this->print_rowmin  = $first_row;
880
        $this->print_colmin  = $first_col;
1092
        $this->print_colmin  = $first_col;
881
        $this->print_rowmax  = $last_row;
1093
        $this->print_rowmax  = $last_row;
882
        $this->print_colmax  = $last_col;
1094
        $this->print_colmax  = $last_col;
883
    }
1095
    }
884
    
1096
 
885
    
1097
 
886
    /**
1098
    /**
887
    * Set the option to hide gridlines on the printed page. 
1099
    * Set the option to hide gridlines on the printed page.
888
    *
1100
    *
889
    * @access public
1101
    * @access public
890
    */
1102
    */
891
    function hideGridlines()
1103
    function hideGridlines()
892
    {
1104
    {
893
        $this->_print_gridlines = 0;
1105
        $this->_print_gridlines = 0;
894
    }
1106
    }
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).
901
    */
1123
    */
902
    function printRowColHeaders($print = 1)
1124
    function printRowColHeaders($print = 1)
903
    {
1125
    {
904
        $this->_print_headers = $print;
1126
        $this->_print_headers = $print;
905
    }
1127
    }
906
    
1128
 
907
    /**
1129
    /**
908
    * Set the vertical and horizontal number of pages that will define the maximum area printed.
1130
    * Set the vertical and horizontal number of pages that will define the maximum area printed.
909
    * It doesn't seem to work with OpenOffice.
1131
    * It doesn't seem to work with OpenOffice.
910
    *
1132
    *
911
    * @access public
1133
    * @access public
Line 917... Line 1139...
917
    {
1139
    {
918
        $this->_fit_page      = 1;
1140
        $this->_fit_page      = 1;
919
        $this->_fit_width     = $width;
1141
        $this->_fit_width     = $width;
920
        $this->_fit_height    = $height;
1142
        $this->_fit_height    = $height;
921
    }
1143
    }
922
    
1144
 
923
    /**
1145
    /**
924
    * Store the horizontal page breaks on a worksheet (for printing).
1146
    * Store the horizontal page breaks on a worksheet (for printing).
925
    * The breaks represent the row after which the break is inserted.
1147
    * The breaks represent the row after which the break is inserted.
926
    *
1148
    *
927
    * @access public
1149
    * @access public
928
    * @param array $breaks Array containing the horizontal page breaks
1150
    * @param array $breaks Array containing the horizontal page breaks
929
    */
1151
    */
930
    function setHPagebreaks($breaks)
1152
    function setHPagebreaks($breaks)
931
    {
1153
    {
932
        foreach($breaks as $break) {
1154
        foreach ($breaks as $break) {
933
            array_push($this->_hbreaks,$break);
1155
            array_push($this->_hbreaks, $break);
934
        }
1156
        }
935
    }
1157
    }
936
    
1158
 
937
    /**
1159
    /**
938
    * Store the vertical page breaks on a worksheet (for printing).
1160
    * Store the vertical page breaks on a worksheet (for printing).
939
    * The breaks represent the column after which the break is inserted.
1161
    * The breaks represent the column after which the break is inserted.
940
    *
1162
    *
941
    * @access public
1163
    * @access public
942
    * @param array $breaks Array containing the vertical page breaks
1164
    * @param array $breaks Array containing the vertical page breaks
943
    */
1165
    */
944
    function setVPagebreaks($breaks)
1166
    function setVPagebreaks($breaks)
945
    {
1167
    {
946
        foreach($breaks as $break) {
1168
        foreach ($breaks as $break) {
947
            array_push($this->_vbreaks,$break);
1169
            array_push($this->_vbreaks, $break);
948
        }
1170
        }
949
    }
1171
    }
950
    
1172
 
951
    
1173
 
952
    /**
1174
    /**
953
    * Set the worksheet zoom factor.
1175
    * Set the worksheet zoom factor.
954
    *
1176
    *
955
    * @access public
1177
    * @access public
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
        }
966
    
1187
 
967
        $this->_zoom = floor($scale);
1188
        $this->_zoom = floor($scale);
968
    }
1189
    }
969
    
1190
 
970
    /**
1191
    /**
971
    * Set the scale factor for the printed page. 
1192
    * Set the scale factor for the printed page.
972
    * It turns off the "fit to page" option
1193
    * It turns off the "fit to page" option
973
    *
1194
    *
974
    * @access public
1195
    * @access public
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
        }
985
    
1205
 
986
        // Turn off "fit to page" option
1206
        // Turn off "fit to page" option
987
        $this->_fit_page    = 0;
1207
        $this->_fit_page = 0;
988
    
1208
 
989
        $this->_print_scale = floor($scale);
1209
        $this->_print_scale = floor($scale);
990
    }
1210
    }
991
    
1211
 
992
    /**
1212
    /**
993
    * Map to the appropriate write method acording to the token recieved.
1213
    * Map to the appropriate write method acording to the token recieved.
994
    *
1214
    *
995
    * @access public
1215
    * @access public
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
    }*/
1007
    
-
 
1008
    
1227
 
1009
        // Match number
-
 
1010
        if (preg_match("/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/",$token)) {
1228
        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
1232
            // Match http or ftp URL
1014
        elseif (preg_match("/^[fh]tt?p:\/\//",$token)) {
-
 
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:
1235
            // Match mailto:
1018
        elseif (preg_match("/^mailto:/",$token)) {
-
 
1019
            return $this->writeUrl($row, $col, $token, $format);
1236
            return $this->writeUrl($row, $col, $token, '', $format);
1020
        }
-
 
1021
        // Match internal or external sheet link
1237
        } elseif (preg_match("/^(?:in|ex)ternal:/", $token)) {
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
        }
-
 
1025
        // Match formula
-
 
1026
        elseif (preg_match("/^=/",$token)) {
1240
        } elseif (preg_match("/^=/", $token)) {
1027
            return $this->writeFormula($row, $col, $token, $format);
-
 
1028
        }
-
 
1029
        // Match formula
1241
            // Match formula
1030
        elseif (preg_match("/^@/",$token)) {
-
 
1031
            return $this->writeFormula($row, $col, $token, $format);
1242
            return $this->writeFormula($row, $col, $token, $format);
1032
        }
1243
        } elseif ($token == '') {
1033
        // Match blank
1244
            // Match blank
1034
        elseif ($token == '') {
-
 
1035
            return $this->writeBlank($row,$col,$format);
1245
            return $this->writeBlank($row, $col, $format);
1036
        }
1246
        } else {
1037
        // Default: match string
1247
            // Default: match string
1038
        else {
-
 
1039
            return $this->writeString($row,$col,$token,$format);
1248
            return $this->writeString($row, $col, $token, $format);
1040
        }
1249
        }
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
    *
1046
    * @access public
1255
    * @access public
1047
    * @param
1256
    * @param integer $row    The row we are writing to
-
 
1257
    * @param integer $col    The first col (leftmost col) we are writing to
-
 
1258
    * @param array   $val    The array of values to write
-
 
1259
    * @param mixed   $format The optional format to apply to the cell
1048
    * @return 
1260
    * @return mixed PEAR_Error on failure
1049
    */
1261
    */
Line 1050... Line 1262...
1050
 
1262
 
1051
    function writeRow($row, $col, $val, $format=0)
1263
    function writeRow($row, $col, $val, $format = null)
-
 
1264
    {
1052
    {   
1265
        $retval = '';
1053
        if (is_array($val)) {
1266
        if (is_array($val)) {
1054
            foreach($val as $v) {
1267
            foreach ($val as $v) {
1055
                if (is_array($v)) {
1268
                if (is_array($v)) {
1056
                    $this->writeCol($row, $col, $v, $format);
1269
                    $this->writeCol($row, $col, $v, $format);
1057
                } else {
1270
                } else {
1058
                    $this->write($row, $col, $v, $format);
1271
                    $this->write($row, $col, $v, $format);
Line 1062... Line 1275...
1062
        } else {
1275
        } else {
1063
            $retval = new PEAR_Error('$val needs to be an array');
1276
            $retval = new PEAR_Error('$val needs to be an array');
1064
        }
1277
        }
1065
        return($retval);
1278
        return($retval);
1066
    }
1279
    }
1067
      
1280
 
1068
    /**
1281
    /**
1069
    * Write an array of values as a column
1282
    * Write an array of values as a column
1070
    *
1283
    *
1071
    * @access public
1284
    * @access public
-
 
1285
    * @param integer $row    The first row (uppermost row) we are writing to
1072
    * @param
1286
    * @param integer $col    The col we are writing to
-
 
1287
    * @param array   $val    The array of values to write
-
 
1288
    * @param mixed   $format The optional format to apply to the cell
1073
    * @return 
1289
    * @return mixed PEAR_Error on failure
1074
    */
1290
    */
1075
    
1291
 
1076
    function writeCol($row, $col, $val, $format=0)
1292
    function writeCol($row, $col, $val, $format = null)
1077
    {
1293
    {
-
 
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);
1081
                $row++;
1298
                $row++;
1082
            }
1299
            }
1083
        } else {
1300
        } else {
1084
            $retval = new PEAR_Error('$val needs to be an array');
1301
            $retval = new PEAR_Error('$val needs to be an array');
1085
        }
1302
        }
1086
        return($retval);
1303
        return($retval);
1087
    }
1304
    }
1088
    
1305
 
1089
    /**
1306
    /**
1090
    * Returns an index to the XF record in the workbook
1307
    * Returns an index to the XF record in the workbook
1091
    *
1308
    *
1092
    * @access private
1309
    * @access private
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
    }
1105
    
1321
 
1106
    
1322
 
1107
    /******************************************************************************
1323
    /******************************************************************************
1108
    *******************************************************************************
1324
    *******************************************************************************
1109
    *
1325
    *
1110
    * Internal methods
1326
    * Internal methods
1111
    */
1327
    */
1112
    
1328
 
1113
    
1329
 
1114
    /**
1330
    /**
1115
    * Store Worksheet data in memory using the parent's class append() or to a
1331
    * Store Worksheet data in memory using the parent's class append() or to a
1116
    * temporary file, the default.
1332
    * temporary file, the default.
1117
    *
1333
    *
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
    }
1136
    
1350
 
1137
    /**
1351
    /**
1138
    * Substitute an Excel cell reference in A1 notation for  zero based row and
1352
    * Substitute an Excel cell reference in A1 notation for  zero based row and
1139
    * column values in an argument list.
1353
    * column values in an argument list.
1140
    *
1354
    *
1141
    * Ex: ("A4", "Hello") is converted to (3, 0, "Hello").
1355
    * Ex: ("A4", "Hello") is converted to (3, 0, "Hello").
Line 1145... Line 1359...
1145
    * @return array
1359
    * @return array
1146
    */
1360
    */
1147
    function _substituteCellref($cell)
1361
    function _substituteCellref($cell)
1148
    {
1362
    {
1149
        $cell = strtoupper($cell);
1363
        $cell = strtoupper($cell);
1150
    
1364
 
1151
        // Convert a column range: 'A:A' or 'B:G'
1365
        // Convert a column range: 'A:A' or 'B:G'
1152
        if (preg_match("/([A-I]?[A-Z]):([A-I]?[A-Z])/",$cell,$match)) {
1366
        if (preg_match("/([A-I]?[A-Z]):([A-I]?[A-Z])/", $cell, $match)) {
1153
            list($no_use, $col1) =  $this->_cellToRowcol($match[1] .'1'); // Add a dummy row
1367
            list($no_use, $col1) =  $this->_cellToRowcol($match[1] .'1'); // Add a dummy row
1154
            list($no_use, $col2) =  $this->_cellToRowcol($match[2] .'1'); // Add a dummy row
1368
            list($no_use, $col2) =  $this->_cellToRowcol($match[2] .'1'); // Add a dummy row
1155
            return(array($col1, $col2));
1369
            return(array($col1, $col2));
1156
        }
1370
        }
1157
    
1371
 
1158
        // Convert a cell range: 'A1:B7'
1372
        // Convert a cell range: 'A1:B7'
1159
        if (preg_match("/\$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)/",$cell,$match)) {
1373
        if (preg_match("/\$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)/", $cell, $match)) {
1160
            list($row1, $col1) =  $this->_cellToRowcol($match[1]);
1374
            list($row1, $col1) =  $this->_cellToRowcol($match[1]);
1161
            list($row2, $col2) =  $this->_cellToRowcol($match[2]);
1375
            list($row2, $col2) =  $this->_cellToRowcol($match[2]);
1162
            return(array($row1, $col1, $row2, $col2));
1376
            return(array($row1, $col1, $row2, $col2));
1163
        }
1377
        }
1164
    
1378
 
1165
        // Convert a cell reference: 'A1' or 'AD2000'
1379
        // Convert a cell reference: 'A1' or 'AD2000'
1166
        if (preg_match("/\$?([A-I]?[A-Z]\$?\d+)/",$cell)) {
1380
        if (preg_match("/\$?([A-I]?[A-Z]\$?\d+)/", $cell)) {
1167
            list($row1, $col1) =  $this->_cellToRowcol($match[1]);
1381
            list($row1, $col1) =  $this->_cellToRowcol($match[1]);
1168
            return(array($row1, $col1));
1382
            return(array($row1, $col1));
1169
        }
1383
        }
1170
    
1384
 
1171
        // TODO use real error codes
1385
        // TODO use real error codes
1172
        $this->raiseError("Unknown cell reference $cell", 0, PEAR_ERROR_DIE);
1386
        $this->raiseError("Unknown cell reference $cell", 0, PEAR_ERROR_DIE);
1173
    }
1387
    }
1174
    
1388
 
1175
    /**
1389
    /**
1176
    * Convert an Excel cell reference in A1 notation to a zero based row and column
1390
    * Convert an Excel cell reference in A1 notation to a zero based row and column
1177
    * reference; converts C1 to (0, 2).
1391
    * reference; converts C1 to (0, 2).
1178
    *
1392
    *
1179
    * @access private
1393
    * @access private
Line 1183... Line 1397...
1183
    function _cellToRowcol($cell)
1397
    function _cellToRowcol($cell)
1184
    {
1398
    {
1185
        preg_match("/\$?([A-I]?[A-Z])\$?(\d+)/",$cell,$match);
1399
        preg_match("/\$?([A-I]?[A-Z])\$?(\d+)/",$cell,$match);
1186
        $col     = $match[1];
1400
        $col     = $match[1];
1187
        $row     = $match[2];
1401
        $row     = $match[2];
1188
    
1402
 
1189
        // Convert base26 column string to number
1403
        // Convert base26 column string to number
1190
        $chars = explode('', $col);
1404
        $chars = explode('', $col);
1191
        $expn  = 0;
1405
        $expn  = 0;
1192
        $col   = 0;
1406
        $col   = 0;
1193
    
1407
 
1194
        while ($chars) {
1408
        while ($chars) {
1195
            $char = array_pop($chars);        // LS char first
1409
            $char = array_pop($chars);        // LS char first
1196
            $col += (ord($char) -ord('A') +1) * pow(26,$expn);
1410
            $col += (ord($char) -ord('A') +1) * pow(26,$expn);
1197
            $expn++;
1411
            $expn++;
1198
        }
1412
        }
1199
    
1413
 
1200
        // Convert 1-index to zero-index
1414
        // Convert 1-index to zero-index
1201
        $row--;
1415
        $row--;
1202
        $col--;
1416
        $col--;
1203
    
1417
 
1204
        return(array($row, $col));
1418
        return(array($row, $col));
1205
    }
1419
    }
1206
 
1420
 
1207
    /**
1421
    /**
1208
    * Based on the algorithm provided by Daniel Rentz of OpenOffice.
1422
    * Based on the algorithm provided by Daniel Rentz of OpenOffice.
1209
    *
1423
    *
1210
    * @access private
1424
    * @access private
1211
    * @param string $plaintext The password to be encoded in plaintext.
1425
    * @param string $plaintext The password to be encoded in plaintext.
Line 1213... Line 1427...
1213
    */
1427
    */
1214
    function _encodePassword($plaintext)
1428
    function _encodePassword($plaintext)
1215
    {
1429
    {
1216
        $password = 0x0000;
1430
        $password = 0x0000;
1217
        $i        = 1;       // char position
1431
        $i        = 1;       // char position
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)
1435
        foreach ($chars as $char) {
1222
        {
-
 
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);
1227
            $i++;
1440
            $i++;
1228
        }
1441
        }
1229
    
1442
 
1230
        $password ^= strlen($plaintext);
1443
        $password ^= strlen($plaintext);
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;
1234
    }
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
    {
-
 
1478
        $this->_Arabic = ($rtl ? 1 : 0);
1235
 
1479
     }
1236
    
1480
 
1237
    /******************************************************************************
1481
    /******************************************************************************
1238
    *******************************************************************************
1482
    *******************************************************************************
1239
    *
1483
    *
1240
    * BIFF RECORDS
1484
    * BIFF RECORDS
1241
    */
1485
    */
1242
    
1486
 
1243
    
1487
 
1244
    /**
1488
    /**
1245
    * Write a double to the specified row and column (zero indexed).
1489
    * Write a double to the specified row and column (zero indexed).
1246
    * An integer can be written as a double. Excel will display an
1490
    * An integer can be written as a double. Excel will display an
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
1263
    
1507
 
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
1510
        // Check that row and col are valid and store max and min values
1267
        if ($row >= $this->_xls_rowmax)
1511
        if ($row >= $this->_xls_rowmax) {
1268
        {
-
 
1269
            return(-2);
1512
            return(-2);
1270
        }
1513
        }
1271
        if ($col >= $this->_xls_colmax)
1514
        if ($col >= $this->_xls_colmax) {
1272
        {
-
 
1273
            return(-2);
1515
            return(-2);
1274
        }
1516
        }
1275
        if ($row <  $this->_dim_rowmin) 
1517
        if ($row <  $this->_dim_rowmin)  {
1276
        {
-
 
1277
            $this->_dim_rowmin = $row;
1518
            $this->_dim_rowmin = $row;
1278
        }
1519
        }
1279
        if ($row >  $this->_dim_rowmax) 
1520
        if ($row >  $this->_dim_rowmax)  {
1280
        {
-
 
1281
            $this->_dim_rowmax = $row;
1521
            $this->_dim_rowmax = $row;
1282
        }
1522
        }
1283
        if ($col <  $this->_dim_colmin) 
1523
        if ($col <  $this->_dim_colmin)  {
1284
        {
-
 
1285
            $this->_dim_colmin = $col;
1524
            $this->_dim_colmin = $col;
1286
        }
1525
        }
1287
        if ($col >  $this->_dim_colmax) 
1526
        if ($col >  $this->_dim_colmax)  {
1288
        {
-
 
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);
1531
        $data      = pack("vvv", $row, $col, $xf);
1294
        $xl_double = pack("d",   $num);
1532
        $xl_double = pack("d",   $num);
1295
        if ($this->_byte_order) // if it's Big Endian
1533
        if ($this->_byte_order) { // if it's Big Endian
1296
        {
-
 
1297
            $xl_double = strrev($xl_double);
1534
            $xl_double = strrev($xl_double);
1298
        }
1535
        }
1299
    
1536
 
1300
        $this->_append($header.$data.$xl_double);
1537
        $this->_append($header.$data.$xl_double);
1301
        return(0);
1538
        return(0);
1302
    }
1539
    }
1303
    
1540
 
1304
    /**
1541
    /**
1305
    * Write a string to the specified row and column (zero indexed).
1542
    * Write a string to the specified row and column (zero indexed).
1306
    * NOTE: there is an Excel 5 defined limit of 255 characters.
1543
    * NOTE: there is an Excel 5 defined limit of 255 characters.
1307
    * $format is optional.
1544
    * $format is optional.
1308
    * Returns  0 : normal termination
1545
    * Returns  0 : normal termination
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
1325
        
1565
 
1326
        $str_error = 0;
1566
        $str_error = 0;
1327
    
1567
 
1328
        // Check that row and col are valid and store max and min values
1568
        // Check that row and col are valid and store max and min values
1329
        if ($row >= $this->_xls_rowmax) 
1569
        if ($row >= $this->_xls_rowmax) {
1330
        {
-
 
1331
            return(-2);
1570
            return(-2);
1332
        }
1571
        }
1333
        if ($col >= $this->_xls_colmax) 
1572
        if ($col >= $this->_xls_colmax) {
1334
        {
-
 
1335
            return(-2);
1573
            return(-2);
1336
        }
1574
        }
1337
        if ($row <  $this->_dim_rowmin) 
1575
        if ($row <  $this->_dim_rowmin) {
1338
        {
-
 
1339
            $this->_dim_rowmin = $row;
1576
            $this->_dim_rowmin = $row;
1340
        }
1577
        }
1341
        if ($row >  $this->_dim_rowmax) 
1578
        if ($row >  $this->_dim_rowmax) {
1342
        {
-
 
1343
            $this->_dim_rowmax = $row;
1579
            $this->_dim_rowmax = $row;
1344
        }
1580
        }
1345
        if ($col <  $this->_dim_colmin) 
1581
        if ($col <  $this->_dim_colmin) {
1346
        {
-
 
1347
            $this->_dim_colmin = $col;
1582
            $this->_dim_colmin = $col;
1348
        }
1583
        }
1349
        if ($col >  $this->_dim_colmax) 
1584
        if ($col >  $this->_dim_colmax) {
1350
        {
-
 
1351
            $this->_dim_colmax = $col;
1585
            $this->_dim_colmax = $col;
1352
        }
1586
        }
1353
    
1587
 
1354
        if ($strlen > $this->_xls_strmax)  // LABEL must be < 255 chars
1588
        if ($strlen > $this->_xls_strmax) { // LABEL must be < 255 chars
1355
        {
-
 
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;
1358
            $strlen    = $this->_xls_strmax;
1591
            $strlen    = $this->_xls_strmax;
1359
            $str_error = -3;
1592
            $str_error = -3;
1360
        }
1593
        }
1361
    
1594
 
1362
        $header    = pack("vv",   $record, $length);
1595
        $header    = pack("vv",   $record, $length);
1363
        $data      = pack("vvvv", $row, $col, $xf, $strlen);
1596
        $data      = pack("vvvv", $row, $col, $xf, $strlen);
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;
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);
1413
        $data      = pack("vvv", $row, $col, $note_length);
1745
        $data      = pack("vvv", $row, $col, $note_length);
Line 1414... Line 1746...
1414
        $this->_append($header.$data.substr($note, 0, 2048));
1746
        $this->_append($header . $data . substr($note, 0, 2048));
1415
 
-
 
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);
1420
            $header = pack("vv",   $record, $length);
1751
            $header = pack("vv",   $record, $length);
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
        }
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
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
1786
        // Check that row and col are valid and store max and min values
1457
        if ($row >= $this->_xls_rowmax) 
1787
        if ($row >= $this->_xls_rowmax) {
1458
        {
-
 
1459
            return(-2);
1788
            return(-2);
1460
        }
1789
        }
1461
        if ($col >= $this->_xls_colmax) 
1790
        if ($col >= $this->_xls_colmax) {
1462
        {
-
 
1463
            return(-2);
1791
            return(-2);
1464
        }
1792
        }
1465
        if ($row <  $this->_dim_rowmin) 
1793
        if ($row <  $this->_dim_rowmin) {
1466
        {
-
 
1467
            $this->_dim_rowmin = $row;
1794
            $this->_dim_rowmin = $row;
1468
        }
1795
        }
1469
        if ($row >  $this->_dim_rowmax) 
1796
        if ($row >  $this->_dim_rowmax) {
1470
        {
-
 
1471
            $this->_dim_rowmax = $row;
1797
            $this->_dim_rowmax = $row;
1472
        }
1798
        }
1473
        if ($col <  $this->_dim_colmin) 
1799
        if ($col <  $this->_dim_colmin) {
1474
        {
-
 
1475
            $this->_dim_colmin = $col;
1800
            $this->_dim_colmin = $col;
1476
        }
1801
        }
1477
        if ($col >  $this->_dim_colmax) 
1802
        if ($col >  $this->_dim_colmax) {
1478
        {
-
 
1479
            $this->_dim_colmax = $col;
1803
            $this->_dim_colmax = $col;
1480
        }
1804
        }
1481
    
1805
 
1482
        $header    = pack("vv",  $record, $length);
1806
        $header    = pack("vv",  $record, $length);
1483
        $data      = pack("vvv", $row, $col, $xf);
1807
        $data      = pack("vvv", $row, $col, $xf);
1484
        $this->_append($header.$data);
1808
        $this->_append($header . $data);
1485
        return 0;
1809
        return 0;
1486
    }
1810
    }
Line 1487... Line 1811...
1487
 
1811
 
1488
    /**
1812
    /**
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
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.
1509
        // Clearly we are not in a position to calculate this a priori. Instead
1833
        // Clearly we are not in a position to calculate this a priori. Instead
1510
        // we set $num to zero and set the option flags in $grbit to ensure
1834
        // we set $num to zero and set the option flags in $grbit to ensure
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
1517
    
1841
 
1518
    
1842
 
1519
        // Check that row and col are valid and store max and min values
1843
        // Check that row and col are valid and store max and min values
1520
        if ($row >= $this->_xls_rowmax)
1844
        if ($this->_checkRowCol($row, $col) == false) {
1521
        {
-
 
1522
            return(-2);
1845
            return -2;
1523
        }
1846
        }
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
        {
-
 
1542
            $this->_dim_colmax = $col;
-
 
1543
        }
-
 
1544
    
1847
 
1545
        // Strip the '=' or '@' sign at the beginning of the formula string
1848
        // Strip the '=' or '@' sign at the beginning of the formula string
1546
        if (preg_match("/^=/",$formula)) {
1849
        if (preg_match("/^=/", $formula)) {
1547
            $formula = preg_replace("/(^=)/","",$formula);
1850
            $formula = preg_replace("/(^=)/", "", $formula);
1548
        }
-
 
1549
        elseif (preg_match("/^@/",$formula)) {
1851
        } elseif (preg_match("/^@/", $formula)) {
1550
            $formula = preg_replace("/(^@)/","",$formula);
1852
            $formula = preg_replace("/(^@)/", "", $formula);
1551
        }
-
 
1552
        else
1853
        } else {
1553
        {
-
 
1554
            // Error handling
1854
            // Error handling
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
    
1858
 
1559
        // Parse the formula using the parser in Parser.php
1859
        // Parse the formula using the parser in Parser.php
1560
        $error = $this->_parser->parse($formula);
1860
        $error = $this->_parser->parse($formula);
1561
        if ($this->isError($error))
1861
        if ($this->isError($error)) {
1562
        {
-
 
1563
            $this->writeString($row, $col, $error->getMessage()); 
1862
            $this->writeString($row, $col, $error->getMessage());
1564
            return -1;
1863
            return -1;
1565
        }
1864
        }
1566
    
1865
 
1567
        $formula = $this->_parser->toReversePolish();
1866
        $formula = $this->_parser->toReversePolish();
1568
        if ($this->isError($formula))
1867
        if ($this->isError($formula)) {
1569
        {
-
 
1570
            $this->writeString($row, $col, $formula->getMessage());
1868
            $this->writeString($row, $col, $formula->getMessage());
1571
            return -1;
1869
            return -1;
1572
        }
1870
        }
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
1576
    
1874
 
1577
        $header    = pack("vv",      $record, $length);
1875
        $header    = pack("vv",      $record, $length);
1578
        $data      = pack("vvvdvVv", $row, $col, $xf, $num,
1876
        $data      = pack("vvvdvVv", $row, $col, $xf, $num,
1579
                                     $grbit, $chn, $formlen);
1877
                                     $grbit, $unknown, $formlen);
1580
    
1878
 
1581
        $this->_append($header.$data.$formula);
1879
        $this->_append($header . $data . $formula);
1582
        return 0;
1880
        return 0;
1583
    }
1881
    }
1584
    
1882
 
1585
    /**
1883
    /**
1586
    * Write a hyperlink.
1884
    * Write a hyperlink.
1587
    * This is comprised of two elements: the visible label and
1885
    * This is comprised of two elements: the visible label and
1588
    * the invisible link. The visible label is the same as the link unless an
1886
    * the invisible link. The visible label is the same as the link unless an
1589
    * alternative string is specified. The label is written using the
1887
    * alternative string is specified. The label is written using the
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
    }
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
1616
    * written to a range of cells. This function also decides the type of hyperlink
1914
    * written to a range of cells. This function also decides the type of hyperlink
1617
    * to be written. These are either, Web (http, ftp, mailto), Internal
1915
    * to be written. These are either, Web (http, ftp, mailto), Internal
1618
    * (Sheet1!A1) or external ('c:\temp\foo.xls#Sheet1!A1').
1916
    * (Sheet1!A1) or external ('c:\temp\foo.xls#Sheet1!A1').
Line 1626... Line 1924...
1626
    * @param string  $url    URL string
1924
    * @param string  $url    URL string
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
    */
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)
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
1636
        if (preg_match('[^internal:]', $url)) {
1934
        if (preg_match('[^internal:]', $url)) {
1637
            return($this->_writeUrlInternal($row1, $col1, $row2, $col2, $url, $string, $format));
1935
            return($this->_writeUrlInternal($row1, $col1, $row2, $col2, $url, $string, $format));
1638
        }
1936
        }
1639
        if (preg_match('[^external:]', $url)) {
1937
        if (preg_match('[^external:]', $url)) {
1640
            return($this->_writeUrlExternal($row1, $col1, $row2, $col2, $url, $string, $format));
1938
            return($this->_writeUrlExternal($row1, $col1, $row2, $col2, $url, $string, $format));
1641
        }
1939
        }
1642
        return($this->_writeUrlWeb($row1, $col1, $row2, $col2, $url, $string, $format));
1940
        return($this->_writeUrlWeb($row1, $col1, $row2, $col2, $url, $string, $format));
1643
    }
1941
    }
1644
    
1942
 
1645
    
1943
 
1646
    /**
1944
    /**
1647
    * Used to write http, ftp and mailto hyperlinks.
1945
    * Used to write http, ftp and mailto hyperlinks.
1648
    * The link type ($options) is 0x03 is the same as absolute dir ref without
1946
    * The link type ($options) is 0x03 is the same as absolute dir ref without
1649
    * sheet. However it is differentiated by the $unknown2 data stream.
1947
    * sheet. However it is differentiated by the $unknown2 data stream.
1650
    *
1948
    *
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
1666
    
1964
 
1667
        if ($format == 0) {
1965
        if (!$format) {
1668
            $format = $this->_url_format;
1966
            $format = $this->_url_format;
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)) {
1677
            return $str_error;
1975
            return $str_error;
1678
        }
1976
        }
1679
    
1977
 
1680
        // Pack the undocumented parts of the hyperlink stream
1978
        // Pack the undocumented parts of the hyperlink stream
1681
        $unknown1    = pack("H*", "D0C9EA79F9BACE118C8200AA004BA90B02000000");
1979
        $unknown1    = pack("H*", "D0C9EA79F9BACE118C8200AA004BA90B02000000");
1682
        $unknown2    = pack("H*", "E0C9EA79F9BACE118C8200AA004BA90B");
1980
        $unknown2    = pack("H*", "E0C9EA79F9BACE118C8200AA004BA90B");
1683
    
1981
 
1684
        // Pack the option flags
1982
        // Pack the option flags
1685
        $options     = pack("V", 0x03);
1983
        $options     = pack("V", 0x03);
1686
    
1984
 
1687
        // Convert URL to a null terminated wchar string
1985
        // Convert URL to a null terminated wchar string
1688
        $url         = join("\0", preg_split("''", $url, -1, PREG_SPLIT_NO_EMPTY));
1986
        $url         = join("\0", preg_split("''", $url, -1, PREG_SPLIT_NO_EMPTY));
1689
        $url         = $url . "\0\0\0";
1987
        $url         = $url . "\0\0\0";
1690
    
1988
 
1691
        // Pack the length of the URL
1989
        // Pack the length of the URL
1692
        $url_len     = pack("V", strlen($url));
1990
        $url_len     = pack("V", strlen($url));
1693
    
1991
 
1694
        // Calculate the data length
1992
        // Calculate the data length
1695
        $length      = 0x34 + strlen($url);
1993
        $length      = 0x34 + strlen($url);
1696
    
1994
 
1697
        // Pack the header data
1995
        // Pack the header data
1698
        $header      = pack("vv",   $record, $length);
1996
        $header      = pack("vv",   $record, $length);
1699
        $data        = pack("vvvv", $row1, $row2, $col1, $col2);
1997
        $data        = pack("vvvv", $row1, $row2, $col1, $col2);
1700
    
1998
 
1701
        // Write the packed data
1999
        // Write the packed data
1702
        $this->_append( $header. $data.
2000
        $this->_append($header . $data .
1703
                        $unknown1. $options.
2001
                       $unknown1 . $options .
1704
                        $unknown2. $url_len. $url);
2002
                       $unknown2 . $url_len . $url);
1705
        return($str_error);
2003
        return($str_error);
1706
    }
2004
    }
1707
    
2005
 
1708
    /**
2006
    /**
1709
    * Used to write internal reference hyperlinks such as "Sheet1!A1".
2007
    * Used to write internal reference hyperlinks such as "Sheet1!A1".
1710
    *
2008
    *
1711
    * @access private
2009
    * @access private
1712
    * @see writeUrl()
2010
    * @see writeUrl()
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
1726
    
2024
 
1727
        if ($format == 0) {
2025
        if (!$format) {
1728
            $format = $this->_url_format;
2026
            $format = $this->_url_format;
1729
        }
2027
        }
1730
    
2028
 
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);
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;
1741
        }
2039
        }
1742
    
2040
 
1743
        // Pack the undocumented parts of the hyperlink stream
2041
        // Pack the undocumented parts of the hyperlink stream
1744
        $unknown1    = pack("H*", "D0C9EA79F9BACE118C8200AA004BA90B02000000");
2042
        $unknown1    = pack("H*", "D0C9EA79F9BACE118C8200AA004BA90B02000000");
1745
    
2043
 
1746
        // Pack the option flags
2044
        // Pack the option flags
1747
        $options     = pack("V", 0x08);
2045
        $options     = pack("V", 0x08);
1748
    
2046
 
1749
        // Convert the URL type and to a null terminated wchar string
2047
        // Convert the URL type and to a null terminated wchar string
1750
        $url         = join("\0", preg_split("''", $url, -1, PREG_SPLIT_NO_EMPTY));
2048
        $url         = join("\0", preg_split("''", $url, -1, PREG_SPLIT_NO_EMPTY));
1751
        $url         = $url . "\0\0\0";
2049
        $url         = $url . "\0\0\0";
1752
    
2050
 
1753
        // Pack the length of the URL as chars (not wchars)
2051
        // Pack the length of the URL as chars (not wchars)
1754
        $url_len     = pack("V", floor(strlen($url)/2));
2052
        $url_len     = pack("V", floor(strlen($url)/2));
1755
    
2053
 
1756
        // Calculate the data length
2054
        // Calculate the data length
1757
        $length      = 0x24 + strlen($url);
2055
        $length      = 0x24 + strlen($url);
1758
    
2056
 
1759
        // Pack the header data
2057
        // Pack the header data
1760
        $header      = pack("vv",   $record, $length);
2058
        $header      = pack("vv",   $record, $length);
1761
        $data        = pack("vvvv", $row1, $row2, $col1, $col2);
2059
        $data        = pack("vvvv", $row1, $row2, $col1, $col2);
1762
    
2060
 
1763
        // Write the packed data
2061
        // Write the packed data
1764
        $this->_append($header. $data.
2062
        $this->_append($header . $data .
1765
                       $unknown1. $options.
2063
                       $unknown1 . $options .
1766
                       $url_len. $url);
2064
                       $url_len . $url);
1767
        return($str_error);
2065
        return($str_error);
1768
    }
2066
    }
1769
    
2067
 
1770
    /**
2068
    /**
1771
    * Write links to external directory names such as 'c:\foo.xls',
2069
    * Write links to external directory names such as 'c:\foo.xls',
1772
    * c:\foo.xls#Sheet1!A1', '../../foo.xls'. and '../../foo.xls#Sheet1!A1'.
2070
    * c:\foo.xls#Sheet1!A1', '../../foo.xls'. and '../../foo.xls#Sheet1!A1'.
1773
    *
2071
    *
1774
    * Note: Excel writes some relative links with the $dir_long string. We ignore
2072
    * Note: Excel writes some relative links with the $dir_long string. We ignore
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";
-
 
2143
        } else {
-
 
2144
            $sheet_len   = '';
Line 1838... Line 2145...
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 1890... Line 2197...
1890
        $header   = pack("vv", $record, $length);
2197
        $header   = pack("vv", $record, $length);
1891
    
2198
    
1892
        // Write the packed data
2199
        // Write the packed data
1893
        $this->_append($header. $data);
2200
        $this->_append($header. $data);
1894
        return($str_error);
2201
        return($str_error);
1895
    }
2202
    }
1896
    
2203
 
1897
    
2204
 
1898
    /**
2205
    /**
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.
-
 
2211
    *                        Use null to set XF without setting height
-
 
2212
    * @param mixed   $format XF format we are giving to the row
1904
    *                        Use NULL to set XF without setting height
2213
    * @param bool    $hidden The optional hidden attribute
1905
    * @param mixed   $format XF format we are giving to the row
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
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
-
 
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 {
1924
            $miyRw = 0xff;          // default row height is 256
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;
-
 
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,
1929
                                     $irwMac,$reserved, $grbit, $ixfe);
2260
                                     $irwMac,$reserved, $grbit, $ixfe);
1930
        $this->_append($header.$data);
2261
        $this->_append($header.$data);
1931
    }
2262
    }
1932
    
2263
 
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
    {
-
 
1940
        $record    = 0x0000;               // Record identifier
2270
    {
1941
        $length    = 0x000A;               // Number of bytes to follow
2271
        $record    = 0x0200;                 // Record identifier
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
-
 
2276
        $reserved  = 0x0000;                 // Reserved by Excel
-
 
2277
 
1946
        $reserved  = 0x0000;               // Reserved by Excel
2278
        if ($this->_BIFF_version == 0x0500) {
-
 
2279
            $length    = 0x000A;               // Number of bytes to follow
-
 
2280
            $data      = pack("vvvvv", $row_min, $row_max,
-
 
2281
                                       $col_min, $col_max, $reserved);
1947
    
2282
        } elseif ($this->_BIFF_version == 0x0600) {
1948
        $header    = pack("vv",    $record, $length);
2283
            $length    = 0x000E;
-
 
2284
            $data      = pack("VVvvv", $row_min, $row_max,
-
 
2285
                                       $col_min, $col_max, $reserved);
1949
        $data      = pack("vvvvv", $row_min, $row_max,
2286
        }
1950
                                   $col_min, $col_max, $reserved);
2287
        $header = pack("vv", $record, $length);
1951
        $this->_prepend($header.$data);
2288
        $this->_prepend($header.$data);
1952
    }
2289
    }
1953
    
2290
 
1954
    /**
2291
    /**
1955
    * Write BIFF record Window2.
2292
    * Write BIFF record Window2.
1956
    *
2293
    *
1957
    * @access private
2294
    * @access private
1958
    */
2295
    */
1959
    function _storeWindow2()
2296
    function _storeWindow2()
-
 
2297
    {
1960
    {
2298
        $record         = 0x023E;     // Record identifier
-
 
2299
        if ($this->_BIFF_version == 0x0500) {
-
 
2300
            $length         = 0x000A;     // Number of bytes to follow
-
 
2301
        } elseif ($this->_BIFF_version == 0x0600) {
1961
        $record         = 0x023E;     // Record identifier
2302
            $length         = 0x0012;
1962
        $length         = 0x000A;     // Number of bytes to follow
2303
        }
1963
    
2304
 
1964
        $grbit          = 0x00B6;     // Option flags
2305
        $grbit          = 0x00B6;     // Option flags
1965
        $rwTop          = 0x0000;     // Top row visible in window
-
 
1966
        $colLeft        = 0x0000;     // Leftmost column visible in window
2306
        $rwTop          = 0x0000;     // Top row visible in window
-
 
2307
        $colLeft        = 0x0000;     // Leftmost column visible in window
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
1979
        $fSelected      = $this->selected;       // 1
2320
        $fSelected      = $this->selected;       // 1
1980
        $fPaged         = 1;                     // 2
2321
        $fPaged         = 1;                     // 2
1981
    
2322
 
1982
        $grbit             = $fDspFmla;
2323
        $grbit             = $fDspFmla;
1983
        $grbit            |= $fDspGrid       << 1;
2324
        $grbit            |= $fDspGrid       << 1;
1984
        $grbit            |= $fDspRwCol      << 2;
2325
        $grbit            |= $fDspRwCol      << 2;
Line 1988... Line 2329...
1988
        $grbit            |= $fArabic        << 6;
2329
        $grbit            |= $fArabic        << 6;
1989
        $grbit            |= $fDspGuts       << 7;
2330
        $grbit            |= $fDspGuts       << 7;
1990
        $grbit            |= $fFrozenNoSplit << 8;
2331
        $grbit            |= $fFrozenNoSplit << 8;
1991
        $grbit            |= $fSelected      << 9;
2332
        $grbit            |= $fSelected      << 9;
1992
        $grbit            |= $fPaged         << 10;
2333
        $grbit            |= $fPaged         << 10;
1993
    
2334
 
1994
        $header  = pack("vv",   $record, $length);
2335
        $header  = pack("vv",   $record, $length);
1995
        $data    = pack("vvvV", $grbit, $rwTop, $colLeft, $rgbHdr);
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);
-
 
2346
        }
1996
        $this->_append($header.$data);
2347
        $this->_append($header.$data);
1997
    }
2348
    }
1998
    
2349
 
1999
    /**
2350
    /**
2000
    * Write BIFF record DEFCOLWIDTH if COLINFO records are in use.
2351
    * Write BIFF record DEFCOLWIDTH if COLINFO records are in use.
2001
    *
2352
    *
2002
    * @access private
2353
    * @access private
2003
    */
2354
    */
2004
    function _storeDefcol()
2355
    function _storeDefcol()
2005
    {
2356
    {
2006
        $record   = 0x0055;      // Record identifier
2357
        $record   = 0x0055;      // Record identifier
2007
        $length   = 0x0002;      // Number of bytes to follow
2358
        $length   = 0x0002;      // Number of bytes to follow
2008
        $colwidth = 0x0008;      // Default column width
2359
        $colwidth = 0x0008;      // Default column width
2009
    
2360
 
2010
        $header   = pack("vv", $record, $length);
2361
        $header   = pack("vv", $record, $length);
2011
        $data     = pack("v",  $colwidth);
2362
        $data     = pack("v",  $colwidth);
2012
        $this->_prepend($header.$data);
2363
        $this->_prepend($header . $data);
2013
    }
2364
    }
2014
    
2365
 
2015
    /**
2366
    /**
2016
    * Write BIFF record COLINFO to define column widths
2367
    * Write BIFF record COLINFO to define column widths
2017
    *
2368
    *
2018
    * Note: The SDK says the record length is 0x0B but Excel writes a 0x0C
2369
    * Note: The SDK says the record length is 0x0B but Excel writes a 0x0C
2019
    * length record.
2370
    * length record.
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
2057
    
2411
 
2058
        $coldx   += 0.72;            // Fudge. Excel subtracts 0.72 !?
2412
        $coldx   += 0.72;            // Fudge. Excel subtracts 0.72 !?
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
 
2061
        $ixfe     = $this->_XF($format);
2415
        $ixfe     = $this->_XF($format);
2062
        $reserved = 0x00;            // Reserved
2416
        $reserved = 0x00;            // Reserved
2063
    
2417
 
-
 
2418
        $level = max(0, min($level, 7));
-
 
2419
        $grbit |= $level << 8;
-
 
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,
2066
                                   $ixfe, $grbit, $reserved);
2423
                                   $ixfe, $grbit, $reserved);
2067
        $this->_prepend($header.$data);
2424
        $this->_prepend($header.$data);
2068
    }
2425
    }
2069
    
2426
 
2070
    /**
2427
    /**
2071
    * Write BIFF record SELECTION.
2428
    * Write BIFF record SELECTION.
2072
    *
2429
    *
2073
    * @access private
2430
    * @access private
2074
    * @param array $array array containing ($rwFirst,$colFirst,$rwLast,$colLast)
2431
    * @param array $array array containing ($rwFirst,$colFirst,$rwLast,$colLast)
Line 2077... Line 2434...
2077
    function _storeSelection($array)
2434
    function _storeSelection($array)
2078
    {
2435
    {
2079
        list($rwFirst,$colFirst,$rwLast,$colLast) = $array;
2436
        list($rwFirst,$colFirst,$rwLast,$colLast) = $array;
2080
        $record   = 0x001D;                  // Record identifier
2437
        $record   = 0x001D;                  // Record identifier
2081
        $length   = 0x000F;                  // Number of bytes to follow
2438
        $length   = 0x000F;                  // Number of bytes to follow
2082
    
2439
 
2083
        $pnn      = $this->_active_pane;     // Pane position
2440
        $pnn      = $this->_active_pane;     // Pane position
2084
        $rwAct    = $rwFirst;                // Active row
2441
        $rwAct    = $rwFirst;                // Active row
2085
        $colAct   = $colFirst;               // Active column
2442
        $colAct   = $colFirst;               // Active column
2086
        $irefAct  = 0;                       // Active cell ref
2443
        $irefAct  = 0;                       // Active cell ref
2087
        $cref     = 1;                       // Number of refs
2444
        $cref     = 1;                       // Number of refs
2088
    
2445
 
2089
        if (!isset($rwLast)) {
2446
        if (!isset($rwLast)) {
2090
            $rwLast   = $rwFirst;       // Last  row in reference
2447
            $rwLast   = $rwFirst;       // Last  row in reference
2091
        }
2448
        }
2092
        if (!isset($colLast)) {
2449
        if (!isset($colLast)) {
2093
            $colLast  = $colFirst;      // Last  col in reference
2450
            $colLast  = $colFirst;      // Last  col in reference
2094
        }
2451
        }
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)
2454
        if ($rwFirst > $rwLast) {
2098
        {
-
 
2099
            list($rwFirst, $rwLast) = array($rwLast, $rwFirst);
2455
            list($rwFirst, $rwLast) = array($rwLast, $rwFirst);
2100
        }
2456
        }
2101
    
2457
 
2102
        if ($colFirst > $colLast)
2458
        if ($colFirst > $colLast) {
2103
        {
-
 
2104
            list($colFirst, $colLast) = array($colLast, $colFirst);
2459
            list($colFirst, $colLast) = array($colLast, $colFirst);
2105
        }
2460
        }
2106
    
2461
 
2107
        $header   = pack("vv",         $record, $length);
2462
        $header   = pack("vv",         $record, $length);
2108
        $data     = pack("CvvvvvvCC",  $pnn, $rwAct, $colAct,
2463
        $data     = pack("CvvvvvvCC",  $pnn, $rwAct, $colAct,
2109
                                       $irefAct, $cref,
2464
                                       $irefAct, $cref,
2110
                                       $rwFirst, $rwLast,
2465
                                       $rwFirst, $rwLast,
2111
                                       $colFirst, $colLast);
2466
                                       $colFirst, $colLast);
2112
        $this->_append($header.$data);
2467
        $this->_append($header . $data);
2113
    }
2468
    }
2114
    
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
          }
-
 
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
2118
    * references in a worksheet.
2496
    * references in a worksheet.
2119
    *
2497
    *
2120
    * Excel only stores references to external sheets that are used in formulas.
2498
    * Excel only stores references to external sheets that are used in formulas.
Line 2126... Line 2504...
2126
    * @access private
2504
    * @access private
2127
    * @param integer $count The number of external sheet references in this worksheet
2505
    * @param integer $count The number of external sheet references in this worksheet
2128
    */
2506
    */
2129
    function _storeExterncount($count)
2507
    function _storeExterncount($count)
2130
    {
2508
    {
2131
        $record   = 0x0016;          // Record identifier
2509
        $record = 0x0016;          // Record identifier
2132
        $length   = 0x0002;          // Number of bytes to follow
2510
        $length = 0x0002;          // Number of bytes to follow
2133
    
2511
 
2134
        $header   = pack("vv", $record, $length);
2512
        $header = pack("vv", $record, $length);
2135
        $data     = pack("v",  $count);
2513
        $data   = pack("v",  $count);
2136
        $this->_prepend($header.$data);
2514
        $this->_prepend($header . $data);
2137
    }
2515
    }
2138
    
2516
 
2139
    /**
2517
    /**
2140
    * Writes the Excel BIFF EXTERNSHEET record. These references are used by
2518
    * Writes the Excel BIFF EXTERNSHEET record. These references are used by
2141
    * formulas. A formula references a sheet name via an index. Since we store a
2519
    * formulas. A formula references a sheet name via an index. Since we store a
2142
    * reference to all of the external worksheets the EXTERNSHEET index is the same
2520
    * reference to all of the external worksheets the EXTERNSHEET index is the same
2143
    * as the worksheet index.
2521
    * as the worksheet index.
Line 2146... Line 2524...
2146
    * @param string $sheetname The name of a external worksheet
2524
    * @param string $sheetname The name of a external worksheet
2147
    */
2525
    */
2148
    function _storeExternsheet($sheetname)
2526
    function _storeExternsheet($sheetname)
2149
    {
2527
    {
2150
        $record    = 0x0017;         // Record identifier
2528
        $record    = 0x0017;         // Record identifier
2151
    
2529
 
2152
        // References to the current sheet are encoded differently to references to
2530
        // References to the current sheet are encoded differently to references to
2153
        // external sheets.
2531
        // external sheets.
2154
        //
2532
        //
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
        }
2166
    
2543
 
2167
        $header     = pack("vv",  $record, $length);
2544
        $header = pack("vv",  $record, $length);
2168
        $data       = pack("CC", $cch, $rgch);
2545
        $data   = pack("CC", $cch, $rgch);
2169
        $this->_prepend($header.$data.$sheetname);
2546
        $this->_prepend($header . $data . $sheetname);
2170
    }
2547
    }
2171
    
2548
 
2172
    /**
2549
    /**
2173
    * Writes the Excel BIFF PANE record.
2550
    * Writes the Excel BIFF PANE record.
2174
    * The panes can either be frozen or thawed (unfrozen).
2551
    * The panes can either be frozen or thawed (unfrozen).
2175
    * Frozen panes are specified in terms of an integer number of rows and columns.
2552
    * Frozen panes are specified in terms of an integer number of rows and columns.
2176
    * Thawed panes are specified in terms of Excel's units for rows and columns.
2553
    * Thawed panes are specified in terms of Excel's units for rows and columns.
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
2200
    
2576
 
2201
        // Code specific to frozen or thawed panes.
2577
        // Code specific to frozen or thawed panes.
2202
        if ($this->_frozen)
2578
        if ($this->_frozen) {
2203
        {
-
 
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
            }
2585
            }
2211
        }
-
 
2212
        else
2586
        } else {
2213
        {
-
 
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
            }
2218
            if (!isset($colLeft)) {
2591
            if (!isset($colLeft)) {
2219
                $colLeft = 0;
2592
                $colLeft = 0;
2220
            }
2593
            }
2221
    
2594
 
2222
            // Convert Excel's row and column units to the internal units.
2595
            // Convert Excel's row and column units to the internal units.
2223
            // The default row height is 12.75
2596
            // The default row height is 12.75
2224
            // The default column width is 8.43
2597
            // The default column width is 8.43
2225
            // The following slope and intersection values were interpolated.
2598
            // The following slope and intersection values were interpolated.
2226
            //
2599
            //
2227
            $y = 20*$y      + 255;
2600
            $y = 20*$y      + 255;
2228
            $x = 113.879*$x + 390;
2601
            $x = 113.879*$x + 390;
2229
        }
2602
        }
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
        //
2607
        //
2235
        if (!isset($pnnAct))
2608
        if (!isset($pnnAct)) {
2236
        {
-
 
2237
            if ($x != 0 and $y != 0)
2609
            if ($x != 0 && $y != 0) {
2238
                $pnnAct = 0; // Bottom right
2610
                $pnnAct = 0; // Bottom right
-
 
2611
            }
2239
            if ($x != 0 and $y == 0)
2612
            if ($x != 0 && $y == 0) {
2240
                $pnnAct = 1; // Top right
2613
                $pnnAct = 1; // Top right
-
 
2614
            }
2241
            if ($x == 0 and $y != 0)
2615
            if ($x == 0 && $y != 0) {
2242
                $pnnAct = 2; // Bottom left
2616
                $pnnAct = 2; // Bottom left
-
 
2617
            }
2243
            if ($x == 0 and $y == 0)
2618
            if ($x == 0 && $y == 0) {
2244
                $pnnAct = 3; // Top left
2619
                $pnnAct = 3; // Top left
-
 
2620
            }
2245
        }
2621
        }
2246
    
2622
 
2247
        $this->_active_pane = $pnnAct; // Used in _storeSelection
2623
        $this->_active_pane = $pnnAct; // Used in _storeSelection
2248
    
2624
 
2249
        $header     = pack("vv",    $record, $length);
2625
        $header     = pack("vv",    $record, $length);
2250
        $data       = pack("vvvvv", $x, $y, $rwTop, $colLeft, $pnnAct);
2626
        $data       = pack("vvvvv", $x, $y, $rwTop, $colLeft, $pnnAct);
2251
        $this->_append($header.$data);
2627
        $this->_append($header . $data);
2252
    }
2628
    }
2253
    
2629
 
2254
    /**
2630
    /**
2255
    * Store the page setup SETUP BIFF record.
2631
    * Store the page setup SETUP BIFF record.
2256
    *
2632
    *
2257
    * @access private
2633
    * @access private
2258
    */
2634
    */
2259
    function _storeSetup()
2635
    function _storeSetup()
2260
    {
2636
    {
2261
        $record       = 0x00A1;                  // Record identifier
2637
        $record       = 0x00A1;                  // Record identifier
2262
        $length       = 0x0022;                  // Number of bytes to follow
2638
        $length       = 0x0022;                  // Number of bytes to follow
2263
    
2639
 
2264
        $iPaperSize   = $this->_paper_size;    // Paper size
2640
        $iPaperSize   = $this->_paper_size;    // Paper size
2265
        $iScale       = $this->_print_scale;   // Print scaling factor
2641
        $iScale       = $this->_print_scale;   // Print scaling factor
2266
        $iPageStart   = 0x01;                 // Starting page number
2642
        $iPageStart   = 0x01;                 // Starting page number
2267
        $iFitWidth    = $this->_fit_width;    // Fit to number of pages wide
2643
        $iFitWidth    = $this->_fit_width;    // Fit to number of pages wide
2268
        $iFitHeight   = $this->_fit_height;   // Fit to number of pages high
2644
        $iFitHeight   = $this->_fit_height;   // Fit to number of pages high
Line 2270... Line 2646...
2270
        $iRes         = 0x0258;               // Print resolution
2646
        $iRes         = 0x0258;               // Print resolution
2271
        $iVRes        = 0x0258;               // Vertical print resolution
2647
        $iVRes        = 0x0258;               // Vertical print resolution
2272
        $numHdr       = $this->_margin_head;  // Header Margin
2648
        $numHdr       = $this->_margin_head;  // Header Margin
2273
        $numFtr       = $this->_margin_foot;   // Footer Margin
2649
        $numFtr       = $this->_margin_foot;   // Footer Margin
2274
        $iCopies      = 0x01;                 // Number of copies
2650
        $iCopies      = 0x01;                 // Number of copies
2275
    
2651
 
2276
        $fLeftToRight = 0x0;                     // Print over then down
2652
        $fLeftToRight = 0x0;                     // Print over then down
2277
        $fLandscape   = $this->_orientation;     // Page orientation
2653
        $fLandscape   = $this->_orientation;     // Page orientation
2278
        $fNoPls       = 0x0;                     // Setup not read from printer
2654
        $fNoPls       = 0x0;                     // Setup not read from printer
2279
        $fNoColor     = 0x0;                     // Print black and white
2655
        $fNoColor     = 0x0;                     // Print black and white
2280
        $fDraft       = 0x0;                     // Print draft quality
2656
        $fDraft       = 0x0;                     // Print draft quality
2281
        $fNotes       = 0x0;                     // Print notes
2657
        $fNotes       = 0x0;                     // Print notes
2282
        $fNoOrient    = 0x0;                     // Orientation not set
2658
        $fNoOrient    = 0x0;                     // Orientation not set
2283
        $fUsePage     = 0x0;                     // Use custom starting page
2659
        $fUsePage     = 0x0;                     // Use custom starting page
2284
    
2660
 
2285
        $grbit           = $fLeftToRight;
2661
        $grbit           = $fLeftToRight;
2286
        $grbit          |= $fLandscape    << 1;
2662
        $grbit          |= $fLandscape    << 1;
2287
        $grbit          |= $fNoPls        << 2;
2663
        $grbit          |= $fNoPls        << 2;
2288
        $grbit          |= $fNoColor      << 3;
2664
        $grbit          |= $fNoColor      << 3;
2289
        $grbit          |= $fDraft        << 4;
2665
        $grbit          |= $fDraft        << 4;
2290
        $grbit          |= $fNotes        << 5;
2666
        $grbit          |= $fNotes        << 5;
2291
        $grbit          |= $fNoOrient     << 6;
2667
        $grbit          |= $fNoOrient     << 6;
2292
        $grbit          |= $fUsePage      << 7;
2668
        $grbit          |= $fUsePage      << 7;
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
2672
        if ($this->_byte_order) { // if it's Big Endian
2297
        {
-
 
2298
            $numHdr = strrev($numHdr);
2673
            $numHdr = strrev($numHdr);
2299
            $numFtr = strrev($numFtr);
2674
            $numFtr = strrev($numFtr);
2300
        }
2675
        }
2301
    
2676
 
2302
        $header = pack("vv", $record, $length);
2677
        $header = pack("vv", $record, $length);
2303
        $data1  = pack("vvvvvvvv", $iPaperSize,
2678
        $data1  = pack("vvvvvvvv", $iPaperSize,
2304
                                   $iScale,
2679
                                   $iScale,
2305
                                   $iPageStart,
2680
                                   $iPageStart,
2306
                                   $iFitWidth,
2681
                                   $iFitWidth,
Line 2308... Line 2683...
2308
                                   $grbit,
2683
                                   $grbit,
2309
                                   $iRes,
2684
                                   $iRes,
2310
                                   $iVRes);
2685
                                   $iVRes);
2311
        $data2  = $numHdr.$numFtr;
2686
        $data2  = $numHdr.$numFtr;
2312
        $data3  = pack("v", $iCopies);
2687
        $data3  = pack("v", $iCopies);
2313
        $this->_prepend($header.$data1.$data2.$data3);
2688
        $this->_prepend($header . $data1 . $data2 . $data3);
2314
    }
2689
    }
2315
    
2690
 
2316
    /**
2691
    /**
2317
    * Store the header caption BIFF record.
2692
    * Store the header caption BIFF record.
2318
    *
2693
    *
2319
    * @access private
2694
    * @access private
2320
    */
2695
    */
2321
    function _storeHeader()
2696
    function _storeHeader()
2322
    {
2697
    {
2323
        $record  = 0x0014;               // Record identifier
2698
        $record  = 0x0014;               // Record identifier
2324
    
2699
 
2325
        $str     = $this->_header;       // header string
2700
        $str      = $this->_header;       // header string
2326
        $cch     = strlen($str);         // Length of 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
-
 
2705
        } else {
2327
        $length  = 1 + $cch;             // Bytes to follow
2706
            $length  = 1 + $cch;             // Bytes to follow
-
 
2707
        }
2328
    
2708
 
2329
        $header    = pack("vv", $record, $length);
2709
        $header   = pack("vv", $record, $length);
-
 
2710
        if ($this->_BIFF_version == 0x0600) {
-
 
2711
            $data     = pack("vC",  $cch, $encoding);
-
 
2712
        } else {
2330
        $data      = pack("C",  $cch);
2713
            $data      = pack("C",  $cch);
-
 
2714
        }
2331
    
2715
 
2332
        $this->_append($header.$data.$str);
2716
        $this->_prepend($header.$data.$str);
2333
    }
2717
    }
2334
    
2718
 
2335
    /**
2719
    /**
2336
    * Store the footer caption BIFF record.
2720
    * Store the footer caption BIFF record.
2337
    *
2721
    *
2338
    * @access private
2722
    * @access private
2339
    */
2723
    */
2340
    function _storeFooter()
2724
    function _storeFooter()
2341
    {
2725
    {
2342
        $record  = 0x0015;               // Record identifier
2726
        $record  = 0x0015;               // Record identifier
2343
    
2727
 
2344
        $str     = $this->_footer;       // Footer string
2728
        $str      = $this->_footer;       // Footer string
2345
        $cch     = strlen($str);         // Length of footer string
2729
        $cch      = strlen($str);         // Length of footer string
-
 
2730
        if ($this->_BIFF_version == 0x0600) {
-
 
2731
            $encoding = 0x0;                  // TODO: Unicode support
2346
        $length  = 1 + $cch;             // Bytes to follow
2732
            $length   = 3 + $cch;             // Bytes to follow
-
 
2733
        } else {
-
 
2734
            $length  = 1 + $cch;
-
 
2735
        }
2347
    
2736
 
2348
        $header    = pack("vv", $record, $length);
2737
        $header    = pack("vv", $record, $length);
-
 
2738
        if ($this->_BIFF_version == 0x0600) {
-
 
2739
            $data      = pack("vC",  $cch, $encoding);
-
 
2740
        } else {
2349
        $data      = pack("C",  $cch);
2741
            $data      = pack("C",  $cch);
-
 
2742
        }
2350
    
2743
 
2351
        $this->_append($header.$data.$str);
2744
        $this->_prepend($header . $data . $str);
2352
    }
2745
    }
2353
    
2746
 
2354
    /**
2747
    /**
2355
    * Store the horizontal centering HCENTER BIFF record.
2748
    * Store the horizontal centering HCENTER BIFF record.
2356
    *
2749
    *
2357
    * @access private
2750
    * @access private
2358
    */
2751
    */
2359
    function _storeHcenter()
2752
    function _storeHcenter()
2360
    {
2753
    {
2361
        $record   = 0x0083;              // Record identifier
2754
        $record   = 0x0083;              // Record identifier
2362
        $length   = 0x0002;              // Bytes to follow
2755
        $length   = 0x0002;              // Bytes to follow
2363
    
2756
 
2364
        $fHCenter = $this->_hcenter;     // Horizontal centering
2757
        $fHCenter = $this->_hcenter;     // Horizontal centering
2365
    
2758
 
2366
        $header    = pack("vv", $record, $length);
2759
        $header    = pack("vv", $record, $length);
2367
        $data      = pack("v",  $fHCenter);
2760
        $data      = pack("v",  $fHCenter);
2368
    
2761
 
2369
        $this->_append($header.$data);
2762
        $this->_prepend($header.$data);
2370
    }
2763
    }
2371
    
2764
 
2372
    /**
2765
    /**
2373
    * Store the vertical centering VCENTER BIFF record.
2766
    * Store the vertical centering VCENTER BIFF record.
2374
    *
2767
    *
2375
    * @access private
2768
    * @access private
2376
    */
2769
    */
2377
    function _storeVcenter()
2770
    function _storeVcenter()
2378
    {
2771
    {
2379
        $record   = 0x0084;              // Record identifier
2772
        $record   = 0x0084;              // Record identifier
2380
        $length   = 0x0002;              // Bytes to follow
2773
        $length   = 0x0002;              // Bytes to follow
2381
    
2774
 
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);
2386
        $this->_append($header.$data);
2779
        $this->_prepend($header . $data);
2387
    }
2780
    }
2388
    
2781
 
2389
    /**
2782
    /**
2390
    * Store the LEFTMARGIN BIFF record.
2783
    * Store the LEFTMARGIN BIFF record.
2391
    *
2784
    *
2392
    * @access private
2785
    * @access private
2393
    */
2786
    */
2394
    function _storeMarginLeft()
2787
    function _storeMarginLeft()
2395
    {
2788
    {
2396
        $record  = 0x0026;                   // Record identifier
2789
        $record  = 0x0026;                   // Record identifier
2397
        $length  = 0x0008;                   // Bytes to follow
2790
        $length  = 0x0008;                   // Bytes to follow
2398
    
2791
 
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);
2795
        $data      = pack("d",   $margin);
2403
        if ($this->_byte_order) // if it's Big Endian
2796
        if ($this->_byte_order) { // if it's Big Endian
2404
        { 
-
 
2405
            $data = strrev($data);
2797
            $data = strrev($data);
2406
        }
2798
        }
2407
    
2799
 
2408
        $this->_append($header.$data);
2800
        $this->_prepend($header . $data);
2409
    }
2801
    }
2410
    
2802
 
2411
    /**
2803
    /**
2412
    * Store the RIGHTMARGIN BIFF record.
2804
    * Store the RIGHTMARGIN BIFF record.
2413
    *
2805
    *
2414
    * @access private
2806
    * @access private
2415
    */
2807
    */
2416
    function _storeMarginRight()
2808
    function _storeMarginRight()
2417
    {
2809
    {
2418
        $record  = 0x0027;                   // Record identifier
2810
        $record  = 0x0027;                   // Record identifier
2419
        $length  = 0x0008;                   // Bytes to follow
2811
        $length  = 0x0008;                   // Bytes to follow
2420
    
2812
 
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);
2816
        $data      = pack("d",   $margin);
2425
        if ($this->_byte_order) // if it's Big Endian
2817
        if ($this->_byte_order) { // if it's Big Endian
2426
        { 
-
 
2427
            $data = strrev($data);
2818
            $data = strrev($data);
2428
        }
2819
        }
2429
    
2820
 
2430
        $this->_append($header.$data);
2821
        $this->_prepend($header . $data);
2431
    }
2822
    }
2432
    
2823
 
2433
    /**
2824
    /**
2434
    * Store the TOPMARGIN BIFF record.
2825
    * Store the TOPMARGIN BIFF record.
2435
    *
2826
    *
2436
    * @access private
2827
    * @access private
2437
    */
2828
    */
2438
    function _storeMarginTop()
2829
    function _storeMarginTop()
2439
    {
2830
    {
2440
        $record  = 0x0028;                   // Record identifier
2831
        $record  = 0x0028;                   // Record identifier
2441
        $length  = 0x0008;                   // Bytes to follow
2832
        $length  = 0x0008;                   // Bytes to follow
2442
    
2833
 
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);
2837
        $data      = pack("d",   $margin);
2447
        if ($this->_byte_order) // if it's Big Endian
2838
        if ($this->_byte_order) { // if it's Big Endian
2448
        { 
-
 
2449
            $data = strrev($data);
2839
            $data = strrev($data);
2450
        }
2840
        }
2451
    
2841
 
2452
        $this->_append($header.$data);
2842
        $this->_prepend($header . $data);
2453
    }
2843
    }
2454
    
2844
 
2455
    /**
2845
    /**
2456
    * Store the BOTTOMMARGIN BIFF record.
2846
    * Store the BOTTOMMARGIN BIFF record.
2457
    *
2847
    *
2458
    * @access private
2848
    * @access private
2459
    */
2849
    */
2460
    function _storeMarginBottom()
2850
    function _storeMarginBottom()
2461
    {
2851
    {
2462
        $record  = 0x0029;                   // Record identifier
2852
        $record  = 0x0029;                   // Record identifier
2463
        $length  = 0x0008;                   // Bytes to follow
2853
        $length  = 0x0008;                   // Bytes to follow
2464
    
2854
 
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);
2858
        $data      = pack("d",   $margin);
2469
        if ($this->_byte_order) // if it's Big Endian
2859
        if ($this->_byte_order) { // if it's Big Endian
2470
        { 
-
 
2471
            $data = strrev($data);
2860
            $data = strrev($data);
2472
        }
2861
        }
2473
    
2862
 
2474
        $this->_append($header.$data);
2863
        $this->_prepend($header . $data);
2475
    }
2864
    }
Line 2476... Line 2865...
2476
 
2865
 
2477
    /**
2866
    /**
2478
    * Merges the area given by its arguments.
2867
    * Merges the area given by its arguments.
Line 2493... Line 2882...
2493
 
2882
 
2494
        // Swap last row/col for first row/col as necessary
2883
        // Swap last row/col for first row/col as necessary
2495
        if ($first_row > $last_row) {
2884
        if ($first_row > $last_row) {
2496
            list($first_row, $last_row) = array($last_row, $first_row);
2885
            list($first_row, $last_row) = array($last_row, $first_row);
2497
        }
2886
        }
2498
    
2887
 
2499
        if ($first_col > $last_col) {
2888
        if ($first_col > $last_col) {
2500
            list($first_col, $last_col) = array($last_col, $first_col);
2889
            list($first_col, $last_col) = array($last_col, $first_col);
2501
        }
2890
        }
2502
    
2891
 
2503
        $header   = pack("vv",    $record, $length);
2892
        $header   = pack("vv",    $record, $length);
2504
        $data     = pack("vvvvv", $cref, $first_row, $last_row,
2893
        $data     = pack("vvvvv", $cref, $first_row, $last_row,
2505
                                  $first_col, $last_col);
2894
                                  $first_col, $last_col);
2506
    
2895
 
2507
        $this->_append($header.$data);
2896
        $this->_append($header.$data);
Line 2508... Line 2897...
2508
    }
2897
    }
2509
 
2898
 
Line 2514... Line 2903...
2514
    */
2903
    */
2515
    function _storePrintHeaders()
2904
    function _storePrintHeaders()
2516
    {
2905
    {
2517
        $record      = 0x002a;                   // Record identifier
2906
        $record      = 0x002a;                   // Record identifier
2518
        $length      = 0x0002;                   // Bytes to follow
2907
        $length      = 0x0002;                   // Bytes to follow
2519
    
2908
 
2520
        $fPrintRwCol = $this->_print_headers;     // Boolean flag
2909
        $fPrintRwCol = $this->_print_headers;     // Boolean flag
2521
    
2910
 
2522
        $header      = pack("vv", $record, $length);
2911
        $header      = pack("vv", $record, $length);
2523
        $data        = pack("v", $fPrintRwCol);
2912
        $data        = pack("v", $fPrintRwCol);
2524
        $this->_prepend($header.$data);
2913
        $this->_prepend($header . $data);
2525
    }
2914
    }
2526
    
2915
 
2527
    /**
2916
    /**
2528
    * Write the PRINTGRIDLINES BIFF record. Must be used in conjunction with the
2917
    * Write the PRINTGRIDLINES BIFF record. Must be used in conjunction with the
2529
    * GRIDSET record.
2918
    * GRIDSET record.
2530
    *
2919
    *
2531
    * @access private
2920
    * @access private
2532
    */
2921
    */
2533
    function _storePrintGridlines()
2922
    function _storePrintGridlines()
2534
    {
2923
    {
2535
        $record      = 0x002b;                    // Record identifier
2924
        $record      = 0x002b;                    // Record identifier
2536
        $length      = 0x0002;                    // Bytes to follow
2925
        $length      = 0x0002;                    // Bytes to follow
2537
    
2926
 
2538
        $fPrintGrid  = $this->_print_gridlines;    // Boolean flag
2927
        $fPrintGrid  = $this->_print_gridlines;    // Boolean flag
2539
    
2928
 
2540
        $header      = pack("vv", $record, $length);
2929
        $header      = pack("vv", $record, $length);
2541
        $data        = pack("v", $fPrintGrid);
2930
        $data        = pack("v", $fPrintGrid);
2542
        $this->_prepend($header.$data);
2931
        $this->_prepend($header . $data);
2543
    }
2932
    }
2544
    
2933
 
2545
    /**
2934
    /**
2546
    * Write the GRIDSET BIFF record. Must be used in conjunction with the
2935
    * Write the GRIDSET BIFF record. Must be used in conjunction with the
2547
    * PRINTGRIDLINES record.
2936
    * PRINTGRIDLINES record.
2548
    *
2937
    *
2549
    * @access private
2938
    * @access private
2550
    */
2939
    */
2551
    function _storeGridset()
2940
    function _storeGridset()
2552
    {
2941
    {
2553
        $record      = 0x0082;                        // Record identifier
2942
        $record      = 0x0082;                        // Record identifier
2554
        $length      = 0x0002;                        // Bytes to follow
2943
        $length      = 0x0002;                        // Bytes to follow
2555
    
2944
 
2556
        $fGridSet    = !($this->_print_gridlines);     // Boolean flag
2945
        $fGridSet    = !($this->_print_gridlines);     // Boolean flag
2557
    
2946
 
2558
        $header      = pack("vv",  $record, $length);
2947
        $header      = pack("vv",  $record, $length);
2559
        $data        = pack("v",   $fGridSet);
2948
        $data        = pack("v",   $fGridSet);
-
 
2949
        $this->_prepend($header . $data);
-
 
2950
    }
-
 
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
 
2560
        $this->_prepend($header.$data);
2995
        $this->_prepend($header.$data);
2561
    }
2996
    }
-
 
2997
 
2562
    
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
2572
        $length      = 0x0002;   // Bytes to follow
3008
        $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) {
3014
        /*if ($this->_fit_page) {
2578
            $grbit = 0x05c1;
3015
            $grbit = 0x05c1;
2579
        }
-
 
2580
        else {
3016
        } else {
2581
            $grbit = 0x04c1;
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
2582
        }
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
        }
-
 
3033
        if ($this->_outline_on) {
-
 
3034
            $grbit |= 0x0400; // Outline symbols displayed
-
 
3035
        }
2583
    
3036
 
2584
        $header      = pack("vv", $record, $length);
3037
        $header = pack("vv", $record, $length);
2585
        $data        = pack("v",  $grbit);
3038
        $data   = pack("v",  $grbit);
2586
        $this->_prepend($header.$data);
3039
        $this->_prepend($header . $data);
2587
    }
3040
    }
2588
    
-
 
2589
    
3041
 
2590
    /**
3042
    /**
2591
    * Write the HORIZONTALPAGEBREAKS BIFF record.
3043
    * Write the HORIZONTALPAGEBREAKS BIFF record.
2592
    *
3044
    *
2593
    * @access private
3045
    * @access private
2594
    */
3046
    */
Line 2596... Line 3048...
2596
    {
3048
    {
2597
        // Return if the user hasn't specified pagebreaks
3049
        // Return if the user hasn't specified pagebreaks
2598
        if (empty($this->_hbreaks)) {
3050
        if (empty($this->_hbreaks)) {
2599
            return;
3051
            return;
2600
        }
3052
        }
2601
    
3053
 
2602
        // Sort and filter array of page breaks
3054
        // Sort and filter array of page breaks
2603
        $breaks = $this->_hbreaks;
3055
        $breaks = $this->_hbreaks;
2604
        sort($breaks,SORT_NUMERIC);
3056
        sort($breaks, SORT_NUMERIC);
2605
        if ($breaks[0] == 0) { // don't use first break if it's 0
3057
        if ($breaks[0] == 0) { // don't use first break if it's 0
2606
            array_shift($breaks);
3058
            array_shift($breaks);
2607
        }
3059
        }
2608
    
3060
 
2609
        $record  = 0x001b;               // Record identifier
3061
        $record  = 0x001b;               // Record identifier
2610
        $cbrk    = count($breaks);       // Number of page breaks
3062
        $cbrk    = count($breaks);       // Number of page breaks
-
 
3063
        if ($this->_BIFF_version == 0x0600) {
-
 
3064
            $length  = 2 + 6*$cbrk;      // Bytes to follow
-
 
3065
        } else {
2611
        $length  = ($cbrk + 1) * 2;      // Bytes to follow
3066
            $length  = 2 + 2*$cbrk;      // Bytes to follow
-
 
3067
        }
2612
    
3068
 
2613
        $header  = pack("vv", $record, $length);
3069
        $header  = pack("vv", $record, $length);
2614
        $data    = pack("v",  $cbrk);
3070
        $data    = pack("v",  $cbrk);
2615
    
3071
 
2616
        // Append each page break
3072
        // Append each page break
2617
        foreach($breaks as $break) {
3073
        foreach ($breaks as $break) {
-
 
3074
            if ($this->_BIFF_version == 0x0600) {
-
 
3075
                $data .= pack("vvv", $break, 0x0000, 0x00ff);
-
 
3076
            } else {
2618
            $data .= pack("v", $break);
3077
                $data .= pack("v", $break);
-
 
3078
            }
2619
        }
3079
        }
2620
    
3080
 
2621
        $this->_prepend($header.$data);
3081
        $this->_prepend($header.$data);
2622
    }
3082
    }
2623
    
3083
 
2624
    
3084
 
2625
    /**
3085
    /**
2626
    * Write the VERTICALPAGEBREAKS BIFF record.
3086
    * Write the VERTICALPAGEBREAKS BIFF record.
2627
    *
3087
    *
2628
    * @access private
3088
    * @access private
2629
    */
3089
    */
Line 2631... Line 3091...
2631
    {
3091
    {
2632
        // Return if the user hasn't specified pagebreaks
3092
        // Return if the user hasn't specified pagebreaks
2633
        if (empty($this->_vbreaks)) {
3093
        if (empty($this->_vbreaks)) {
2634
            return;
3094
            return;
2635
        }
3095
        }
2636
    
3096
 
2637
        // 1000 vertical pagebreaks appears to be an internal Excel 5 limit.
3097
        // 1000 vertical pagebreaks appears to be an internal Excel 5 limit.
2638
        // It is slightly higher in Excel 97/200, approx. 1026
3098
        // It is slightly higher in Excel 97/200, approx. 1026
2639
        $breaks = array_slice($this->_vbreaks,0,1000);
3099
        $breaks = array_slice($this->_vbreaks,0,1000);
2640
    
3100
 
2641
        // Sort and filter array of page breaks
3101
        // Sort and filter array of page breaks
2642
        sort($breaks,SORT_NUMERIC);
3102
        sort($breaks, SORT_NUMERIC);
2643
        if ($breaks[0] == 0) { // don't use first break if it's 0
3103
        if ($breaks[0] == 0) { // don't use first break if it's 0
2644
            array_shift($breaks);
3104
            array_shift($breaks);
2645
        }
3105
        }
2646
    
3106
 
2647
        $record  = 0x001a;               // Record identifier
3107
        $record  = 0x001a;               // Record identifier
2648
        $cbrk    = count($breaks);       // Number of page breaks
3108
        $cbrk    = count($breaks);       // Number of page breaks
-
 
3109
        if ($this->_BIFF_version == 0x0600) {
-
 
3110
            $length  = 2 + 6*$cbrk;      // Bytes to follow
-
 
3111
        } else {
2649
        $length  = ($cbrk + 1) * 2;      // Bytes to follow
3112
            $length  = 2 + 2*$cbrk;      // Bytes to follow
-
 
3113
        }
2650
    
3114
 
2651
        $header  = pack("vv",  $record, $length);
3115
        $header  = pack("vv",  $record, $length);
2652
        $data    = pack("v",   $cbrk);
3116
        $data    = pack("v",   $cbrk);
2653
    
3117
 
2654
        // Append each page break
3118
        // Append each page break
2655
        foreach ($breaks as $break) {
3119
        foreach ($breaks as $break) {
-
 
3120
            if ($this->_BIFF_version == 0x0600) {
-
 
3121
                $data .= pack("vvv", $break, 0x0000, 0xffff);
-
 
3122
            } else {
2656
            $data .= pack("v", $break);
3123
                $data .= pack("v", $break);
-
 
3124
            }
2657
        }
3125
        }
2658
    
3126
 
2659
        $this->_prepend($header.$data);
3127
        $this->_prepend($header . $data);
2660
    }
3128
    }
2661
    
3129
 
2662
    /**
3130
    /**
2663
    * Set the Biff PROTECT record to indicate that the worksheet is protected.
3131
    * Set the Biff PROTECT record to indicate that the worksheet is protected.
2664
    *
3132
    *
2665
    * @access private
3133
    * @access private
2666
    */
3134
    */
Line 2668... Line 3136...
2668
    {
3136
    {
2669
        // Exit unless sheet protection has been specified
3137
        // Exit unless sheet protection has been specified
2670
        if ($this->_protect == 0) {
3138
        if ($this->_protect == 0) {
2671
            return;
3139
            return;
2672
        }
3140
        }
2673
    
3141
 
2674
        $record      = 0x0012;             // Record identifier
3142
        $record      = 0x0012;             // Record identifier
2675
        $length      = 0x0002;             // Bytes to follow
3143
        $length      = 0x0002;             // Bytes to follow
2676
    
3144
 
2677
        $fLock       = $this->_protect;    // Worksheet is protected
3145
        $fLock       = $this->_protect;    // Worksheet is protected
2678
    
3146
 
2679
        $header      = pack("vv", $record, $length);
3147
        $header      = pack("vv", $record, $length);
2680
        $data        = pack("v",  $fLock);
3148
        $data        = pack("v",  $fLock);
2681
    
3149
 
2682
        $this->_prepend($header.$data);
3150
        $this->_prepend($header.$data);
2683
    }
3151
    }
2684
    
3152
 
2685
    /**
3153
    /**
2686
    * Write the worksheet PASSWORD record.
3154
    * Write the worksheet PASSWORD record.
2687
    *
3155
    *
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
        }
2696
    
3164
 
2697
        $record      = 0x0013;               // Record identifier
3165
        $record      = 0x0013;               // Record identifier
2698
        $length      = 0x0002;               // Bytes to follow
3166
        $length      = 0x0002;               // Bytes to follow
2699
    
3167
 
2700
        $wPassword   = $this->_password;     // Encoded password
3168
        $wPassword   = $this->_password;     // Encoded password
2701
    
3169
 
2702
        $header      = pack("vv", $record, $length);
3170
        $header      = pack("vv", $record, $length);
2703
        $data        = pack("v",  $wPassword);
3171
        $data        = pack("v",  $wPassword);
2704
    
3172
 
2705
        $this->_prepend($header.$data);
3173
        $this->_prepend($header . $data);
2706
    }
3174
    }
2707
    
3175
 
Line 2708... Line 3176...
2708
 
3176
 
2709
    /**
3177
    /**
2710
    * Insert a 24bit bitmap image in a worksheet.
3178
    * Insert a 24bit bitmap image in a worksheet.
2711
    *
3179
    *
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);
2730
    
3197
 
2731
        // Scale the frame of the image.
3198
        // Scale the frame of the image.
2732
        $width  *= $scale_x;
3199
        $width  *= $scale_x;
2733
        $height *= $scale_y;
3200
        $height *= $scale_y;
2734
    
3201
 
2735
        // Calculate the vertices of the image and write the OBJ record
3202
        // Calculate the vertices of the image and write the OBJ record
2736
        $this->_positionImage($col, $row, $x, $y, $width, $height);
3203
        $this->_positionImage($col, $row, $x, $y, $width, $height);
2737
    
3204
 
2738
        // Write the IMDATA record to store the bitmap data
3205
        // Write the IMDATA record to store the bitmap data
2739
        $record      = 0x007f;
3206
        $record      = 0x007f;
2740
        $length      = 8 + $size;
3207
        $length      = 8 + $size;
2741
        $cf          = 0x09;
3208
        $cf          = 0x09;
2742
        $env         = 0x01;
3209
        $env         = 0x01;
2743
        $lcb         = $size;
3210
        $lcb         = $size;
2744
    
3211
 
2745
        $header      = pack("vvvvV", $record, $length, $cf, $env, $lcb);
3212
        $header      = pack("vvvvV", $record, $length, $cf, $env, $lcb);
2746
        $this->_append($header.$data);
3213
        $this->_append($header.$data);
2747
    }
3214
    }
2748
    
3215
 
2749
    /**
3216
    /**
2750
    * Calculate the vertices that define the position of the image as required by
3217
    * Calculate the vertices that define the position of the image as required by
2751
    * the OBJ record.
3218
    * the OBJ record.
2752
    *
3219
    *
2753
    *         +------------+------------+
3220
    *         +------------+------------+
Line 2800... Line 3267...
2800
    function _positionImage($col_start, $row_start, $x1, $y1, $width, $height)
3267
    function _positionImage($col_start, $row_start, $x1, $y1, $width, $height)
2801
    {
3268
    {
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
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))
3274
        if ($x1 >= $this->_sizeCol($col_start)) {
2808
        {
-
 
2809
            $x1 = 0;
3275
            $x1 = 0;
2810
        }
3276
        }
2811
        if ($y1 >= $this->_sizeRow($row_start))
3277
        if ($y1 >= $this->_sizeRow($row_start)) {
2812
        {
-
 
2813
            $y1 = 0;
3278
            $y1 = 0;
2814
        }
3279
        }
2815
    
3280
 
2816
        $width      = $width  + $x1 -1;
3281
        $width      = $width  + $x1 -1;
2817
        $height     = $height + $y1 -1;
3282
        $height     = $height + $y1 -1;
2818
    
3283
 
2819
        // Subtract the underlying cell widths to find the end cell of the image
3284
        // Subtract the underlying cell widths to find the end cell of the image
2820
        while ($width >= $this->_sizeCol($col_end)) {
3285
        while ($width >= $this->_sizeCol($col_end)) {
2821
            $width -= $this->_sizeCol($col_end);
3286
            $width -= $this->_sizeCol($col_end);
2822
            $col_end++;
3287
            $col_end++;
2823
        }
3288
        }
2824
    
3289
 
2825
        // Subtract the underlying cell heights to find the end cell of the image
3290
        // Subtract the underlying cell heights to find the end cell of the image
2826
        while ($height >= $this->_sizeRow($row_end)) {
3291
        while ($height >= $this->_sizeRow($row_end)) {
2827
            $height -= $this->_sizeRow($row_end);
3292
            $height -= $this->_sizeRow($row_end);
2828
            $row_end++;
3293
            $row_end++;
2829
        }
3294
        }
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) {
2835
            return;
3300
            return;
-
 
3301
        }
2836
        if ($this->_sizeCol($col_end)   == 0)
3302
        if ($this->_sizeCol($col_end)   == 0) {
2837
            return;
3303
            return;
-
 
3304
        }
2838
        if ($this->_sizeRow($row_start) == 0)
3305
        if ($this->_sizeRow($row_start) == 0) {
2839
            return;
3306
            return;
-
 
3307
        }
2840
        if ($this->_sizeRow($row_end)   == 0)
3308
        if ($this->_sizeRow($row_end)   == 0) {
2841
            return;
3309
            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;
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,
3319
                                 $row_start, $y1,
2851
                                  $col_end, $x2,
3320
                                 $col_end, $x2,
2852
                                  $row_end, $y2
3321
                                 $row_end, $y2);
2853
                                );
-
 
2854
    }
3322
    }
2855
    
3323
 
2856
    /**
3324
    /**
2857
    * Convert the width of a cell from user's units to pixels. By interpolation
3325
    * Convert the width of a cell from user's units to pixels. By interpolation
2858
    * the relationship is: y = 7x +5. If the width hasn't been set by the user we
3326
    * the relationship is: y = 7x +5. If the width hasn't been set by the user we
2859
    * use the default value. If the col is hidden we use a value of zero.
3327
    * use the default value. If the col is hidden we use a value of zero.
2860
    *
3328
    *
2861
    * @access private
3329
    * @access private
2862
    * @param integer $col The column 
3330
    * @param integer $col The column
2863
    * @return integer The width in pixels
3331
    * @return integer The width in pixels
2864
    */
3332
    */
2865
    function _sizeCol($col)
3333
    function _sizeCol($col)
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
    }
2880
    
3346
 
2881
    /**
3347
    /**
2882
    * Convert the height of a cell from user's units to pixels. By interpolation
3348
    * Convert the height of a cell from user's units to pixels. By interpolation
2883
    * the relationship is: y = 4/3x. If the height hasn't been set by the user we
3349
    * the relationship is: y = 4/3x. If the height hasn't been set by the user we
2884
    * use the default value. If the row is hidden we use a value of zero. (Not
3350
    * use the default value. If the row is hidden we use a value of zero. (Not
2885
    * possible to hide row yet).
3351
    * possible to hide row yet).
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
    }
2906
    
3370
 
2907
    /**
3371
    /**
2908
    * Store the OBJ record that precedes an IMDATA record. This could be generalise
3372
    * Store the OBJ record that precedes an IMDATA record. This could be generalise
2909
    * to support other Excel objects.
3373
    * to support other Excel objects.
2910
    *
3374
    *
2911
    * @access private
3375
    * @access private
Line 2920... Line 3384...
2920
    */
3384
    */
2921
    function _storeObjPicture($colL,$dxL,$rwT,$dyT,$colR,$dxR,$rwB,$dyB)
3385
    function _storeObjPicture($colL,$dxL,$rwT,$dyT,$colR,$dxR,$rwB,$dyB)
2922
    {
3386
    {
2923
        $record      = 0x005d;   // Record identifier
3387
        $record      = 0x005d;   // Record identifier
2924
        $length      = 0x003c;   // Bytes to follow
3388
        $length      = 0x003c;   // Bytes to follow
2925
    
3389
 
2926
        $cObj        = 0x0001;   // Count of objects in file (set to 1)
3390
        $cObj        = 0x0001;   // Count of objects in file (set to 1)
2927
        $OT          = 0x0008;   // Object type. 8 = Picture
3391
        $OT          = 0x0008;   // Object type. 8 = Picture
2928
        $id          = 0x0001;   // Object ID
3392
        $id          = 0x0001;   // Object ID
2929
        $grbit       = 0x0614;   // Option flags
3393
        $grbit       = 0x0614;   // Option flags
2930
    
3394
 
2931
        $cbMacro     = 0x0000;   // Length of FMLA structure
3395
        $cbMacro     = 0x0000;   // Length of FMLA structure
2932
        $Reserved1   = 0x0000;   // Reserved
3396
        $Reserved1   = 0x0000;   // Reserved
2933
        $Reserved2   = 0x0000;   // Reserved
3397
        $Reserved2   = 0x0000;   // Reserved
2934
    
3398
 
2935
        $icvBack     = 0x09;     // Background colour
3399
        $icvBack     = 0x09;     // Background colour
2936
        $icvFore     = 0x09;     // Foreground colour
3400
        $icvFore     = 0x09;     // Foreground colour
2937
        $fls         = 0x00;     // Fill pattern
3401
        $fls         = 0x00;     // Fill pattern
2938
        $fAuto       = 0x00;     // Automatic fill
3402
        $fAuto       = 0x00;     // Automatic fill
2939
        $icv         = 0x08;     // Line colour
3403
        $icv         = 0x08;     // Line colour
Line 2945... Line 3409...
2945
        $Reserved3   = 0x0000;   // Reserved
3409
        $Reserved3   = 0x0000;   // Reserved
2946
        $cbPictFmla  = 0x0000;   // Length of FMLA structure
3410
        $cbPictFmla  = 0x0000;   // Length of FMLA structure
2947
        $Reserved4   = 0x0000;   // Reserved
3411
        $Reserved4   = 0x0000;   // Reserved
2948
        $grbit2      = 0x0001;   // Option flags
3412
        $grbit2      = 0x0001;   // Option flags
2949
        $Reserved5   = 0x0000;   // Reserved
3413
        $Reserved5   = 0x0000;   // Reserved
2950
    
3414
 
2951
    
3415
 
2952
        $header      = pack("vv", $record, $length);
3416
        $header      = pack("vv", $record, $length);
2953
        $data        = pack("V", $cObj);
3417
        $data        = pack("V", $cObj);
2954
        $data       .= pack("v", $OT);
3418
        $data       .= pack("v", $OT);
2955
        $data       .= pack("v", $id);
3419
        $data       .= pack("v", $id);
2956
        $data       .= pack("v", $grbit);
3420
        $data       .= pack("v", $grbit);
Line 2978... Line 3442...
2978
        $data       .= pack("v", $Reserved3);
3442
        $data       .= pack("v", $Reserved3);
2979
        $data       .= pack("v", $cbPictFmla);
3443
        $data       .= pack("v", $cbPictFmla);
2980
        $data       .= pack("v", $Reserved4);
3444
        $data       .= pack("v", $Reserved4);
2981
        $data       .= pack("v", $grbit2);
3445
        $data       .= pack("v", $grbit2);
2982
        $data       .= pack("V", $Reserved5);
3446
        $data       .= pack("V", $Reserved5);
2983
    
3447
 
2984
        $this->_append($header.$data);
3448
        $this->_append($header . $data);
2985
    }
3449
    }
2986
    
3450
 
2987
    /**
3451
    /**
2988
    * Convert a 24 bit bitmap into the modified internal format used by Windows.
3452
    * Convert a 24 bit bitmap into the modified internal format used by Windows.
2989
    * This is described in BITMAPCOREHEADER and BITMAPCOREINFO structures in the
3453
    * This is described in BITMAPCOREHEADER and BITMAPCOREINFO structures in the
2990
    * MSDN library.
3454
    * MSDN library.
2991
    *
3455
    *
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
        }
3003
            
3467
 
3004
        // Slurp the file into a string.
3468
        // Slurp the file into a string.
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) {
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);
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");
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
        //
3024
        $size_array   = unpack("V", substr($data, 0, 4));
3488
        $size_array   = unpack("Vsa", substr($data, 0, 4));
3025
        $size   = $size_array[''];
3489
        $size   = $size_array['sa'];
3026
        $data   = substr($data, 4);
3490
        $data   = substr($data, 4);
3027
        $size  -= 0x36; // Subtract size of bitmap header.
3491
        $size  -= 0x36; // Subtract size of bitmap header.
3028
        $size  += 0x0C; // Add size of BIFF header.
3492
        $size  += 0x0C; // Add size of BIFF header.
3029
    
3493
 
3030
        // Remove bitmap data: reserved, offset, header length.
3494
        // Remove bitmap data: reserved, offset, header length.
3031
        $data = substr($data, 12);
3495
        $data = substr($data, 12);
3032
    
3496
 
3033
        // Read and remove the bitmap width and height. Verify the sizes.
3497
        // Read and remove the bitmap width and height. Verify the sizes.
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
        }
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");
3053
        }
3517
        }
3054
    
3518
 
3055
        // Read and remove the bitmap compression. Verify compression.
3519
        // Read and remove the bitmap compression. Verify compression.
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;
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");
3062
        }
3526
        }
3063
    
3527
 
3064
        // Remove bitmap data: data size, hres, vres, colours, imp. colours.
3528
        // Remove bitmap data: data size, hres, vres, colours, imp. colours.
3065
        $data = substr($data, 20);
3529
        $data = substr($data, 20);
3066
    
3530
 
3067
        // Add the BITMAPCOREHEADER data
3531
        // Add the BITMAPCOREHEADER data
3068
        $header  = pack("Vvvvv", 0x000c, $width, $height, 0x01, 0x18);
3532
        $header  = pack("Vvvvv", 0x000c, $width, $height, 0x01, 0x18);
3069
        $data    = $header . $data;
3533
        $data    = $header . $data;
3070
    
3534
 
3071
        return (array($width, $height, $size, $data));
3535
        return (array($width, $height, $size, $data));
3072
    }
3536
    }
3073
    
3537
 
3074
    /**
3538
    /**
3075
    * Store the window zoom factor. This should be a reduced fraction but for
3539
    * Store the window zoom factor. This should be a reduced fraction but for
3076
    * simplicity we will store all fractions with a numerator of 100.
3540
    * simplicity we will store all fractions with a numerator of 100.
3077
    *
3541
    *
3078
    * @access private
3542
    * @access private
Line 3081... Line 3545...
3081
    {
3545
    {
3082
        // If scale is 100 we don't need to write a record
3546
        // If scale is 100 we don't need to write a record
3083
        if ($this->_zoom == 100) {
3547
        if ($this->_zoom == 100) {
3084
            return;
3548
            return;
3085
        }
3549
        }
3086
    
3550
 
3087
        $record      = 0x00A0;               // Record identifier
3551
        $record      = 0x00A0;               // Record identifier
3088
        $length      = 0x0004;               // Bytes to follow
3552
        $length      = 0x0004;               // Bytes to follow
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);
-
 
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));
3092
        $this->_append($header.$data);
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
}
3095
?>
3596
?>