ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
Spreadsheet_Excel_Writer_Workbook Class Reference
+ Inheritance diagram for Spreadsheet_Excel_Writer_Workbook:
+ Collaboration diagram for Spreadsheet_Excel_Writer_Workbook:

Public Member Functions

 Spreadsheet_Excel_Writer_Workbook ($filename)
 Class constructor. More...
 
 close ()
 Calls finalization methods. More...
 
 sheets ()
 An accessor for the _worksheets[] array Returns an array of the worksheet objects in a workbook It actually calls to worksheets() More...
 
 worksheets ()
 An accessor for the _worksheets[] array. More...
 
 setVersion ($version)
 Sets the BIFF version. More...
 
 setCountry ($code)
 Set the country identifier for the workbook. More...
 
addWorksheet ($name='')
 Add a new worksheet to the Excel workbook. More...
 
addFormat ($properties=array())
 Add a new format to the Excel workbook. More...
 
addValidator ()
 Create new validator. More...
 
 setCustomColor ($index, $red, $green, $blue)
 Change the RGB components of the elements in the colour palette. More...
 
 _setPaletteXl97 ()
 Sets the colour palette to the Excel 97+ default. More...
 
 _storeWorkbook ()
 Assemble worksheets into a workbook and send the BIFF data to an OLE storage. More...
 
 _storeOLEFile ()
 Store the workbook in an OLE container. More...
 
 _calcSheetOffsets ()
 Calculate offsets for Worksheet BOF records. More...
 
 _storeAllFonts ()
 Store the Excel FONT records. More...
 
 _storeAllNumFormats ()
 Store user defined numerical formats i.e. More...
 
 _storeAllXfs ()
 Write all XF records. More...
 
 _storeAllStyles ()
 Write all STYLE records. More...
 
 _storeExterns ()
 Write the EXTERNCOUNT and EXTERNSHEET records. More...
 
 _storeNames ()
 Write the NAME record to define the print area and the repeat rows and cols. More...
 
 _storeCodepage ()
 Stores the CODEPAGE biff record. More...
 
 _storeWindow1 ()
 Write Excel BIFF WINDOW1 record. More...
 
 _storeBoundsheet ($sheetname, $offset)
 Writes Excel BIFF BOUNDSHEET record. More...
 
 _storeSupbookInternal ()
 Write Internal SUPBOOK record. More...
 
 _storeExternsheetBiff8 ()
 Writes the Excel BIFF EXTERNSHEET record. More...
 
 _storeStyle ()
 Write Excel BIFF STYLE records. More...
 
 _storeNumFormat ($format, $ifmt)
 Writes Excel FORMAT record for non "built-in" numerical formats. More...
 
 _storeDatemode ()
 Write DATEMODE record to indicate the date system in use (1904 or 1900). More...
 
 _storeExterncount ($cxals)
 Write BIFF record EXTERNCOUNT to indicate the number of external sheet references in the workbook. More...
 
 _storeExternsheet ($sheetname)
 Writes the Excel BIFF EXTERNSHEET record. More...
 
 _storeNameShort ($index, $type, $rowmin, $rowmax, $colmin, $colmax)
 Store the NAME record in the short format that is used for storing the print area, repeat rows only and repeat columns only. More...
 
 _storeNameLong ($index, $type, $rowmin, $rowmax, $colmin, $colmax)
 Store the NAME record in the long format that is used for storing the repeat rows and columns when both are specified. More...
 
 _storeCountry ()
 Stores the COUNTRY record for localization. More...
 
 _storePalette ()
 Stores the PALETTE biff record. More...
 
 _calculateSharedStringsSizes ()
 Calculate Handling of the SST continue blocks is complicated by the need to include an additional continuation byte depending on whether the string is split between blocks or whether it starts at the beginning of the block. More...
 
 _storeSharedStringsTable ()
 Write all of the workbooks strings into an indexed array. More...
 
- Public Member Functions inherited from Spreadsheet_Excel_Writer_BIFFwriter
 Spreadsheet_Excel_Writer_BIFFwriter ()
 Constructor. More...
 
 _setByteOrder ()
 Determine the byte order and store it as class data to avoid recalculating it for each call to new(). More...
 
 _prepend ($data)
 General storage function. More...
 
 _append ($data)
 General storage function. More...
 
 _storeBof ($type)
 Writes Excel BOF record to indicate the beginning of a stream or sub-stream in the BIFF file. More...
 
 _storeEof ()
 Writes Excel EOF record to indicate the end of a BIFF stream. More...
 
 _addContinue ($data)
 Excel limits the size of BIFF records. More...
 
 setTempDir ($dir)
 Sets the temp dir used for storing the OLE file. More...
 
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them. More...
 
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes. More...
 
 isError ($data, $code=null)
 Tell whether a value is a PEAR error. More...
 
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 
 expectError ($code=' *')
 This method is used to tell which errors you expect to get. More...
 
 popExpect ()
 This method pops one element off the expected error codes stack. More...
 
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available. More...
 
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack. More...
 
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied. More...
 
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options. More...
 
 staticPushErrorHandling ($mode, $options=null)
 
 staticPopErrorHandling ()
 
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack. More...
 
 popErrorHandling ()
 Pop the last error handler used. More...
 
 loadExtension ($ext)
 OS independant PHP extension load. More...
 

Data Fields

 $_filename
 
 $_parser
 
 $_1904
 
 $_activesheet
 
 $_firstsheet
 
 $_selected
 
 $_xf_index
 
 $_fileclosed
 
 $_biffsize
 
 $_sheetname
 
 $_tmp_format
 
 $_worksheets
 
 $_sheetnames
 
 $_formats
 
 $_palette
 
 $_url_format
 
 $_codepage
 
 $_country_code
 
 $_string_sizeinfo_size
 
- Data Fields inherited from Spreadsheet_Excel_Writer_BIFFwriter
 $_BIFF_version = 0x0500
 
 $_byte_order
 
 $_data
 
 $_datasize
 
 $_limit
 
 $_tmp_dir
 
- Data Fields inherited from PEAR
 $_debug = false
 
 $_default_error_mode = null
 
 $_default_error_options = null
 
 $_default_error_handler = ''
 
 $_error_class = 'PEAR_Error'
 
 $_expected_errors = array()
 

Detailed Description

Definition at line 50 of file Workbook.php.

Member Function Documentation

◆ _calcSheetOffsets()

Spreadsheet_Excel_Writer_Workbook::_calcSheetOffsets ( )

Calculate offsets for Worksheet BOF records.

private

Definition at line 606 of file Workbook.php.

References Spreadsheet_Excel_Writer_BIFFwriter\$_datasize, and _calculateSharedStringsSizes().

Referenced by _storeWorkbook().

607  {
608  if ($this->_BIFF_version == 0x0600) {
609  $boundsheet_length = 12; // fixed length for a BOUNDSHEET record
610  } else {
611  $boundsheet_length = 11;
612  }
613  $EOF = 4;
614  $offset = $this->_datasize;
615 
616  if ($this->_BIFF_version == 0x0600) {
617  // add the length of the SST
618  /* TODO: check this works for a lot of strings (> 8224 bytes) */
619  $offset += $this->_calculateSharedStringsSizes();
620  if ($this->_country_code != -1) {
621  $offset += 8; // adding COUNTRY record
622  }
623  // add the lenght of SUPBOOK, EXTERNSHEET and NAME records
624  //$offset += 8; // FIXME: calculate real value when storing the records
625  }
626  $total_worksheets = count($this->_worksheets);
627  // add the length of the BOUNDSHEET records
628  for ($i = 0; $i < $total_worksheets; $i++) {
629  $offset += $boundsheet_length + strlen($this->_worksheets[$i]->name);
630  }
631  $offset += $EOF;
632 
633  for ($i = 0; $i < $total_worksheets; $i++) {
634  $this->_worksheets[$i]->offset = $offset;
635  $offset += $this->_worksheets[$i]->_datasize;
636  }
637  $this->_biffsize = $offset;
638  }
_calculateSharedStringsSizes()
Calculate Handling of the SST continue blocks is complicated by the need to include an additional con...
Definition: Workbook.php:1293
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _calculateSharedStringsSizes()

Spreadsheet_Excel_Writer_Workbook::_calculateSharedStringsSizes ( )

Calculate Handling of the SST continue blocks is complicated by the need to include an additional continuation byte depending on whether the string is split between blocks or whether it starts at the beginning of the block.

(There are also additional complications that will arise later when/if Rich Strings are supported).

private

Definition at line 1293 of file Workbook.php.

Referenced by _calcSheetOffsets().

1294  {
1295  /* Iterate through the strings to calculate the CONTINUE block sizes.
1296  For simplicity we use the same size for the SST and CONTINUE records:
1297  8228 : Maximum Excel97 block size
1298  -4 : Length of block header
1299  -8 : Length of additional SST header information
1300  -8 : Arbitrary number to keep within _add_continue() limit = 8208
1301  */
1302  $continue_limit = 8208;
1303  $block_length = 0;
1304  $written = 0;
1305  $this->_block_sizes = array();
1306  $continue = 0;
1307 
1308  foreach (array_keys($this->_str_table) as $string) {
1309  $string_length = strlen($string);
1310  $headerinfo = unpack("vlength/Cencoding", $string);
1311  $encoding = $headerinfo["encoding"];
1312  $split_string = 0;
1313 
1314  // Block length is the total length of the strings that will be
1315  // written out in a single SST or CONTINUE block.
1316  $block_length += $string_length;
1317 
1318  // We can write the string if it doesn't cross a CONTINUE boundary
1319  if ($block_length < $continue_limit) {
1320  $written += $string_length;
1321  continue;
1322  }
1323 
1324  // Deal with the cases where the next string to be written will exceed
1325  // the CONTINUE boundary. If the string is very long it may need to be
1326  // written in more than one CONTINUE record.
1327  while ($block_length >= $continue_limit) {
1328 
1329  // We need to avoid the case where a string is continued in the first
1330  // n bytes that contain the string header information.
1331  $header_length = 3; // Min string + header size -1
1332  $space_remaining = $continue_limit - $written - $continue;
1333 
1334 
1335  /* TODO: Unicode data should only be split on char (2 byte)
1336  boundaries. Therefore, in some cases we need to reduce the
1337  amount of available
1338  */
1339  $align = 0;
1340 
1341  // Only applies to Unicode strings
1342  if ($encoding == 1) {
1343  // Min string + header size -1
1344  $header_length = 4;
1345 
1346  if ($space_remaining > $header_length) {
1347  // String contains 3 byte header => split on odd boundary
1348  if (!$split_string && $space_remaining % 2 != 1) {
1349  $space_remaining--;
1350  $align = 1;
1351  }
1352  // Split section without header => split on even boundary
1353  else if ($split_string && $space_remaining % 2 == 1) {
1354  $space_remaining--;
1355  $align = 1;
1356  }
1357 
1358  $split_string = 1;
1359  }
1360  }
1361 
1362 
1363  if ($space_remaining > $header_length) {
1364  // Write as much as possible of the string in the current block
1365  $written += $space_remaining;
1366 
1367  // Reduce the current block length by the amount written
1368  $block_length -= $continue_limit - $continue - $align;
1369 
1370  // Store the max size for this block
1371  $this->_block_sizes[] = $continue_limit - $align;
1372 
1373  // If the current string was split then the next CONTINUE block
1374  // should have the string continue flag (grbit) set unless the
1375  // split string fits exactly into the remaining space.
1376  if ($block_length > 0) {
1377  $continue = 1;
1378  } else {
1379  $continue = 0;
1380  }
1381  } else {
1382  // Store the max size for this block
1383  $this->_block_sizes[] = $written + $continue;
1384 
1385  // Not enough space to start the string in the current block
1386  $block_length -= $continue_limit - $space_remaining - $continue;
1387  $continue = 0;
1388 
1389  }
1390 
1391  // If the string (or substr) is small enough we can write it in the
1392  // new CONTINUE block. Else, go through the loop again to write it in
1393  // one or more CONTINUE blocks
1394  if ($block_length < $continue_limit) {
1395  $written = $block_length;
1396  } else {
1397  $written = 0;
1398  }
1399  }
1400  }
1401 
1402  // Store the max size for the last block unless it is empty
1403  if ($written + $continue) {
1404  $this->_block_sizes[] = $written + $continue;
1405  }
1406 
1407 
1408  /* Calculate the total length of the SST and associated CONTINUEs (if any).
1409  The SST record will have a length even if it contains no strings.
1410  This length is required to set the offsets in the BOUNDSHEET records since
1411  they must be written before the SST records
1412  */
1413 
1414  $tmp_block_sizes = array();
1415  $tmp_block_sizes = $this->_block_sizes;
1416 
1417  $length = 12;
1418  if (!empty($tmp_block_sizes)) {
1419  $length += array_shift($tmp_block_sizes); // SST
1420  }
1421  while (!empty($tmp_block_sizes)) {
1422  $length += 4 + array_shift($tmp_block_sizes); // CONTINUEs
1423  }
1424 
1425  return $length;
1426  }
+ Here is the caller graph for this function:

◆ _setPaletteXl97()

Spreadsheet_Excel_Writer_Workbook::_setPaletteXl97 ( )

Sets the colour palette to the Excel 97+ default.

private

Definition at line 421 of file Workbook.php.

Referenced by Spreadsheet_Excel_Writer_Workbook().

422  {
423  $this->_palette = array(
424  array(0x00, 0x00, 0x00, 0x00), // 8
425  array(0xff, 0xff, 0xff, 0x00), // 9
426  array(0xff, 0x00, 0x00, 0x00), // 10
427  array(0x00, 0xff, 0x00, 0x00), // 11
428  array(0x00, 0x00, 0xff, 0x00), // 12
429  array(0xff, 0xff, 0x00, 0x00), // 13
430  array(0xff, 0x00, 0xff, 0x00), // 14
431  array(0x00, 0xff, 0xff, 0x00), // 15
432  array(0x80, 0x00, 0x00, 0x00), // 16
433  array(0x00, 0x80, 0x00, 0x00), // 17
434  array(0x00, 0x00, 0x80, 0x00), // 18
435  array(0x80, 0x80, 0x00, 0x00), // 19
436  array(0x80, 0x00, 0x80, 0x00), // 20
437  array(0x00, 0x80, 0x80, 0x00), // 21
438  array(0xc0, 0xc0, 0xc0, 0x00), // 22
439  array(0x80, 0x80, 0x80, 0x00), // 23
440  array(0x99, 0x99, 0xff, 0x00), // 24
441  array(0x99, 0x33, 0x66, 0x00), // 25
442  array(0xff, 0xff, 0xcc, 0x00), // 26
443  array(0xcc, 0xff, 0xff, 0x00), // 27
444  array(0x66, 0x00, 0x66, 0x00), // 28
445  array(0xff, 0x80, 0x80, 0x00), // 29
446  array(0x00, 0x66, 0xcc, 0x00), // 30
447  array(0xcc, 0xcc, 0xff, 0x00), // 31
448  array(0x00, 0x00, 0x80, 0x00), // 32
449  array(0xff, 0x00, 0xff, 0x00), // 33
450  array(0xff, 0xff, 0x00, 0x00), // 34
451  array(0x00, 0xff, 0xff, 0x00), // 35
452  array(0x80, 0x00, 0x80, 0x00), // 36
453  array(0x80, 0x00, 0x00, 0x00), // 37
454  array(0x00, 0x80, 0x80, 0x00), // 38
455  array(0x00, 0x00, 0xff, 0x00), // 39
456  array(0x00, 0xcc, 0xff, 0x00), // 40
457  array(0xcc, 0xff, 0xff, 0x00), // 41
458  array(0xcc, 0xff, 0xcc, 0x00), // 42
459  array(0xff, 0xff, 0x99, 0x00), // 43
460  array(0x99, 0xcc, 0xff, 0x00), // 44
461  array(0xff, 0x99, 0xcc, 0x00), // 45
462  array(0xcc, 0x99, 0xff, 0x00), // 46
463  array(0xff, 0xcc, 0x99, 0x00), // 47
464  array(0x33, 0x66, 0xff, 0x00), // 48
465  array(0x33, 0xcc, 0xcc, 0x00), // 49
466  array(0x99, 0xcc, 0x00, 0x00), // 50
467  array(0xff, 0xcc, 0x00, 0x00), // 51
468  array(0xff, 0x99, 0x00, 0x00), // 52
469  array(0xff, 0x66, 0x00, 0x00), // 53
470  array(0x66, 0x66, 0x99, 0x00), // 54
471  array(0x96, 0x96, 0x96, 0x00), // 55
472  array(0x00, 0x33, 0x66, 0x00), // 56
473  array(0x33, 0x99, 0x66, 0x00), // 57
474  array(0x00, 0x33, 0x00, 0x00), // 58
475  array(0x33, 0x33, 0x00, 0x00), // 59
476  array(0x99, 0x33, 0x00, 0x00), // 60
477  array(0x99, 0x33, 0x66, 0x00), // 61
478  array(0x33, 0x33, 0x99, 0x00), // 62
479  array(0x33, 0x33, 0x33, 0x00), // 63
480  );
481  }
+ Here is the caller graph for this function:

◆ _storeAllFonts()

Spreadsheet_Excel_Writer_Workbook::_storeAllFonts ( )

Store the Excel FONT records.

private

Definition at line 645 of file Workbook.php.

References $_tmp_format, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeWorkbook().

646  {
647  // tmp_format is added by the constructor. We use this to write the default XF's
648  $format = $this->_tmp_format;
649  $font = $format->getFont();
650 
651  // Note: Fonts are 0-indexed. According to the SDK there is no index 4,
652  // so the following fonts are 0, 1, 2, 3, 5
653  //
654  for ($i = 1; $i <= 5; $i++){
655  $this->_append($font);
656  }
657 
658  // Iterate through the XF objects and write a FONT record if it isn't the
659  // same as the default FONT and if it hasn't already been used.
660  //
661  $fonts = array();
662  $index = 6; // The first user defined FONT
663 
664  $key = $format->getFontKey(); // The default font from _tmp_format
665  $fonts[$key] = 0; // Index of the default font
666 
667  $total_formats = count($this->_formats);
668  for ($i = 0; $i < $total_formats; $i++) {
669  $key = $this->_formats[$i]->getFontKey();
670  if (isset($fonts[$key])) {
671  // FONT has already been used
672  $this->_formats[$i]->font_index = $fonts[$key];
673  } else {
674  // Add a new FONT record
675  $fonts[$key] = $index;
676  $this->_formats[$i]->font_index = $index;
677  $index++;
678  $font = $this->_formats[$i]->getFont();
679  $this->_append($font);
680  }
681  }
682  }
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeAllNumFormats()

Spreadsheet_Excel_Writer_Workbook::_storeAllNumFormats ( )

Store user defined numerical formats i.e.

FORMAT records

private

Definition at line 689 of file Workbook.php.

References _storeNumFormat().

Referenced by _storeWorkbook().

690  {
691  // Leaning num_format syndrome
692  $hash_num_formats = array();
693  $num_formats = array();
694  $index = 164;
695 
696  // Iterate through the XF objects and write a FORMAT record if it isn't a
697  // built-in format type and if the FORMAT string hasn't already been used.
698  $total_formats = count($this->_formats);
699  for ($i = 0; $i < $total_formats; $i++) {
700  $num_format = $this->_formats[$i]->_num_format;
701 
702  // Check if $num_format is an index to a built-in format.
703  // Also check for a string of zeros, which is a valid format string
704  // but would evaluate to zero.
705  //
706  if (!preg_match("/^0+\d/", $num_format)) {
707  if (preg_match("/^\d+$/", $num_format)) { // built-in format
708  continue;
709  }
710  }
711 
712  if (isset($hash_num_formats[$num_format])) {
713  // FORMAT has already been used
714  $this->_formats[$i]->_num_format = $hash_num_formats[$num_format];
715  } else{
716  // Add a new FORMAT
717  $hash_num_formats[$num_format] = $index;
718  $this->_formats[$i]->_num_format = $index;
719  array_push($num_formats,$num_format);
720  $index++;
721  }
722  }
723 
724  // Write the new FORMAT records starting from 0xA4
725  $index = 164;
726  foreach ($num_formats as $num_format) {
727  $this->_storeNumFormat($num_format,$index);
728  $index++;
729  }
730  }
_storeNumFormat($format, $ifmt)
Writes Excel FORMAT record for non "built-in" numerical formats.
Definition: Workbook.php:1006
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeAllStyles()

Spreadsheet_Excel_Writer_Workbook::_storeAllStyles ( )

Write all STYLE records.

private

Definition at line 764 of file Workbook.php.

References _storeStyle().

Referenced by _storeWorkbook().

765  {
766  $this->_storeStyle();
767  }
_storeStyle()
Write Excel BIFF STYLE records.
Definition: Workbook.php:984
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeAllXfs()

Spreadsheet_Excel_Writer_Workbook::_storeAllXfs ( )

Write all XF records.

private

Definition at line 737 of file Workbook.php.

References $_tmp_format, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeWorkbook().

738  {
739  // _tmp_format is added by the constructor. We use this to write the default XF's
740  // The default font index is 0
741  //
742  $format = $this->_tmp_format;
743  for ($i = 0; $i <= 14; $i++) {
744  $xf = $format->getXf('style'); // Style XF
745  $this->_append($xf);
746  }
747 
748  $xf = $format->getXf('cell'); // Cell XF
749  $this->_append($xf);
750 
751  // User defined XFs
752  $total_formats = count($this->_formats);
753  for ($i = 0; $i < $total_formats; $i++) {
754  $xf = $this->_formats[$i]->getXf('cell');
755  $this->_append($xf);
756  }
757  }
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeBoundsheet()

Spreadsheet_Excel_Writer_Workbook::_storeBoundsheet (   $sheetname,
  $offset 
)

Writes Excel BIFF BOUNDSHEET record.

FIXME: inconsistent with BIFF documentation

Parameters
string$sheetnameWorksheet name
integer$offsetLocation of worksheet BOF private

Definition at line 921 of file Workbook.php.

References $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeWorkbook().

922  {
923  $record = 0x0085; // Record identifier
924  if ($this->_BIFF_version == 0x0600) {
925  $length = 0x08 + strlen($sheetname); // Number of bytes to follow
926  } else {
927  $length = 0x07 + strlen($sheetname); // Number of bytes to follow
928  }
929 
930  $grbit = 0x0000; // Visibility and sheet type
931  $cch = strlen($sheetname); // Length of sheet name
932 
933  $header = pack("vv", $record, $length);
934  if ($this->_BIFF_version == 0x0600) {
935  $data = pack("Vvv", $offset, $grbit, $cch);
936  } else {
937  $data = pack("VvC", $offset, $grbit, $cch);
938  }
939  $this->_append($header.$data.$sheetname);
940  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeCodepage()

Spreadsheet_Excel_Writer_Workbook::_storeCodepage ( )

Stores the CODEPAGE biff record.

private

Definition at line 871 of file Workbook.php.

References $_codepage, $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeWorkbook().

872  {
873  $record = 0x0042; // Record identifier
874  $length = 0x0002; // Number of bytes to follow
875  $cv = $this->_codepage; // The code page
876 
877  $header = pack('vv', $record, $length);
878  $data = pack('v', $cv);
879 
880  $this->_append($header . $data);
881  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeCountry()

Spreadsheet_Excel_Writer_Workbook::_storeCountry ( )

Stores the COUNTRY record for localization.

private

Definition at line 1247 of file Workbook.php.

References $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeWorkbook().

1248  {
1249  $record = 0x008C; // Record identifier
1250  $length = 4; // Number of bytes to follow
1251 
1252  $header = pack('vv', $record, $length);
1253  /* using the same country code always for simplicity */
1254  $data = pack('vv', $this->_country_code, $this->_country_code);
1255  $this->_append($header . $data);
1256  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeDatemode()

Spreadsheet_Excel_Writer_Workbook::_storeDatemode ( )

Write DATEMODE record to indicate the date system in use (1904 or 1900).

private

Definition at line 1033 of file Workbook.php.

References $_1904, $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeWorkbook().

1034  {
1035  $record = 0x0022; // Record identifier
1036  $length = 0x0002; // Bytes to follow
1037 
1038  $f1904 = $this->_1904; // Flag for 1904 date system
1039 
1040  $header = pack("vv", $record, $length);
1041  $data = pack("v", $f1904);
1042  $this->_append($header . $data);
1043  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeExterncount()

Spreadsheet_Excel_Writer_Workbook::_storeExterncount (   $cxals)

Write BIFF record EXTERNCOUNT to indicate the number of external sheet references in the workbook.

Excel only stores references to external sheets that are used in NAME. The workbook NAME record is required to define the print area and the repeat rows and columns.

A similar method is used in Worksheet.php for a slightly different purpose.

Parameters
integer$cxalsNumber of external references private

Definition at line 1059 of file Workbook.php.

References $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeExterns().

1060  {
1061  $record = 0x0016; // Record identifier
1062  $length = 0x0002; // Number of bytes to follow
1063 
1064  $header = pack("vv", $record, $length);
1065  $data = pack("v", $cxals);
1066  $this->_append($header . $data);
1067  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeExterns()

Spreadsheet_Excel_Writer_Workbook::_storeExterns ( )

Write the EXTERNCOUNT and EXTERNSHEET records.

These are used as indexes for the NAME records.

private

Definition at line 775 of file Workbook.php.

References _storeExterncount(), and _storeExternsheet().

Referenced by _storeWorkbook().

776  {
777  // Create EXTERNCOUNT with number of worksheets
778  $this->_storeExterncount(count($this->_worksheets));
779 
780  // Create EXTERNSHEET for each worksheet
781  foreach ($this->_sheetnames as $sheetname) {
782  $this->_storeExternsheet($sheetname);
783  }
784  }
_storeExternsheet($sheetname)
Writes the Excel BIFF EXTERNSHEET record.
Definition: Workbook.php:1080
_storeExterncount($cxals)
Write BIFF record EXTERNCOUNT to indicate the number of external sheet references in the workbook...
Definition: Workbook.php:1059
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeExternsheet()

Spreadsheet_Excel_Writer_Workbook::_storeExternsheet (   $sheetname)

Writes the Excel BIFF EXTERNSHEET record.

These references are used by formulas. NAME record is required to define the print area and the repeat rows and columns.

A similar method is used in Worksheet.php for a slightly different purpose.

Parameters
string$sheetnameWorksheet name private

Definition at line 1080 of file Workbook.php.

References $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeExterns().

1081  {
1082  $record = 0x0017; // Record identifier
1083  $length = 0x02 + strlen($sheetname); // Number of bytes to follow
1084 
1085  $cch = strlen($sheetname); // Length of sheet name
1086  $rgch = 0x03; // Filename encoding
1087 
1088  $header = pack("vv", $record, $length);
1089  $data = pack("CC", $cch, $rgch);
1090  $this->_append($header . $data . $sheetname);
1091  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeExternsheetBiff8()

Spreadsheet_Excel_Writer_Workbook::_storeExternsheetBiff8 ( )

Writes the Excel BIFF EXTERNSHEET record.

These references are used by formulas.

Parameters
string$sheetnameWorksheet name private

Definition at line 964 of file Workbook.php.

References $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

965  {
966  $total_references = count($this->_parser->_references);
967  $record = 0x0017; // Record identifier
968  $length = 2 + 6 * $total_references; // Number of bytes to follow
969 
970  $supbook_index = 0; // FIXME: only using internal SUPBOOK record
971  $header = pack("vv", $record, $length);
972  $data = pack('v', $total_references);
973  for ($i = 0; $i < $total_references; $i++) {
974  $data .= $this->_parser->_references[$i];
975  }
976  $this->_append($header . $data);
977  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:

◆ _storeNameLong()

Spreadsheet_Excel_Writer_Workbook::_storeNameLong (   $index,
  $type,
  $rowmin,
  $rowmax,
  $colmin,
  $colmax 
)

Store the NAME record in the long format that is used for storing the repeat rows and columns when both are specified.

This shares a lot of code with _storeNameShort() but we use a separate method to keep the code clean. Code abstraction for reuse can be carried too far, and I should know. ;-)

Parameters
integer$indexSheet index
integer$typeBuilt-in name type
integer$rowminStart row
integer$rowmaxEnd row
integer$colminStart colum
integer$colmaxEnd column private

Definition at line 1172 of file Workbook.php.

References $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeNames().

1173  {
1174  $record = 0x0018; // Record identifier
1175  $length = 0x003d; // Number of bytes to follow
1176  $grbit = 0x0020; // Option flags
1177  $chKey = 0x00; // Keyboard shortcut
1178  $cch = 0x01; // Length of text name
1179  $cce = 0x002e; // Length of text definition
1180  $ixals = $index + 1; // Sheet index
1181  $itab = $ixals; // Equal to ixals
1182  $cchCustMenu = 0x00; // Length of cust menu text
1183  $cchDescription = 0x00; // Length of description text
1184  $cchHelptopic = 0x00; // Length of help topic text
1185  $cchStatustext = 0x00; // Length of status bar text
1186  $rgch = $type; // Built-in name type
1187 
1188  $unknown01 = 0x29;
1189  $unknown02 = 0x002b;
1190  $unknown03 = 0x3b;
1191  $unknown04 = 0xffff-$index;
1192  $unknown05 = 0x0000;
1193  $unknown06 = 0x0000;
1194  $unknown07 = 0x1087;
1195  $unknown08 = 0x8008;
1196 
1197  $header = pack("vv", $record, $length);
1198  $data = pack("v", $grbit);
1199  $data .= pack("C", $chKey);
1200  $data .= pack("C", $cch);
1201  $data .= pack("v", $cce);
1202  $data .= pack("v", $ixals);
1203  $data .= pack("v", $itab);
1204  $data .= pack("C", $cchCustMenu);
1205  $data .= pack("C", $cchDescription);
1206  $data .= pack("C", $cchHelptopic);
1207  $data .= pack("C", $cchStatustext);
1208  $data .= pack("C", $rgch);
1209  $data .= pack("C", $unknown01);
1210  $data .= pack("v", $unknown02);
1211  // Column definition
1212  $data .= pack("C", $unknown03);
1213  $data .= pack("v", $unknown04);
1214  $data .= pack("v", $unknown05);
1215  $data .= pack("v", $unknown06);
1216  $data .= pack("v", $unknown07);
1217  $data .= pack("v", $unknown08);
1218  $data .= pack("v", $index);
1219  $data .= pack("v", $index);
1220  $data .= pack("v", 0x0000);
1221  $data .= pack("v", 0x3fff);
1222  $data .= pack("C", $colmin);
1223  $data .= pack("C", $colmax);
1224  // Row definition
1225  $data .= pack("C", $unknown03);
1226  $data .= pack("v", $unknown04);
1227  $data .= pack("v", $unknown05);
1228  $data .= pack("v", $unknown06);
1229  $data .= pack("v", $unknown07);
1230  $data .= pack("v", $unknown08);
1231  $data .= pack("v", $index);
1232  $data .= pack("v", $index);
1233  $data .= pack("v", $rowmin);
1234  $data .= pack("v", $rowmax);
1235  $data .= pack("C", 0x00);
1236  $data .= pack("C", 0xff);
1237  // End of data
1238  $data .= pack("C", 0x10);
1239  $this->_append($header . $data);
1240  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeNames()

Spreadsheet_Excel_Writer_Workbook::_storeNames ( )

Write the NAME record to define the print area and the repeat rows and cols.

private

Definition at line 791 of file Workbook.php.

References _storeNameLong(), and _storeNameShort().

Referenced by _storeWorkbook().

792  {
793  // Create the print area NAME records
794  $total_worksheets = count($this->_worksheets);
795  for ($i = 0; $i < $total_worksheets; $i++) {
796  // Write a Name record if the print area has been defined
797  if (isset($this->_worksheets[$i]->print_rowmin)) {
798  $this->_storeNameShort(
799  $this->_worksheets[$i]->index,
800  0x06, // NAME type
801  $this->_worksheets[$i]->print_rowmin,
802  $this->_worksheets[$i]->print_rowmax,
803  $this->_worksheets[$i]->print_colmin,
804  $this->_worksheets[$i]->print_colmax
805  );
806  }
807  }
808 
809  // Create the print title NAME records
810  $total_worksheets = count($this->_worksheets);
811  for ($i = 0; $i < $total_worksheets; $i++) {
812  $rowmin = $this->_worksheets[$i]->title_rowmin;
813  $rowmax = $this->_worksheets[$i]->title_rowmax;
814  $colmin = $this->_worksheets[$i]->title_colmin;
815  $colmax = $this->_worksheets[$i]->title_colmax;
816 
817  // Determine if row + col, row, col or nothing has been defined
818  // and write the appropriate record
819  //
820  if (isset($rowmin) && isset($colmin)) {
821  // Row and column titles have been defined.
822  // Row title has been defined.
823  $this->_storeNameLong(
824  $this->_worksheets[$i]->index,
825  0x07, // NAME type
826  $rowmin,
827  $rowmax,
828  $colmin,
829  $colmax
830  );
831  } elseif (isset($rowmin)) {
832  // Row title has been defined.
833  $this->_storeNameShort(
834  $this->_worksheets[$i]->index,
835  0x07, // NAME type
836  $rowmin,
837  $rowmax,
838  0x00,
839  0xff
840  );
841  } elseif (isset($colmin)) {
842  // Column title has been defined.
843  $this->_storeNameShort(
844  $this->_worksheets[$i]->index,
845  0x07, // NAME type
846  0x0000,
847  0x3fff,
848  $colmin,
849  $colmax
850  );
851  } else {
852  // Print title hasn't been defined.
853  }
854  }
855  }
_storeNameLong($index, $type, $rowmin, $rowmax, $colmin, $colmax)
Store the NAME record in the long format that is used for storing the repeat rows and columns when bo...
Definition: Workbook.php:1172
_storeNameShort($index, $type, $rowmin, $rowmax, $colmin, $colmax)
Store the NAME record in the short format that is used for storing the print area, repeat rows only and repeat columns only.
Definition: Workbook.php:1106
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeNameShort()

Spreadsheet_Excel_Writer_Workbook::_storeNameShort (   $index,
  $type,
  $rowmin,
  $rowmax,
  $colmin,
  $colmax 
)

Store the NAME record in the short format that is used for storing the print area, repeat rows only and repeat columns only.

Parameters
integer$indexSheet index
integer$typeBuilt-in name type
integer$rowminStart row
integer$rowmaxEnd row
integer$colminStart colum
integer$colmaxEnd column private

Definition at line 1106 of file Workbook.php.

References $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeNames().

1107  {
1108  $record = 0x0018; // Record identifier
1109  $length = 0x0024; // Number of bytes to follow
1110 
1111  $grbit = 0x0020; // Option flags
1112  $chKey = 0x00; // Keyboard shortcut
1113  $cch = 0x01; // Length of text name
1114  $cce = 0x0015; // Length of text definition
1115  $ixals = $index + 1; // Sheet index
1116  $itab = $ixals; // Equal to ixals
1117  $cchCustMenu = 0x00; // Length of cust menu text
1118  $cchDescription = 0x00; // Length of description text
1119  $cchHelptopic = 0x00; // Length of help topic text
1120  $cchStatustext = 0x00; // Length of status bar text
1121  $rgch = $type; // Built-in name type
1122 
1123  $unknown03 = 0x3b;
1124  $unknown04 = 0xffff-$index;
1125  $unknown05 = 0x0000;
1126  $unknown06 = 0x0000;
1127  $unknown07 = 0x1087;
1128  $unknown08 = 0x8005;
1129 
1130  $header = pack("vv", $record, $length);
1131  $data = pack("v", $grbit);
1132  $data .= pack("C", $chKey);
1133  $data .= pack("C", $cch);
1134  $data .= pack("v", $cce);
1135  $data .= pack("v", $ixals);
1136  $data .= pack("v", $itab);
1137  $data .= pack("C", $cchCustMenu);
1138  $data .= pack("C", $cchDescription);
1139  $data .= pack("C", $cchHelptopic);
1140  $data .= pack("C", $cchStatustext);
1141  $data .= pack("C", $rgch);
1142  $data .= pack("C", $unknown03);
1143  $data .= pack("v", $unknown04);
1144  $data .= pack("v", $unknown05);
1145  $data .= pack("v", $unknown06);
1146  $data .= pack("v", $unknown07);
1147  $data .= pack("v", $unknown08);
1148  $data .= pack("v", $index);
1149  $data .= pack("v", $index);
1150  $data .= pack("v", $rowmin);
1151  $data .= pack("v", $rowmax);
1152  $data .= pack("C", $colmin);
1153  $data .= pack("C", $colmax);
1154  $this->_append($header . $data);
1155  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeNumFormat()

Spreadsheet_Excel_Writer_Workbook::_storeNumFormat (   $format,
  $ifmt 
)

Writes Excel FORMAT record for non "built-in" numerical formats.

Parameters
string$formatCustom format string
integer$ifmtFormat index code private

Definition at line 1006 of file Workbook.php.

References $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeAllNumFormats().

1007  {
1008  $record = 0x041E; // Record identifier
1009 
1010  if ($this->_BIFF_version == 0x0600) {
1011  $length = 5 + strlen($format); // Number of bytes to follow
1012  $encoding = 0x0;
1013  } elseif ($this->_BIFF_version == 0x0500) {
1014  $length = 3 + strlen($format); // Number of bytes to follow
1015  }
1016 
1017  $cch = strlen($format); // Length of format string
1018 
1019  $header = pack("vv", $record, $length);
1020  if ($this->_BIFF_version == 0x0600) {
1021  $data = pack("vvC", $ifmt, $cch, $encoding);
1022  } elseif ($this->_BIFF_version == 0x0500) {
1023  $data = pack("vC", $ifmt, $cch);
1024  }
1025  $this->_append($header . $data . $format);
1026  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeOLEFile()

Spreadsheet_Excel_Writer_Workbook::_storeOLEFile ( )

Store the workbook in an OLE container.

private

Returns
mixed true on success. PEAR_Error on failure

Definition at line 566 of file Workbook.php.

References $res, OLE\Asc2Ucs(), PEAR\isError(), and PEAR\raiseError().

Referenced by _storeWorkbook().

567  {
568  if($this->_BIFF_version == 0x0600) {
569  $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Workbook'));
570  } else {
571  $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Book'));
572  }
573  if ($this->_tmp_dir != '') {
574  $OLE->setTempDir($this->_tmp_dir);
575  }
576  $res = $OLE->init();
577  if ($this->isError($res)) {
578  return $this->raiseError("OLE Error: ".$res->getMessage());
579  }
580  $OLE->append($this->_data);
581 
582  $total_worksheets = count($this->_worksheets);
583  for ($i = 0; $i < $total_worksheets; $i++) {
584  while ($tmp = $this->_worksheets[$i]->getData()) {
585  $OLE->append($tmp);
586  }
587  }
588 
589  $root = new OLE_PPS_Root(time(), time(), array($OLE));
590  if ($this->_tmp_dir != '') {
591  $root->setTempDir($this->_tmp_dir);
592  }
593 
594  $res = $root->save($this->_filename);
595  if ($this->isError($res)) {
596  return $this->raiseError("OLE Error: ".$res->getMessage());
597  }
598  return true;
599  }
Asc2Ucs($ascii)
Utility function to transform ASCII text to Unicode.
Definition: OLE.php:473
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storePalette()

Spreadsheet_Excel_Writer_Workbook::_storePalette ( )

Stores the PALETTE biff record.

private

Definition at line 1263 of file Workbook.php.

References $_palette, $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeWorkbook().

1264  {
1265  $aref = $this->_palette;
1266 
1267  $record = 0x0092; // Record identifier
1268  $length = 2 + 4 * count($aref); // Number of bytes to follow
1269  $ccv = count($aref); // Number of RGB values to follow
1270  $data = ''; // The RGB data
1271 
1272  // Pack the RGB data
1273  foreach ($aref as $color) {
1274  foreach ($color as $byte) {
1275  $data .= pack("C",$byte);
1276  }
1277  }
1278 
1279  $header = pack("vvv", $record, $length, $ccv);
1280  $this->_append($header . $data);
1281  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeSharedStringsTable()

Spreadsheet_Excel_Writer_Workbook::_storeSharedStringsTable ( )

Write all of the workbooks strings into an indexed array.

See the comments in _calculate_shared_string_sizes() for more information.

The Excel documentation says that the SST record should be followed by an EXTSST record. The EXTSST record is a hash table that is used to optimise access to SST. However, despite the documentation it doesn't seem to be required so we will ignore it.

private

Definition at line 1439 of file Workbook.php.

References $data, $total, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeWorkbook().

1440  {
1441  $record = 0x00fc; // Record identifier
1442  $length = 0x0008; // Number of bytes to follow
1443  $total = 0x0000;
1444 
1445  // Iterate through the strings to calculate the CONTINUE block sizes
1446  $continue_limit = 8208;
1447  $block_length = 0;
1448  $written = 0;
1449  $continue = 0;
1450 
1451  // sizes are upside down
1452  $tmp_block_sizes = $this->_block_sizes;
1453  // $tmp_block_sizes = array_reverse($this->_block_sizes);
1454 
1455  // The SST record is required even if it contains no strings. Thus we will
1456  // always have a length
1457  //
1458  if (!empty($tmp_block_sizes)) {
1459  $length = 8 + array_shift($tmp_block_sizes);
1460  }
1461  else {
1462  // No strings
1463  $length = 8;
1464  }
1465 
1466 
1467 
1468  // Write the SST block header information
1469  $header = pack("vv", $record, $length);
1470  $data = pack("VV", $this->_str_total, $this->_str_unique);
1471  $this->_append($header . $data);
1472 
1473 
1474 
1475 
1476  /* TODO: not good for performance */
1477  foreach (array_keys($this->_str_table) as $string) {
1478 
1479  $string_length = strlen($string);
1480  $headerinfo = unpack("vlength/Cencoding", $string);
1481  $encoding = $headerinfo["encoding"];
1482  $split_string = 0;
1483 
1484  // Block length is the total length of the strings that will be
1485  // written out in a single SST or CONTINUE block.
1486  //
1487  $block_length += $string_length;
1488 
1489 
1490  // We can write the string if it doesn't cross a CONTINUE boundary
1491  if ($block_length < $continue_limit) {
1492  $this->_append($string);
1493  $written += $string_length;
1494  continue;
1495  }
1496 
1497  // Deal with the cases where the next string to be written will exceed
1498  // the CONTINUE boundary. If the string is very long it may need to be
1499  // written in more than one CONTINUE record.
1500  //
1501  while ($block_length >= $continue_limit) {
1502 
1503  // We need to avoid the case where a string is continued in the first
1504  // n bytes that contain the string header information.
1505  //
1506  $header_length = 3; // Min string + header size -1
1507  $space_remaining = $continue_limit - $written - $continue;
1508 
1509 
1510  // Unicode data should only be split on char (2 byte) boundaries.
1511  // Therefore, in some cases we need to reduce the amount of available
1512  // space by 1 byte to ensure the correct alignment.
1513  $align = 0;
1514 
1515  // Only applies to Unicode strings
1516  if ($encoding == 1) {
1517  // Min string + header size -1
1518  $header_length = 4;
1519 
1520  if ($space_remaining > $header_length) {
1521  // String contains 3 byte header => split on odd boundary
1522  if (!$split_string && $space_remaining % 2 != 1) {
1523  $space_remaining--;
1524  $align = 1;
1525  }
1526  // Split section without header => split on even boundary
1527  else if ($split_string && $space_remaining % 2 == 1) {
1528  $space_remaining--;
1529  $align = 1;
1530  }
1531 
1532  $split_string = 1;
1533  }
1534  }
1535 
1536 
1537  if ($space_remaining > $header_length) {
1538  // Write as much as possible of the string in the current block
1539  $tmp = substr($string, 0, $space_remaining);
1540  $this->_append($tmp);
1541 
1542  // The remainder will be written in the next block(s)
1543  $string = substr($string, $space_remaining);
1544 
1545  // Reduce the current block length by the amount written
1546  $block_length -= $continue_limit - $continue - $align;
1547 
1548  // If the current string was split then the next CONTINUE block
1549  // should have the string continue flag (grbit) set unless the
1550  // split string fits exactly into the remaining space.
1551  //
1552  if ($block_length > 0) {
1553  $continue = 1;
1554  } else {
1555  $continue = 0;
1556  }
1557  } else {
1558  // Not enough space to start the string in the current block
1559  $block_length -= $continue_limit - $space_remaining - $continue;
1560  $continue = 0;
1561  }
1562 
1563  // Write the CONTINUE block header
1564  if (!empty($this->_block_sizes)) {
1565  $record = 0x003C;
1566  $length = array_shift($tmp_block_sizes);
1567 
1568  $header = pack('vv', $record, $length);
1569  if ($continue) {
1570  $header .= pack('C', $encoding);
1571  }
1572  $this->_append($header);
1573  }
1574 
1575  // If the string (or substr) is small enough we can write it in the
1576  // new CONTINUE block. Else, go through the loop again to write it in
1577  // one or more CONTINUE blocks
1578  //
1579  if ($block_length < $continue_limit) {
1580  $this->_append($string);
1581  $written = $block_length;
1582  } else {
1583  $written = 0;
1584  }
1585  }
1586  }
1587  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeStyle()

Spreadsheet_Excel_Writer_Workbook::_storeStyle ( )

Write Excel BIFF STYLE records.

private

Definition at line 984 of file Workbook.php.

References $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeAllStyles().

985  {
986  $record = 0x0293; // Record identifier
987  $length = 0x0004; // Bytes to follow
988 
989  $ixfe = 0x8000; // Index to style XF
990  $BuiltIn = 0x00; // Built-in style
991  $iLevel = 0xff; // Outline style level
992 
993  $header = pack("vv", $record, $length);
994  $data = pack("vCC", $ixfe, $BuiltIn, $iLevel);
995  $this->_append($header . $data);
996  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeSupbookInternal()

Spreadsheet_Excel_Writer_Workbook::_storeSupbookInternal ( )

Write Internal SUPBOOK record.

private

Definition at line 947 of file Workbook.php.

References $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

948  {
949  $record = 0x01AE; // Record identifier
950  $length = 0x0004; // Bytes to follow
951 
952  $header = pack("vv", $record, $length);
953  $data = pack("vv", count($this->_worksheets), 0x0104);
954  $this->_append($header . $data);
955  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:

◆ _storeWindow1()

Spreadsheet_Excel_Writer_Workbook::_storeWindow1 ( )

Write Excel BIFF WINDOW1 record.

private

Definition at line 888 of file Workbook.php.

References $_activesheet, $_firstsheet, $_selected, $data, and Spreadsheet_Excel_Writer_BIFFwriter\_append().

Referenced by _storeWorkbook().

889  {
890  $record = 0x003D; // Record identifier
891  $length = 0x0012; // Number of bytes to follow
892 
893  $xWn = 0x0000; // Horizontal position of window
894  $yWn = 0x0000; // Vertical position of window
895  $dxWn = 0x25BC; // Width of window
896  $dyWn = 0x1572; // Height of window
897 
898  $grbit = 0x0038; // Option flags
899  $ctabsel = $this->_selected; // Number of workbook tabs selected
900  $wTabRatio = 0x0258; // Tab to scrollbar ratio
901 
902  $itabFirst = $this->_firstsheet; // 1st displayed worksheet
903  $itabCur = $this->_activesheet; // Active worksheet
904 
905  $header = pack("vv", $record, $length);
906  $data = pack("vvvvvvvvv", $xWn, $yWn, $dxWn, $dyWn,
907  $grbit,
908  $itabCur, $itabFirst,
909  $ctabsel, $wTabRatio);
910  $this->_append($header . $data);
911  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_append($data)
General storage function.
Definition: BIFFwriter.php:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _storeWorkbook()

Spreadsheet_Excel_Writer_Workbook::_storeWorkbook ( )

Assemble worksheets into a workbook and send the BIFF data to an OLE storage.

private

Returns
mixed true on success. PEAR_Error on failure

Definition at line 490 of file Workbook.php.

References $res, _calcSheetOffsets(), _storeAllFonts(), _storeAllNumFormats(), _storeAllStyles(), _storeAllXfs(), Spreadsheet_Excel_Writer_BIFFwriter\_storeBof(), _storeBoundsheet(), _storeCodepage(), _storeCountry(), _storeDatemode(), Spreadsheet_Excel_Writer_BIFFwriter\_storeEof(), _storeExterns(), _storeNames(), _storeOLEFile(), _storePalette(), _storeSharedStringsTable(), _storeWindow1(), PEAR\isError(), and PEAR\raiseError().

Referenced by close().

491  {
492  if (count($this->_worksheets) == 0) {
493  return true;
494  }
495 
496  // Ensure that at least one worksheet has been selected.
497  if ($this->_activesheet == 0) {
498  $this->_worksheets[0]->selected = 1;
499  }
500 
501  // Calculate the number of selected worksheet tabs and call the finalization
502  // methods for each worksheet
503  $total_worksheets = count($this->_worksheets);
504  for ($i = 0; $i < $total_worksheets; $i++) {
505  if ($this->_worksheets[$i]->selected) {
506  $this->_selected++;
507  }
508  $this->_worksheets[$i]->close($this->_sheetnames);
509  }
510 
511  // Add Workbook globals
512  $this->_storeBof(0x0005);
513  $this->_storeCodepage();
514  if ($this->_BIFF_version == 0x0600) {
515  $this->_storeWindow1();
516  }
517  if ($this->_BIFF_version == 0x0500) {
518  $this->_storeExterns(); // For print area and repeat rows
519  }
520  $this->_storeNames(); // For print area and repeat rows
521  if ($this->_BIFF_version == 0x0500) {
522  $this->_storeWindow1();
523  }
524  $this->_storeDatemode();
525  $this->_storeAllFonts();
526  $this->_storeAllNumFormats();
527  $this->_storeAllXfs();
528  $this->_storeAllStyles();
529  $this->_storePalette();
530  $this->_calcSheetOffsets();
531 
532  // Add BOUNDSHEET records
533  for ($i = 0; $i < $total_worksheets; $i++) {
534  $this->_storeBoundsheet($this->_worksheets[$i]->name,$this->_worksheets[$i]->offset);
535  }
536 
537  if ($this->_country_code != -1) {
538  $this->_storeCountry();
539  }
540 
541  if ($this->_BIFF_version == 0x0600) {
542  //$this->_storeSupbookInternal();
543  /* TODO: store external SUPBOOK records and XCT and CRN records
544  in case of external references for BIFF8 */
545  //$this->_storeExternsheetBiff8();
546  $this->_storeSharedStringsTable();
547  }
548 
549  // End Workbook globals
550  $this->_storeEof();
551 
552  // Store the workbook in an OLE container
553  $res = $this->_storeOLEFile();
554  if ($this->isError($res)) {
555  return $this->raiseError($res->getMessage());
556  }
557  return true;
558  }
_storeBoundsheet($sheetname, $offset)
Writes Excel BIFF BOUNDSHEET record.
Definition: Workbook.php:921
_storeWindow1()
Write Excel BIFF WINDOW1 record.
Definition: Workbook.php:888
_storeCodepage()
Stores the CODEPAGE biff record.
Definition: Workbook.php:871
_storeSharedStringsTable()
Write all of the workbooks strings into an indexed array.
Definition: Workbook.php:1439
_storeOLEFile()
Store the workbook in an OLE container.
Definition: Workbook.php:566
_storeAllFonts()
Store the Excel FONT records.
Definition: Workbook.php:645
_storeEof()
Writes Excel EOF record to indicate the end of a BIFF stream.
Definition: BIFFwriter.php:199
_calcSheetOffsets()
Calculate offsets for Worksheet BOF records.
Definition: Workbook.php:606
_storeDatemode()
Write DATEMODE record to indicate the date system in use (1904 or 1900).
Definition: Workbook.php:1033
_storeAllXfs()
Write all XF records.
Definition: Workbook.php:737
_storeAllNumFormats()
Store user defined numerical formats i.e.
Definition: Workbook.php:689
_storeNames()
Write the NAME record to define the print area and the repeat rows and cols.
Definition: Workbook.php:791
_storeBof($type)
Writes Excel BOF record to indicate the beginning of a stream or sub-stream in the BIFF file...
Definition: BIFFwriter.php:170
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
_storePalette()
Stores the PALETTE biff record.
Definition: Workbook.php:1263
_storeCountry()
Stores the COUNTRY record for localization.
Definition: Workbook.php:1247
_storeExterns()
Write the EXTERNCOUNT and EXTERNSHEET records.
Definition: Workbook.php:775
_storeAllStyles()
Write all STYLE records.
Definition: Workbook.php:764
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addFormat()

& Spreadsheet_Excel_Writer_Workbook::addFormat (   $properties = array())

Add a new format to the Excel workbook.

Also, pass any properties to the Format constructor.

public

Parameters
array$propertiesarray with properties for initializing the format.
Returns
&Spreadsheet_Excel_Writer_Format reference to an Excel Format

Definition at line 356 of file Workbook.php.

Referenced by Spreadsheet_Excel_Writer_Workbook().

357  {
358  $format = new Spreadsheet_Excel_Writer_Format($this->_BIFF_version, $this->_xf_index, $properties);
359  $this->_xf_index += 1;
360  $this->_formats[] = &$format;
361  return $format;
362  }
+ Here is the caller graph for this function:

◆ addValidator()

& Spreadsheet_Excel_Writer_Workbook::addValidator ( )

Create new validator.

public

Returns
&Spreadsheet_Excel_Writer_Validator reference to a Validator

Definition at line 370 of file Workbook.php.

References $valid.

371  {
372  include_once 'Spreadsheet/Excel/Writer/Validator.php';
373  /* FIXME: check for successful inclusion*/
374  $valid = new Spreadsheet_Excel_Writer_Validator($this->_parser);
375  return $valid;
376  }
$valid

◆ addWorksheet()

& Spreadsheet_Excel_Writer_Workbook::addWorksheet (   $name = '')

Add a new worksheet to the Excel workbook.

If no name is given the name of the worksheet will be Sheeti$i, with $i in [1..].

public

Parameters
string$namethe optional name of the worksheet
Returns
mixed reference to a worksheet object on success, PEAR_Error on failure

Definition at line 310 of file Workbook.php.

References $_sheetname, and PEAR\raiseError().

311  {
312  $index = count($this->_worksheets);
313  $sheetname = $this->_sheetname;
314 
315  if ($name == '') {
316  $name = $sheetname.($index+1);
317  }
318 
319  // Check that sheetname is <= 31 chars (Excel limit before BIFF8).
320  if ($this->_BIFF_version != 0x0600)
321  {
322  if (strlen($name) > 31) {
323  return $this->raiseError("Sheetname $name must be <= 31 chars");
324  }
325  }
326 
327  // Check that the worksheet name doesn't already exist: a fatal Excel error.
328  $total_worksheets = count($this->_worksheets);
329  for ($i = 0; $i < $total_worksheets; $i++) {
330  if ($this->_worksheets[$i]->getName() == $name) {
331  return $this->raiseError("Worksheet '$name' already exists");
332  }
333  }
334 
335  $worksheet = new Spreadsheet_Excel_Writer_Worksheet($this->_BIFF_version,
336  $name, $index,
337  $this->_activesheet, $this->_firstsheet,
338  $this->_str_total, $this->_str_unique,
339  $this->_str_table, $this->_url_format,
340  $this->_parser, $this->_tmp_dir);
341 
342  $this->_worksheets[$index] = &$worksheet; // Store ref for iterator
343  $this->_sheetnames[$index] = $name; // Store EXTERNSHEET names
344  $this->_parser->setExtSheet($name, $index); // Register worksheet name with parser
345  return $worksheet;
346  }
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
+ Here is the call graph for this function:

◆ close()

Spreadsheet_Excel_Writer_Workbook::close ( )

Calls finalization methods.

This method should always be the last one to be called on every workbook

public

Returns
mixed true on success. PEAR_Error on failure

Definition at line 213 of file Workbook.php.

References $res, _storeWorkbook(), PEAR\isError(), and PEAR\raiseError().

214  {
215  if ($this->_fileclosed) { // Prevent close() from being called twice.
216  return true;
217  }
218  $res = $this->_storeWorkbook();
219  if ($this->isError($res)) {
220  return $this->raiseError($res->getMessage());
221  }
222  $this->_fileclosed = 1;
223  return true;
224  }
_storeWorkbook()
Assemble worksheets into a workbook and send the BIFF data to an OLE storage.
Definition: Workbook.php:490
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279
+ Here is the call graph for this function:

◆ setCountry()

Spreadsheet_Excel_Writer_Workbook::setCountry (   $code)

Set the country identifier for the workbook.

public

Parameters
integer$codeIs the international calling country code for the chosen country.

Definition at line 295 of file Workbook.php.

296  {
297  $this->_country_code = $code;
298  }

◆ setCustomColor()

Spreadsheet_Excel_Writer_Workbook::setCustomColor (   $index,
  $red,
  $green,
  $blue 
)

Change the RGB components of the elements in the colour palette.

public

Parameters
integer$indexcolour index
integer$redred RGB value [0-255]
integer$greengreen RGB value [0-255]
integer$blueblue RGB value [0-255]
Returns
integer The palette index for the custom color

Definition at line 388 of file Workbook.php.

References PEAR\raiseError().

389  {
390  // Match a HTML #xxyyzz style parameter
391  /*if (defined $_[1] and $_[1] =~ /^#(\w\w)(\w\w)(\w\w)/ ) {
392  @_ = ($_[0], hex $1, hex $2, hex $3);
393  }*/
394 
395  // Check that the colour index is the right range
396  if ($index < 8 or $index > 64) {
397  // TODO: assign real error codes
398  return $this->raiseError("Color index $index outside range: 8 <= index <= 64");
399  }
400 
401  // Check that the colour components are in the right range
402  if (($red < 0 or $red > 255) ||
403  ($green < 0 or $green > 255) ||
404  ($blue < 0 or $blue > 255))
405  {
406  return $this->raiseError("Color component outside range: 0 <= color <= 255");
407  }
408 
409  $index -= 8; // Adjust colour index (wingless dragonfly)
410 
411  // Set the RGB value
412  $this->_palette[$index] = array($red, $green, $blue, 0);
413  return($index + 8);
414  }
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
+ Here is the call graph for this function:

◆ setVersion()

Spreadsheet_Excel_Writer_Workbook::setVersion (   $version)

Sets the BIFF version.

This method exists just to access experimental functionality from BIFF8. It will be deprecated ! Only possible value is 8 (Excel 97/2000). For any other value it fails silently.

public

Parameters
integer$versionThe BIFF version

Definition at line 262 of file Workbook.php.

263  {
264  if ($version == 8) { // only accept version 8
265  $version = 0x0600;
266  $this->_BIFF_version = $version;
267  // change BIFFwriter limit for CONTINUE records
268  $this->_limit = 8228;
269  $this->_tmp_format->_BIFF_version = $version;
270  $this->_url_format->_BIFF_version = $version;
271  $this->_parser->_BIFF_version = $version;
272  $this->_codepage = 0x04B0;
273 
274  $total_worksheets = count($this->_worksheets);
275  // change version for all worksheets too
276  for ($i = 0; $i < $total_worksheets; $i++) {
277  $this->_worksheets[$i]->_BIFF_version = $version;
278  }
279 
280  $total_formats = count($this->_formats);
281  // change version for all formats too
282  for ($i = 0; $i < $total_formats; $i++) {
283  $this->_formats[$i]->_BIFF_version = $version;
284  }
285  }
286  }

◆ sheets()

Spreadsheet_Excel_Writer_Workbook::sheets ( )

An accessor for the _worksheets[] array Returns an array of the worksheet objects in a workbook It actually calls to worksheets()

public

See also
worksheets()
Returns
array

Definition at line 235 of file Workbook.php.

References worksheets().

236  {
237  return $this->worksheets();
238  }
worksheets()
An accessor for the _worksheets[] array.
Definition: Workbook.php:247
+ Here is the call graph for this function:

◆ Spreadsheet_Excel_Writer_Workbook()

Spreadsheet_Excel_Writer_Workbook::Spreadsheet_Excel_Writer_Workbook (   $filename)

Class constructor.

Parameters
stringfilename for storing the workbook. "-" for writing to stdout. public

Definition at line 174 of file Workbook.php.

References $filename, _setPaletteXl97(), addFormat(), and Spreadsheet_Excel_Writer_BIFFwriter\Spreadsheet_Excel_Writer_BIFFwriter().

Referenced by Spreadsheet_Excel_Writer\Spreadsheet_Excel_Writer().

175  {
176  // It needs to call its parent's constructor explicitly
178 
179  $this->_filename = $filename;
180  $this->_parser =& new Spreadsheet_Excel_Writer_Parser($this->_byte_order, $this->_BIFF_version);
181  $this->_1904 = 0;
182  $this->_activesheet = 0;
183  $this->_firstsheet = 0;
184  $this->_selected = 0;
185  $this->_xf_index = 16; // 15 style XF's and 1 cell XF.
186  $this->_fileclosed = 0;
187  $this->_biffsize = 0;
188  $this->_sheetname = 'Sheet';
189  $this->_tmp_format =& new Spreadsheet_Excel_Writer_Format($this->_BIFF_version);
190  $this->_worksheets = array();
191  $this->_sheetnames = array();
192  $this->_formats = array();
193  $this->_palette = array();
194  $this->_codepage = 0x04E4; // FIXME: should change for BIFF8
195  $this->_country_code = -1;
196  $this->_string_sizeinfo = 3;
197 
198  // Add the default format for hyperlinks
199  $this->_url_format =& $this->addFormat(array('color' => 'blue', 'underline' => 1));
200  $this->_str_total = 0;
201  $this->_str_unique = 0;
202  $this->_str_table = array();
203  $this->_setPaletteXl97();
204  }
_setPaletteXl97()
Sets the colour palette to the Excel 97+ default.
Definition: Workbook.php:421
$filename
Definition: buildRTE.php:89
& addFormat($properties=array())
Add a new format to the Excel workbook.
Definition: Workbook.php:356
Spreadsheet_Excel_Writer_BIFFwriter()
Constructor.
Definition: BIFFwriter.php:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ worksheets()

Spreadsheet_Excel_Writer_Workbook::worksheets ( )

An accessor for the _worksheets[] array.

Returns an array of the worksheet objects in a workbook

public

Returns
array

Definition at line 247 of file Workbook.php.

References $_worksheets.

Referenced by sheets().

248  {
249  return $this->_worksheets;
250  }
+ Here is the caller graph for this function:

Field Documentation

◆ $_1904

Spreadsheet_Excel_Writer_Workbook::$_1904

Definition at line 68 of file Workbook.php.

Referenced by _storeDatemode().

◆ $_activesheet

Spreadsheet_Excel_Writer_Workbook::$_activesheet

Definition at line 74 of file Workbook.php.

Referenced by _storeWindow1().

◆ $_biffsize

Spreadsheet_Excel_Writer_Workbook::$_biffsize

Definition at line 106 of file Workbook.php.

◆ $_codepage

Spreadsheet_Excel_Writer_Workbook::$_codepage

Definition at line 154 of file Workbook.php.

Referenced by _storeCodepage().

◆ $_country_code

Spreadsheet_Excel_Writer_Workbook::$_country_code

Definition at line 160 of file Workbook.php.

◆ $_fileclosed

Spreadsheet_Excel_Writer_Workbook::$_fileclosed

Definition at line 99 of file Workbook.php.

◆ $_filename

Spreadsheet_Excel_Writer_Workbook::$_filename

Definition at line 56 of file Workbook.php.

◆ $_firstsheet

Spreadsheet_Excel_Writer_Workbook::$_firstsheet

Definition at line 80 of file Workbook.php.

Referenced by _storeWindow1().

◆ $_formats

Spreadsheet_Excel_Writer_Workbook::$_formats

Definition at line 136 of file Workbook.php.

◆ $_palette

Spreadsheet_Excel_Writer_Workbook::$_palette

Definition at line 142 of file Workbook.php.

Referenced by _storePalette().

◆ $_parser

Spreadsheet_Excel_Writer_Workbook::$_parser

Definition at line 62 of file Workbook.php.

◆ $_selected

Spreadsheet_Excel_Writer_Workbook::$_selected

Definition at line 86 of file Workbook.php.

Referenced by _storeWindow1().

◆ $_sheetname

Spreadsheet_Excel_Writer_Workbook::$_sheetname

Definition at line 112 of file Workbook.php.

Referenced by addWorksheet().

◆ $_sheetnames

Spreadsheet_Excel_Writer_Workbook::$_sheetnames

Definition at line 130 of file Workbook.php.

◆ $_string_sizeinfo_size

Spreadsheet_Excel_Writer_Workbook::$_string_sizeinfo_size

Definition at line 166 of file Workbook.php.

◆ $_tmp_format

Spreadsheet_Excel_Writer_Workbook::$_tmp_format

Definition at line 118 of file Workbook.php.

Referenced by _storeAllFonts(), and _storeAllXfs().

◆ $_url_format

Spreadsheet_Excel_Writer_Workbook::$_url_format

Definition at line 148 of file Workbook.php.

◆ $_worksheets

Spreadsheet_Excel_Writer_Workbook::$_worksheets

Definition at line 124 of file Workbook.php.

Referenced by worksheets().

◆ $_xf_index

Spreadsheet_Excel_Writer_Workbook::$_xf_index

Definition at line 92 of file Workbook.php.


The documentation for this class was generated from the following file: