Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/excel/Workbook.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003 *  Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
00004 *
00005 *  The majority of this is _NOT_ my code.  I simply ported it from the
00006 *  PERL Spreadsheet::WriteExcel module.
00007 *
00008 *  The author of the Spreadsheet::WriteExcel module is John McNamara 
00009 *  <jmcnamara@cpan.org>
00010 *
00011 *  I _DO_ maintain this code, and John McNamara has nothing to do with the
00012 *  porting of this code to PHP.  Any questions directly related to this
00013 *  class library should be directed to me.
00014 *
00015 *  License Information:
00016 *
00017 *    Spreadsheet::WriteExcel:  A library for generating Excel Spreadsheets
00018 *    Copyright (C) 2002 Xavier Noguer xnoguer@rezebra.com
00019 *
00020 *    This library is free software; you can redistribute it and/or
00021 *    modify it under the terms of the GNU Lesser General Public
00022 *    License as published by the Free Software Foundation; either
00023 *    version 2.1 of the License, or (at your option) any later version.
00024 *
00025 *    This library is distributed in the hope that it will be useful,
00026 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00027 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00028 *    Lesser General Public License for more details.
00029 *
00030 *    You should have received a copy of the GNU Lesser General Public
00031 *    License along with this library; if not, write to the Free Software
00032 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00033 */
00034 
00035 //require_once('Format.php');
00036 require_once("$CFG->libdir/excel/Format.php");
00037 require_once('OLEwriter.php');
00038 require_once('BIFFwriter.php');
00039 
00047 class Workbook extends BIFFwriter
00048 {
00054     function Workbook($filename)
00055     {
00056         $this->BIFFwriter(); // It needs to call its parent's constructor explicitly
00057     
00058         $this->_filename         = $filename;
00059         $this->parser            = new Parser($this->_byte_order);
00060         $this->_1904             = 0;
00061         $this->activesheet       = 0;
00062         $this->firstsheet        = 0;
00063         $this->selected          = 0;
00064         $this->xf_index          = 16; // 15 style XF's and 1 cell XF.
00065         $this->_fileclosed       = 0;
00066         $this->_biffsize         = 0;
00067         $this->sheetname         = "Sheet";
00068         $this->tmp_format        = new Format();
00069         $this->worksheets        = array();
00070         $this->sheetnames        = array();
00071         $this->formats           = array();
00072         $this->palette           = array();
00073     
00074         // Add the default format for hyperlinks
00075         $this->url_format =& $this->add_format(array('color' => 'blue', 'underline' => 1));
00076     
00077         // Check for a filename
00078         //if ($this->_filename == '') {
00079         //    die('Filename required by Spreadsheet::WriteExcel->new()');
00080         //}
00081     
00082         # Warn if tmpfiles can't be used.
00083         //$this->tmpfile_warning();
00084         $this->_set_palette_xl97();
00085     }
00086     
00091     function close()
00092     {
00093         if ($this->_fileclosed) { // Prevent close() from being called twice.
00094             return;
00095         }
00096         $this->store_workbook();
00097         $this->_fileclosed = 1;
00098     }
00099     
00100     
00107     function sheets()
00108     {
00109         return($this->worksheets());
00110     }
00111     
00117     function worksheets()
00118     {
00119         return($this->worksheets);
00120     }
00121     
00130     function &add_worksheet($name = '')
00131     {
00132         $index     = count($this->worksheets);
00133         $sheetname = $this->sheetname;
00134 
00135         if($name == '') {
00136             $name = $sheetname.($index+1); 
00137         }
00138     
00139         // Check that sheetname is <= 31 chars (Excel limit).
00140         if(strlen($name) > 31) {
00141             die("Sheetname $name must be <= 31 chars");
00142         }
00143     
00144         // Check that the worksheet name doesn't already exist: a fatal Excel error.
00145         for($i=0; $i < count($this->worksheets); $i++)
00146         {
00147             if($name == $this->worksheets[$i]->get_name()) {
00148                 die("Worksheet '$name' already exists");
00149             }
00150         }
00151     
00152         $worksheet = new Worksheet($name,$index,$this->activesheet,
00153                                    $this->firstsheet,$this->url_format,
00154                                    $this->parser);
00155         $this->worksheets[$index] = &$worksheet;      // Store ref for iterator
00156         $this->sheetnames[$index] = $name;            // Store EXTERNSHEET names
00157         //$this->parser->set_ext_sheet($name,$index); // Store names in Formula.php
00158         return($worksheet);
00159     }
00160     
00169     function &addworksheet($name = '')
00170     {
00171         return($this->add_worksheet($name));
00172     }
00173     
00182     function &add_format($properties = array())
00183     {
00184         $format = new Format($this->xf_index,$properties);
00185         $this->xf_index += 1;
00186         $this->formats[] = &$format;
00187         return($format);
00188     }
00189     
00198     function &addformat($properties = array())
00199     {
00200          return($this->add_format($properties));
00201     }
00202     
00203     
00214     function set_custom_color($index,$red,$green,$blue)
00215     {
00216         // Match a HTML #xxyyzz style parameter
00217         /*if (defined $_[1] and $_[1] =~ /^#(\w\w)(\w\w)(\w\w)/ ) {
00218             @_ = ($_[0], hex $1, hex $2, hex $3);
00219         }*/
00220     
00221         // Check that the colour index is the right range
00222         if ($index < 8 or $index > 64) {
00223             die("Color index $index outside range: 8 <= index <= 64");
00224         }
00225     
00226         // Check that the colour components are in the right range
00227         if ( ($red   < 0 or $red   > 255) ||
00228              ($green < 0 or $green > 255) ||
00229              ($blue  < 0 or $blue  > 255) )  
00230         {
00231             die("Color component outside range: 0 <= color <= 255");
00232         }
00233 
00234         $index -= 8; // Adjust colour index (wingless dragonfly)
00235         
00236         // Set the RGB value
00237         $this->palette[$index] = array($red, $green, $blue, 0);
00238         return($index + 8);
00239     }
00240     
00244     function _set_palette_xl97()
00245     {
00246         $this->palette = array(
00247                            array(0x00, 0x00, 0x00, 0x00),   // 8
00248                            array(0xff, 0xff, 0xff, 0x00),   // 9
00249                            array(0xff, 0x00, 0x00, 0x00),   // 10
00250                            array(0x00, 0xff, 0x00, 0x00),   // 11
00251                            array(0x00, 0x00, 0xff, 0x00),   // 12
00252                            array(0xff, 0xff, 0x00, 0x00),   // 13
00253                            array(0xff, 0x00, 0xff, 0x00),   // 14
00254                            array(0x00, 0xff, 0xff, 0x00),   // 15
00255                            array(0x80, 0x00, 0x00, 0x00),   // 16
00256                            array(0x00, 0x80, 0x00, 0x00),   // 17
00257                            array(0x00, 0x00, 0x80, 0x00),   // 18
00258                            array(0x80, 0x80, 0x00, 0x00),   // 19
00259                            array(0x80, 0x00, 0x80, 0x00),   // 20
00260                            array(0x00, 0x80, 0x80, 0x00),   // 21
00261                            array(0xc0, 0xc0, 0xc0, 0x00),   // 22
00262                            array(0x80, 0x80, 0x80, 0x00),   // 23
00263                            array(0x99, 0x99, 0xff, 0x00),   // 24
00264                            array(0x99, 0x33, 0x66, 0x00),   // 25
00265                            array(0xff, 0xff, 0xcc, 0x00),   // 26
00266                            array(0xcc, 0xff, 0xff, 0x00),   // 27
00267                            array(0x66, 0x00, 0x66, 0x00),   // 28
00268                            array(0xff, 0x80, 0x80, 0x00),   // 29
00269                            array(0x00, 0x66, 0xcc, 0x00),   // 30
00270                            array(0xcc, 0xcc, 0xff, 0x00),   // 31
00271                            array(0x00, 0x00, 0x80, 0x00),   // 32
00272                            array(0xff, 0x00, 0xff, 0x00),   // 33
00273                            array(0xff, 0xff, 0x00, 0x00),   // 34
00274                            array(0x00, 0xff, 0xff, 0x00),   // 35
00275                            array(0x80, 0x00, 0x80, 0x00),   // 36
00276                            array(0x80, 0x00, 0x00, 0x00),   // 37
00277                            array(0x00, 0x80, 0x80, 0x00),   // 38
00278                            array(0x00, 0x00, 0xff, 0x00),   // 39
00279                            array(0x00, 0xcc, 0xff, 0x00),   // 40
00280                            array(0xcc, 0xff, 0xff, 0x00),   // 41
00281                            array(0xcc, 0xff, 0xcc, 0x00),   // 42
00282                            array(0xff, 0xff, 0x99, 0x00),   // 43
00283                            array(0x99, 0xcc, 0xff, 0x00),   // 44
00284                            array(0xff, 0x99, 0xcc, 0x00),   // 45
00285                            array(0xcc, 0x99, 0xff, 0x00),   // 46
00286                            array(0xff, 0xcc, 0x99, 0x00),   // 47
00287                            array(0x33, 0x66, 0xff, 0x00),   // 48
00288                            array(0x33, 0xcc, 0xcc, 0x00),   // 49
00289                            array(0x99, 0xcc, 0x00, 0x00),   // 50
00290                            array(0xff, 0xcc, 0x00, 0x00),   // 51
00291                            array(0xff, 0x99, 0x00, 0x00),   // 52
00292                            array(0xff, 0x66, 0x00, 0x00),   // 53
00293                            array(0x66, 0x66, 0x99, 0x00),   // 54
00294                            array(0x96, 0x96, 0x96, 0x00),   // 55
00295                            array(0x00, 0x33, 0x66, 0x00),   // 56
00296                            array(0x33, 0x99, 0x66, 0x00),   // 57
00297                            array(0x00, 0x33, 0x00, 0x00),   // 58
00298                            array(0x33, 0x33, 0x00, 0x00),   // 59
00299                            array(0x99, 0x33, 0x00, 0x00),   // 60
00300                            array(0x99, 0x33, 0x66, 0x00),   // 61
00301                            array(0x33, 0x33, 0x99, 0x00),   // 62
00302                            array(0x33, 0x33, 0x33, 0x00),   // 63
00303                          );
00304     }
00305     
00306     
00307     ###############################################################################
00308     #
00309     # _tmpfile_warning()
00310     #
00311     # Check that tmp files can be created for use in Worksheet.pm. A CGI, mod_perl
00312     # or IIS might not have permission to create tmp files. The test is here rather
00313     # than in Worksheet.pm so that only one warning is given.
00314     #
00315     /*sub _tmpfile_warning {
00316     
00317         my $fh = IO::File->new_tmpfile();
00318     
00319         if ((not defined $fh) && ($^W)) {
00320             carp("Unable to create tmp files via IO::File->new_tmpfile(). " .
00321                  "Storing data in memory")
00322     }
00323     }*/
00324     
00329     function store_workbook()
00330     {
00331         // Ensure that at least one worksheet has been selected.
00332         if ($this->activesheet == 0) {
00333             $this->worksheets[0]->selected = 1;
00334         }
00335     
00336         // Calculate the number of selected worksheet tabs and call the finalization
00337         // methods for each worksheet
00338         for($i=0; $i < count($this->worksheets); $i++)
00339         {
00340             if($this->worksheets[$i]->selected)
00341               $this->selected++;
00342             $this->worksheets[$i]->close($this->sheetnames);
00343         }
00344     
00345         // Add Workbook globals
00346         $this->_store_bof(0x0005);
00347         $this->_store_externs();    // For print area and repeat rows
00348         $this->_store_names();      // For print area and repeat rows
00349         $this->_store_window1();
00350         $this->_store_1904();
00351         $this->_store_all_fonts();
00352         $this->_store_all_num_formats();
00353         $this->_store_all_xfs();
00354         $this->_store_all_styles();
00355         $this->_store_palette();
00356         $this->_calc_sheet_offsets();
00357     
00358         // Add BOUNDSHEET records
00359         for($i=0; $i < count($this->worksheets); $i++) {
00360             $this->_store_boundsheet($this->worksheets[$i]->name,$this->worksheets[$i]->offset);
00361         }
00362     
00363         // End Workbook globals
00364         $this->_store_eof();
00365 
00366         // Store the workbook in an OLE container
00367         $this->_store_OLE_file();
00368     }
00369     
00374     function _store_OLE_file()
00375     {
00376         $OLE  = new OLEwriter($this->_filename);
00377         // Write Worksheet data if data <~ 7MB
00378         if ($OLE->set_size($this->_biffsize))
00379         {
00380             $OLE->write_header();
00381             $OLE->write($this->_data);
00382             foreach($this->worksheets as $sheet) 
00383             {
00384                 while ($tmp = $sheet->get_data()) {
00385                     $OLE->write($tmp);
00386                 }
00387             }
00388         }
00389         $OLE->close();
00390     }
00391     
00395     function _calc_sheet_offsets()
00396     {
00397         $BOF     = 11;
00398         $EOF     = 4;
00399         $offset  = $this->_datasize;
00400         for($i=0; $i < count($this->worksheets); $i++) {
00401             $offset += $BOF + strlen($this->worksheets[$i]->name);
00402         }
00403         $offset += $EOF;
00404         for($i=0; $i < count($this->worksheets); $i++) {
00405             $this->worksheets[$i]->offset = $offset;
00406             $offset += $this->worksheets[$i]->_datasize;
00407         }
00408         $this->_biffsize = $offset;
00409     }
00410     
00414     function _store_all_fonts()
00415     {
00416         // tmp_format is added by new(). We use this to write the default XF's
00417         $format = $this->tmp_format;
00418         $font   = $format->get_font();
00419     
00420         // Note: Fonts are 0-indexed. According to the SDK there is no index 4,
00421         // so the following fonts are 0, 1, 2, 3, 5
00422         //
00423         for($i=1; $i <= 5; $i++){
00424             $this->_append($font);
00425         }
00426     
00427         // Iterate through the XF objects and write a FONT record if it isn't the
00428         // same as the default FONT and if it hasn't already been used.
00429         //
00430         $fonts = array();
00431         $index = 6;                  // The first user defined FONT
00432     
00433         $key = $format->get_font_key(); // The default font from _tmp_format
00434         $fonts[$key] = 0;               // Index of the default font
00435     
00436         for($i=0; $i < count($this->formats); $i++) {
00437             $key = $this->formats[$i]->get_font_key();
00438             if (isset($fonts[$key])) {
00439                 // FONT has already been used
00440                 $this->formats[$i]->font_index = $fonts[$key];
00441             }
00442             else {
00443                 // Add a new FONT record
00444                 $fonts[$key]        = $index;
00445                 $this->formats[$i]->font_index = $index;
00446                 $index++;
00447                 $font = $this->formats[$i]->get_font();
00448                 $this->_append($font);
00449             }
00450         }
00451     }
00452     
00456     function _store_all_num_formats()
00457     {
00458         // Leaning num_format syndrome
00459         $hash_num_formats = array();
00460         $num_formats      = array();
00461         $index = 164;
00462     
00463         // Iterate through the XF objects and write a FORMAT record if it isn't a
00464         // built-in format type and if the FORMAT string hasn't already been used.
00465         //
00466         for($i=0; $i < count($this->formats); $i++)
00467         {
00468             $num_format = $this->formats[$i]->_num_format;
00469     
00470             // Check if $num_format is an index to a built-in format.
00471             // Also check for a string of zeros, which is a valid format string
00472             // but would evaluate to zero.
00473             //
00474             if (!preg_match("/^0+\d/",$num_format))
00475             {
00476                 if (preg_match("/^\d+$/",$num_format)) { // built-in format
00477                     continue;
00478                 }
00479             }
00480     
00481             if (isset($hash_num_formats[$num_format])) {
00482                 // FORMAT has already been used
00483                 $this->formats[$i]->_num_format = $hash_num_formats[$num_format];
00484             }
00485             else
00486             {
00487                 // Add a new FORMAT
00488                 $hash_num_formats[$num_format]  = $index;
00489                 $this->formats[$i]->_num_format = $index;
00490                 array_push($num_formats,$num_format);
00491                 $index++;
00492             }
00493         }
00494     
00495         // Write the new FORMAT records starting from 0xA4
00496         $index = 164;
00497         foreach ($num_formats as $num_format)
00498         {
00499             $this->_store_num_format($num_format,$index);
00500             $index++;
00501         }
00502     }
00503     
00507     function _store_all_xfs()
00508     {
00509         // tmp_format is added by the constructor. We use this to write the default XF's
00510         // The default font index is 0
00511         //
00512         $format = $this->tmp_format;
00513         for ($i=0; $i <= 14; $i++)
00514         {
00515             $xf = $format->get_xf('style'); // Style XF
00516             $this->_append($xf);
00517         }
00518     
00519         $xf = $format->get_xf('cell');      // Cell XF
00520         $this->_append($xf);
00521     
00522         // User defined XFs
00523         for($i=0; $i < count($this->formats); $i++)
00524         {
00525             $xf = $this->formats[$i]->get_xf('cell');
00526             $this->_append($xf);
00527         }
00528     }
00529     
00533     function _store_all_styles()
00534     {
00535         $this->_store_style();
00536     }
00537     
00542     function _store_externs()
00543     {
00544         // Create EXTERNCOUNT with number of worksheets
00545         $this->_store_externcount(count($this->worksheets));
00546     
00547         // Create EXTERNSHEET for each worksheet
00548         foreach ($this->sheetnames as $sheetname) {
00549             $this->_store_externsheet($sheetname);
00550         }
00551     }
00552     
00556     function _store_names()
00557     {
00558         // Create the print area NAME records
00559         foreach ($this->worksheets as $worksheet)
00560         {
00561             // Write a Name record if the print area has been defined
00562             if (isset($worksheet->_print_rowmin))
00563             {
00564                 $this->store_name_short(
00565                     $worksheet->index,
00566                     0x06, // NAME type
00567                     $worksheet->_print_rowmin,
00568                     $worksheet->_print_rowmax,
00569                     $worksheet->_print_colmin,
00570                     $worksheet->_print_colmax
00571                     );
00572             }
00573         }
00574     
00575         // Create the print title NAME records
00576         foreach ($this->worksheets as $worksheet)
00577         {
00578             $rowmin = $worksheet->_title_rowmin;
00579             $rowmax = $worksheet->_title_rowmax;
00580             $colmin = $worksheet->_title_colmin;
00581             $colmax = $worksheet->_title_colmax;
00582     
00583             // Determine if row + col, row, col or nothing has been defined
00584             // and write the appropriate record
00585             //
00586             if (isset($rowmin) && isset($colmin))
00587             {
00588                 // Row and column titles have been defined.
00589                 // Row title has been defined.
00590                 $this->store_name_long(
00591                     $worksheet->index,
00592                     0x07, // NAME type
00593                     $rowmin,
00594                     $rowmax,
00595                     $colmin,
00596                     $colmax
00597                     );
00598             }
00599             elseif (isset($rowmin))
00600             {
00601                 // Row title has been defined.
00602                 $this->store_name_short(
00603                     $worksheet->index,
00604                     0x07, // NAME type
00605                     $rowmin,
00606                     $rowmax,
00607                     0x00,
00608                     0xff
00609                     );
00610             }
00611             elseif (isset($colmin))
00612             {
00613                 // Column title has been defined.
00614                 $this->store_name_short(
00615                     $worksheet->index,
00616                     0x07, // NAME type
00617                     0x0000,
00618                     0x3fff,
00619                     $colmin,
00620                     $colmax
00621                     );
00622             }
00623             else {
00624                 // Print title hasn't been defined.
00625             }
00626         }
00627     }
00628     
00629 
00630     
00631     
00632     /******************************************************************************
00633     *
00634     * BIFF RECORDS
00635     *
00636     */
00637     
00641     function _store_window1()
00642     {
00643         $record    = 0x003D;                 // Record identifier
00644         $length    = 0x0012;                 // Number of bytes to follow
00645     
00646         $xWn       = 0x0000;                 // Horizontal position of window
00647         $yWn       = 0x0000;                 // Vertical position of window
00648         $dxWn      = 0x25BC;                 // Width of window
00649         $dyWn      = 0x1572;                 // Height of window
00650     
00651         $grbit     = 0x0038;                 // Option flags
00652         $ctabsel   = $this->selected;        // Number of workbook tabs selected
00653         $wTabRatio = 0x0258;                 // Tab to scrollbar ratio
00654     
00655         $itabFirst = $this->firstsheet;   // 1st displayed worksheet
00656         $itabCur   = $this->activesheet;  // Active worksheet
00657     
00658         $header    = pack("vv",        $record, $length);
00659         $data      = pack("vvvvvvvvv", $xWn, $yWn, $dxWn, $dyWn,
00660                                        $grbit,
00661                                        $itabCur, $itabFirst,
00662                                        $ctabsel, $wTabRatio);
00663         $this->_append($header.$data);
00664     }
00665     
00672     function _store_boundsheet($sheetname,$offset)
00673     {
00674         $record    = 0x0085;                    // Record identifier
00675         $length    = 0x07 + strlen($sheetname); // Number of bytes to follow
00676     
00677         $grbit     = 0x0000;                    // Sheet identifier
00678         $cch       = strlen($sheetname);        // Length of sheet name
00679     
00680         $header    = pack("vv",  $record, $length);
00681         $data      = pack("VvC", $offset, $grbit, $cch);
00682         $this->_append($header.$data.$sheetname);
00683     }
00684     
00688     function _store_style()
00689     {
00690         $record    = 0x0293;   // Record identifier
00691         $length    = 0x0004;   // Bytes to follow
00692                                
00693         $ixfe      = 0x8000;   // Index to style XF
00694         $BuiltIn   = 0x00;     // Built-in style
00695         $iLevel    = 0xff;     // Outline style level
00696     
00697         $header    = pack("vv",  $record, $length);
00698         $data      = pack("vCC", $ixfe, $BuiltIn, $iLevel);
00699         $this->_append($header.$data);
00700     }
00701     
00702     
00709     function _store_num_format($format,$ifmt)
00710     {
00711         $record    = 0x041E;                      // Record identifier
00712         $length    = 0x03 + strlen($format);      // Number of bytes to follow
00713     
00714         $cch       = strlen($format);             // Length of format string
00715     
00716         $header    = pack("vv", $record, $length);
00717         $data      = pack("vC", $ifmt, $cch);
00718         $this->_append($header.$data.$format);
00719     }
00720     
00724     function _store_1904()
00725     {
00726         $record    = 0x0022;         // Record identifier
00727         $length    = 0x0002;         // Bytes to follow
00728 
00729         $f1904     = $this->_1904;   // Flag for 1904 date system
00730     
00731         $header    = pack("vv", $record, $length);
00732         $data      = pack("v", $f1904);
00733         $this->_append($header.$data);
00734     }
00735     
00736     
00749     function _store_externcount($cxals)
00750     {
00751         $record   = 0x0016;          // Record identifier
00752         $length   = 0x0002;          // Number of bytes to follow
00753     
00754         $header   = pack("vv", $record, $length);
00755         $data     = pack("v",  $cxals);
00756         $this->_append($header.$data);
00757     }
00758     
00759     
00769     function _store_externsheet($sheetname)
00770     {
00771         $record      = 0x0017;                     // Record identifier
00772         $length      = 0x02 + strlen($sheetname);  // Number of bytes to follow
00773                                                    
00774         $cch         = strlen($sheetname);         // Length of sheet name
00775         $rgch        = 0x03;                       // Filename encoding
00776     
00777         $header      = pack("vv",  $record, $length);
00778         $data        = pack("CC", $cch, $rgch);
00779         $this->_append($header.$data.$sheetname);
00780     }
00781     
00782     
00794     function store_name_short($index,$type,$rowmin,$rowmax,$colmin,$colmax)
00795     {
00796         $record          = 0x0018;       // Record identifier
00797         $length          = 0x0024;       // Number of bytes to follow
00798     
00799         $grbit           = 0x0020;       // Option flags
00800         $chKey           = 0x00;         // Keyboard shortcut
00801         $cch             = 0x01;         // Length of text name
00802         $cce             = 0x0015;       // Length of text definition
00803         $ixals           = $index + 1;   // Sheet index
00804         $itab            = $ixals;       // Equal to ixals
00805         $cchCustMenu     = 0x00;         // Length of cust menu text
00806         $cchDescription  = 0x00;         // Length of description text
00807         $cchHelptopic    = 0x00;         // Length of help topic text
00808         $cchStatustext   = 0x00;         // Length of status bar text
00809         $rgch            = $type;        // Built-in name type
00810     
00811         $unknown03       = 0x3b;
00812         $unknown04       = 0xffff-$index;
00813         $unknown05       = 0x0000;
00814         $unknown06       = 0x0000;
00815         $unknown07       = 0x1087;
00816         $unknown08       = 0x8005;
00817     
00818         $header             = pack("vv", $record, $length);
00819         $data               = pack("v", $grbit);
00820         $data              .= pack("C", $chKey);
00821         $data              .= pack("C", $cch);
00822         $data              .= pack("v", $cce);
00823         $data              .= pack("v", $ixals);
00824         $data              .= pack("v", $itab);
00825         $data              .= pack("C", $cchCustMenu);
00826         $data              .= pack("C", $cchDescription);
00827         $data              .= pack("C", $cchHelptopic);
00828         $data              .= pack("C", $cchStatustext);
00829         $data              .= pack("C", $rgch);
00830         $data              .= pack("C", $unknown03);
00831         $data              .= pack("v", $unknown04);
00832         $data              .= pack("v", $unknown05);
00833         $data              .= pack("v", $unknown06);
00834         $data              .= pack("v", $unknown07);
00835         $data              .= pack("v", $unknown08);
00836         $data              .= pack("v", $index);
00837         $data              .= pack("v", $index);
00838         $data              .= pack("v", $rowmin);
00839         $data              .= pack("v", $rowmax);
00840         $data              .= pack("C", $colmin);
00841         $data              .= pack("C", $colmax);
00842         $this->_append($header.$data);
00843     }
00844     
00845     
00859     function store_name_long($index,$type,$rowmin,$rowmax,$colmin,$colmax)
00860     {
00861         $record          = 0x0018;       // Record identifier
00862         $length          = 0x003d;       // Number of bytes to follow
00863         $grbit           = 0x0020;       // Option flags
00864         $chKey           = 0x00;         // Keyboard shortcut
00865         $cch             = 0x01;         // Length of text name
00866         $cce             = 0x002e;       // Length of text definition
00867         $ixals           = $index + 1;   // Sheet index
00868         $itab            = $ixals;       // Equal to ixals
00869         $cchCustMenu     = 0x00;         // Length of cust menu text
00870         $cchDescription  = 0x00;         // Length of description text
00871         $cchHelptopic    = 0x00;         // Length of help topic text
00872         $cchStatustext   = 0x00;         // Length of status bar text
00873         $rgch            = $type;        // Built-in name type
00874     
00875         $unknown01       = 0x29;
00876         $unknown02       = 0x002b;
00877         $unknown03       = 0x3b;
00878         $unknown04       = 0xffff-$index;
00879         $unknown05       = 0x0000;
00880         $unknown06       = 0x0000;
00881         $unknown07       = 0x1087;
00882         $unknown08       = 0x8008;
00883     
00884         $header             = pack("vv",  $record, $length);
00885         $data               = pack("v", $grbit);
00886         $data              .= pack("C", $chKey);
00887         $data              .= pack("C", $cch);
00888         $data              .= pack("v", $cce);
00889         $data              .= pack("v", $ixals);
00890         $data              .= pack("v", $itab);
00891         $data              .= pack("C", $cchCustMenu);
00892         $data              .= pack("C", $cchDescription);
00893         $data              .= pack("C", $cchHelptopic);
00894         $data              .= pack("C", $cchStatustext);
00895         $data              .= pack("C", $rgch);
00896         $data              .= pack("C", $unknown01);
00897         $data              .= pack("v", $unknown02);
00898         // Column definition
00899         $data              .= pack("C", $unknown03);
00900         $data              .= pack("v", $unknown04);
00901         $data              .= pack("v", $unknown05);
00902         $data              .= pack("v", $unknown06);
00903         $data              .= pack("v", $unknown07);
00904         $data              .= pack("v", $unknown08);
00905         $data              .= pack("v", $index);
00906         $data              .= pack("v", $index);
00907         $data              .= pack("v", 0x0000);
00908         $data              .= pack("v", 0x3fff);
00909         $data              .= pack("C", $colmin);
00910         $data              .= pack("C", $colmax);
00911         // Row definition
00912         $data              .= pack("C", $unknown03);
00913         $data              .= pack("v", $unknown04);
00914         $data              .= pack("v", $unknown05);
00915         $data              .= pack("v", $unknown06);
00916         $data              .= pack("v", $unknown07);
00917         $data              .= pack("v", $unknown08);
00918         $data              .= pack("v", $index);
00919         $data              .= pack("v", $index);
00920         $data              .= pack("v", $rowmin);
00921         $data              .= pack("v", $rowmax);
00922         $data              .= pack("C", 0x00);
00923         $data              .= pack("C", 0xff);
00924         // End of data
00925         $data              .= pack("C", 0x10);
00926         $this->_append($header.$data);
00927     }
00928     
00929     
00933     function _store_palette()
00934     {
00935         $aref            = $this->palette;
00936     
00937         $record          = 0x0092;                 // Record identifier
00938         $length          = 2 + 4 * count($aref);   // Number of bytes to follow
00939         $ccv             =         count($aref);   // Number of RGB values to follow
00940         $data = '';                                // The RGB data
00941     
00942         // Pack the RGB data
00943         foreach($aref as $color)
00944         {
00945             foreach($color as $byte) {
00946                 $data .= pack("C",$byte);
00947             }
00948         }
00949     
00950         $header = pack("vvv",  $record, $length, $ccv);
00951         $this->_append($header.$data);
00952     }
00953 }
00954 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations