ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
PHPExcel_Writer_Excel5_Parser Class Reference
+ Collaboration diagram for PHPExcel_Writer_Excel5_Parser:

Public Member Functions

 __construct ()
 The class constructor. More...
 
 _initializeHashes ()
 Initialize the ptg and function hashes. More...
 
 _convert ($token)
 Convert a token to the proper ptg value. More...
 
 _convertNumber ($num)
 Convert a number token to ptgInt or ptgNum. More...
 
 _convertString ($string)
 Convert a string token to ptgStr. More...
 
 _convertFunction ($token, $num_args)
 Convert a function to a ptgFunc or ptgFuncVarV depending on the number of args that it takes. More...
 
 _convertRange2d ($range, $class=0)
 Convert an Excel range such as A1:D4 to a ptgRefV. More...
 
 _convertRange3d ($token)
 Convert an Excel 3d range such as "Sheet1!A1:D4" or "Sheet1:Sheet2!A1:D4" to a ptgArea3d. More...
 
 _convertRef2d ($cell)
 Convert an Excel reference such as A1, $B2, C$3 or $D$4 to a ptgRefV. More...
 
 _convertRef3d ($cell)
 Convert an Excel 3d reference such as "Sheet1!A1" or "Sheet1:Sheet2!A1" to a ptgRef3d. More...
 
 _convertError ($errorCode)
 Convert an error code to a ptgErr. More...
 
 _packExtRef ($ext_ref)
 Convert the sheet name part of an external reference, for example "Sheet1" or "Sheet1:Sheet2", to a packed structure. More...
 
 _getRefIndex ($ext_ref)
 Look up the REF index that corresponds to an external sheet name (or range). More...
 
 _getSheetIndex ($sheet_name)
 Look up the index that corresponds to an external sheet name. More...
 
 setExtSheet ($name, $index)
 This method is used to update the array of sheet names. More...
 
 _cellToPackedRowcol ($cell)
 pack() row and column into the required 3 or 4 byte format. More...
 
 _rangeToPackedRange ($range)
 pack() row range into the required 3 or 4 byte format. More...
 
 _cellToRowcol ($cell)
 Convert an Excel cell reference such as A1 or $B2 or C$3 or $D$4 to a zero indexed row and column number. More...
 
 _advance ()
 Advance to the next valid token. More...
 
 _match ($token)
 Checks if it's a valid token. More...
 
 parse ($formula)
 The parsing method. More...
 
 _condition ()
 It parses a condition. More...
 
 _expression ()
 It parses a expression. More...
 
 _parenthesizedExpression ()
 This function just introduces a ptgParen element in the tree, so that Excel doesn't get confused when working with a parenthesized formula afterwards. More...
 
 _term ()
 It parses a term. More...
 
 _fact ()
 It parses a factor. More...
 
 _func ()
 It parses a function call. More...
 
 _createTree ($value, $left, $right)
 Creates a tree. More...
 
 toReversePolish ($tree=array())
 Builds a string containing the tree in reverse polish notation (What you would use in a HP calculator stack). More...
 

Data Fields

const REGEX_SHEET_TITLE_UNQUOTED = '[^\*\:\/\\\\\?\[\]\+\-\% \\\'\^\&<>\=\,\;\#\(\)\"\{\}]+'
 Constants. More...
 
const REGEX_SHEET_TITLE_QUOTED = '(([^\*\:\/\\\\\?\[\]\\\'])+|(\\\'\\\')+)+'
 
 $_current_char
 
 $_current_token
 
 $_formula
 
 $_lookahead
 
 $_parse_tree
 
 $_ext_sheets
 
 $_references
 

Detailed Description

Definition at line 60 of file Parser.php.

Constructor & Destructor Documentation

◆ __construct()

PHPExcel_Writer_Excel5_Parser::__construct ( )

The class constructor.

Definition at line 122 of file Parser.php.

References _initializeHashes(), and array.

123  {
124  $this->_current_char = 0;
125  $this->_current_token = ''; // The token we are working on.
126  $this->_formula = ''; // The formula to parse.
127  $this->_lookahead = ''; // The character ahead of the current char.
128  $this->_parse_tree = ''; // The parse tree to be generated.
129  $this->_initializeHashes(); // Initialize the hashes: ptg's and function's ptg's
130  $this->_ext_sheets = array();
131  $this->_references = array();
132  }
_initializeHashes()
Initialize the ptg and function hashes.
Definition: Parser.php:139
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Member Function Documentation

◆ _advance()

PHPExcel_Writer_Excel5_Parser::_advance ( )

Advance to the next valid token.

private

Definition at line 1040 of file Parser.php.

References $_current_char, and _match().

Referenced by _condition(), _expression(), _fact(), _func(), _term(), and parse().

1041  {
1042  $i = $this->_current_char;
1043  $formula_length = strlen($this->_formula);
1044  // eat up white spaces
1045  if ($i < $formula_length) {
1046  while ($this->_formula{$i} == " ") {
1047  ++$i;
1048  }
1049 
1050  if ($i < ($formula_length - 1)) {
1051  $this->_lookahead = $this->_formula{$i+1};
1052  }
1053  $token = '';
1054  }
1055 
1056  while ($i < $formula_length) {
1057  $token .= $this->_formula{$i};
1058 
1059  if ($i < ($formula_length - 1)) {
1060  $this->_lookahead = $this->_formula{$i+1};
1061  } else {
1062  $this->_lookahead = '';
1063  }
1064 
1065  if ($this->_match($token) != '') {
1066  //if ($i < strlen($this->_formula) - 1) {
1067  // $this->_lookahead = $this->_formula{$i+1};
1068  //}
1069  $this->_current_char = $i + 1;
1070  $this->_current_token = $token;
1071  return 1;
1072  }
1073 
1074  if ($i < ($formula_length - 2)) {
1075  $this->_lookahead = $this->_formula{$i+2};
1076  } else { // if we run out of characters _lookahead becomes empty
1077  $this->_lookahead = '';
1078  }
1079  ++$i;
1080  }
1081  //die("Lexical error ".$this->_current_char);
1082  }
_match($token)
Checks if it&#39;s a valid token.
Definition: Parser.php:1091
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _cellToPackedRowcol()

PHPExcel_Writer_Excel5_Parser::_cellToPackedRowcol (   $cell)

pack() row and column into the required 3 or 4 byte format.

private

Parameters
string$cellThe Excel cell reference to be packed
Returns
array Array containing the row and column in packed() format

Definition at line 940 of file Parser.php.

References $row, _cellToRowcol(), and array.

Referenced by _convertRange2d(), _convertRange3d(), _convertRef2d(), and _convertRef3d().

941  {
942  $cell = strtoupper($cell);
943  list($row, $col, $row_rel, $col_rel) = $this->_cellToRowcol($cell);
944  if ($col >= 256) {
945  throw new PHPExcel_Writer_Exception("Column in: $cell greater than 255");
946  }
947  if ($row >= 65536) {
948  throw new PHPExcel_Writer_Exception("Row in: $cell greater than 65536 ");
949  }
950 
951  // Set the high bits to indicate if row or col are relative.
952  $col |= $col_rel << 14;
953  $col |= $row_rel << 15;
954  $col = pack('v', $col);
955 
956  $row = pack('v', $row);
957 
958  return array($row, $col);
959  }
Create styles array
The data for the language used.
_cellToRowcol($cell)
Convert an Excel cell reference such as A1 or $B2 or C$3 or $D$4 to a zero indexed row and column num...
Definition: Parser.php:1010
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _cellToRowcol()

PHPExcel_Writer_Excel5_Parser::_cellToRowcol (   $cell)

Convert an Excel cell reference such as A1 or $B2 or C$3 or $D$4 to a zero indexed row and column number.

Also returns two (0,1) values to indicate whether the row or column are relative references.

private

Parameters
string$cellThe Excel cell reference in A1 format.
Returns
array

Definition at line 1010 of file Parser.php.

References $row, and array.

Referenced by _cellToPackedRowcol().

1011  {
1012  preg_match('/(\$)?([A-I]?[A-Z])(\$)?(\d+)/',$cell,$match);
1013  // return absolute column if there is a $ in the ref
1014  $col_rel = empty($match[1]) ? 1 : 0;
1015  $col_ref = $match[2];
1016  $row_rel = empty($match[3]) ? 1 : 0;
1017  $row = $match[4];
1018 
1019  // Convert base26 column string to a number.
1020  $expn = strlen($col_ref) - 1;
1021  $col = 0;
1022  $col_ref_length = strlen($col_ref);
1023  for ($i = 0; $i < $col_ref_length; ++$i) {
1024  $col += (ord($col_ref{$i}) - 64) * pow(26, $expn);
1025  --$expn;
1026  }
1027 
1028  // Convert 1-index to zero-index
1029  --$row;
1030  --$col;
1031 
1032  return array($row, $col, $row_rel, $col_rel);
1033  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ _condition()

PHPExcel_Writer_Excel5_Parser::_condition ( )

It parses a condition.

It assumes the following rule: Cond -> Expr [(">" | "<") Expr]

private

Returns
mixed The parsed ptg'd tree on success

Definition at line 1221 of file Parser.php.

References $result, _advance(), _createTree(), and _expression().

Referenced by _func(), and parse().

1222  {
1223  $result = $this->_expression();
1224  if ($this->_current_token == "<") {
1225  $this->_advance();
1226  $result2 = $this->_expression();
1227  $result = $this->_createTree('ptgLT', $result, $result2);
1228  } elseif ($this->_current_token == ">") {
1229  $this->_advance();
1230  $result2 = $this->_expression();
1231  $result = $this->_createTree('ptgGT', $result, $result2);
1232  } elseif ($this->_current_token == "<=") {
1233  $this->_advance();
1234  $result2 = $this->_expression();
1235  $result = $this->_createTree('ptgLE', $result, $result2);
1236  } elseif ($this->_current_token == ">=") {
1237  $this->_advance();
1238  $result2 = $this->_expression();
1239  $result = $this->_createTree('ptgGE', $result, $result2);
1240  } elseif ($this->_current_token == "=") {
1241  $this->_advance();
1242  $result2 = $this->_expression();
1243  $result = $this->_createTree('ptgEQ', $result, $result2);
1244  } elseif ($this->_current_token == "<>") {
1245  $this->_advance();
1246  $result2 = $this->_expression();
1247  $result = $this->_createTree('ptgNE', $result, $result2);
1248  } elseif ($this->_current_token == "&") {
1249  $this->_advance();
1250  $result2 = $this->_expression();
1251  $result = $this->_createTree('ptgConcat', $result, $result2);
1252  }
1253  return $result;
1254  }
$result
_createTree($value, $left, $right)
Creates a tree.
Definition: Parser.php:1508
_expression()
It parses a expression.
Definition: Parser.php:1267
_advance()
Advance to the next valid token.
Definition: Parser.php:1040
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _convert()

PHPExcel_Writer_Excel5_Parser::_convert (   $token)

Convert a token to the proper ptg value.

private

Parameters
mixed$tokenThe token to convert.
Returns
mixed the converted token on success

Definition at line 515 of file Parser.php.

References _convertError(), _convertNumber(), _convertRange2d(), _convertRange3d(), _convertRef2d(), _convertRef3d(), and _convertString().

Referenced by toReversePolish().

516  {
517  if (preg_match("/\"([^\"]|\"\"){0,255}\"/", $token)) {
518  return $this->_convertString($token);
519 
520  } elseif (is_numeric($token)) {
521  return $this->_convertNumber($token);
522 
523  // match references like A1 or $A$1
524  } elseif (preg_match('/^\$?([A-Ia-i]?[A-Za-z])\$?(\d+)$/',$token)) {
525  return $this->_convertRef2d($token);
526 
527  // match external references like Sheet1!A1 or Sheet1:Sheet2!A1 or Sheet1!$A$1 or Sheet1:Sheet2!$A$1
528  } elseif (preg_match("/^" . self::REGEX_SHEET_TITLE_UNQUOTED . "(\:" . self::REGEX_SHEET_TITLE_UNQUOTED . ")?\!\\$?[A-Ia-i]?[A-Za-z]\\$?(\d+)$/u",$token)) {
529  return $this->_convertRef3d($token);
530 
531  // match external references like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1 or 'Sheet1'!$A$1 or 'Sheet1:Sheet2'!$A$1
532  } elseif (preg_match("/^'" . self::REGEX_SHEET_TITLE_QUOTED . "(\:" . self::REGEX_SHEET_TITLE_QUOTED . ")?'\!\\$?[A-Ia-i]?[A-Za-z]\\$?(\d+)$/u",$token)) {
533  return $this->_convertRef3d($token);
534 
535  // match ranges like A1:B2 or $A$1:$B$2
536  } elseif (preg_match('/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)\:(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/', $token)) {
537  return $this->_convertRange2d($token);
538 
539  // match external ranges like Sheet1!A1:B2 or Sheet1:Sheet2!A1:B2 or Sheet1!$A$1:$B$2 or Sheet1:Sheet2!$A$1:$B$2
540  } elseif (preg_match("/^" . self::REGEX_SHEET_TITLE_UNQUOTED . "(\:" . self::REGEX_SHEET_TITLE_UNQUOTED . ")?\!\\$?([A-Ia-i]?[A-Za-z])?\\$?(\d+)\:\\$?([A-Ia-i]?[A-Za-z])?\\$?(\d+)$/u",$token)) {
541  return $this->_convertRange3d($token);
542 
543  // match external ranges like 'Sheet1'!A1:B2 or 'Sheet1:Sheet2'!A1:B2 or 'Sheet1'!$A$1:$B$2 or 'Sheet1:Sheet2'!$A$1:$B$2
544  } elseif (preg_match("/^'" . self::REGEX_SHEET_TITLE_QUOTED . "(\:" . self::REGEX_SHEET_TITLE_QUOTED . ")?'\!\\$?([A-Ia-i]?[A-Za-z])?\\$?(\d+)\:\\$?([A-Ia-i]?[A-Za-z])?\\$?(\d+)$/u",$token)) {
545  return $this->_convertRange3d($token);
546 
547  // operators (including parentheses)
548  } elseif (isset($this->ptg[$token])) {
549  return pack("C", $this->ptg[$token]);
550 
551  // match error codes
552  } elseif (preg_match("/^#[A-Z0\/]{3,5}[!?]{1}$/", $token) or $token == '#N/A') {
553  return $this->_convertError($token);
554 
555  // commented so argument number can be processed correctly. See toReversePolish().
556  /*elseif (preg_match("/[A-Z0-9\xc0-\xdc\.]+/",$token))
557  {
558  return($this->_convertFunction($token,$this->_func_args));
559  }*/
560 
561  // if it's an argument, ignore the token (the argument remains)
562  } elseif ($token == 'arg') {
563  return '';
564  }
565 
566  // TODO: use real error codes
567  throw new PHPExcel_Writer_Exception("Unknown token $token");
568  }
_convertError($errorCode)
Convert an error code to a ptgErr.
Definition: Parser.php:782
_convertRange3d($token)
Convert an Excel 3d range such as "Sheet1!A1:D4" or "Sheet1:Sheet2!A1:D4" to a ptgArea3d.
Definition: Parser.php:676
_convertRange2d($range, $class=0)
Convert an Excel range such as A1:D4 to a ptgRefV.
Definition: Parser.php:638
_convertRef2d($cell)
Convert an Excel reference such as A1, $B2, C$3 or $D$4 to a ptgRefV.
Definition: Parser.php:718
_convertString($string)
Convert a string token to ptgStr.
Definition: Parser.php:596
_convertRef3d($cell)
Convert an Excel 3d reference such as "Sheet1!A1" or "Sheet1:Sheet2!A1" to a ptgRef3d.
Definition: Parser.php:748
_convertNumber($num)
Convert a number token to ptgInt or ptgNum.
Definition: Parser.php:576
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _convertError()

PHPExcel_Writer_Excel5_Parser::_convertError (   $errorCode)

Convert an error code to a ptgErr.

private

Parameters
string$errorCodeThe error code for conversion to its ptg value
Returns
string The error code ptgErr

Definition at line 782 of file Parser.php.

Referenced by _convert().

783  {
784  switch ($errorCode) {
785  case '#NULL!': return pack("C", 0x00);
786  case '#DIV/0!': return pack("C", 0x07);
787  case '#VALUE!': return pack("C", 0x0F);
788  case '#REF!': return pack("C", 0x17);
789  case '#NAME?': return pack("C", 0x1D);
790  case '#NUM!': return pack("C", 0x24);
791  case '#N/A': return pack("C", 0x2A);
792  }
793  return pack("C", 0xFF);
794  }
+ Here is the caller graph for this function:

◆ _convertFunction()

PHPExcel_Writer_Excel5_Parser::_convertFunction (   $token,
  $num_args 
)

Convert a function to a ptgFunc or ptgFuncVarV depending on the number of args that it takes.

private

Parameters
string$tokenThe name of the function for convertion to ptg value.
integer$num_argsThe number of arguments the function receives.
Returns
string The packed ptg for the function

Definition at line 616 of file Parser.php.

617  {
618  $args = $this->_functions[$token][1];
619 // $volatile = $this->_functions[$token][3];
620 
621  // Fixed number of args eg. TIME($i,$j,$k).
622  if ($args >= 0) {
623  return pack("Cv", $this->ptg['ptgFuncV'], $this->_functions[$token][0]);
624  }
625  // Variable number of args eg. SUM($i,$j,$k, ..).
626  if ($args == -1) {
627  return pack("CCv", $this->ptg['ptgFuncVarV'], $num_args, $this->_functions[$token][0]);
628  }
629  }

◆ _convertNumber()

PHPExcel_Writer_Excel5_Parser::_convertNumber (   $num)

Convert a number token to ptgInt or ptgNum.

private

Parameters
mixed$numan integer or double for conversion to its ptg value

Definition at line 576 of file Parser.php.

References PHPExcel_Writer_Excel5_BIFFwriter\getByteOrder().

Referenced by _convert().

577  {
578  // Integer in the range 0..2**16-1
579  if ((preg_match("/^\d+$/", $num)) and ($num <= 65535)) {
580  return pack("Cv", $this->ptg['ptgInt'], $num);
581  } else { // A float
582  if (PHPExcel_Writer_Excel5_BIFFwriter::getByteOrder()) { // if it's Big Endian
583  $num = strrev($num);
584  }
585  return pack("Cd", $this->ptg['ptgNum'], $num);
586  }
587  }
static getByteOrder()
Determine the byte order and store it as class data to avoid recalculating it for each call to new()...
Definition: BIFFwriter.php:113
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _convertRange2d()

PHPExcel_Writer_Excel5_Parser::_convertRange2d (   $range,
  $class = 0 
)

Convert an Excel range such as A1:D4 to a ptgRefV.

private

Parameters
string$rangeAn Excel range in the A1:A2
int$class

Definition at line 638 of file Parser.php.

References _cellToPackedRowcol().

Referenced by _convert().

639  {
640 
641  // TODO: possible class value 0,1,2 check Formula.pm
642  // Split the range into 2 cell refs
643  if (preg_match('/^(\$)?([A-Ia-i]?[A-Za-z])(\$)?(\d+)\:(\$)?([A-Ia-i]?[A-Za-z])(\$)?(\d+)$/', $range)) {
644  list($cell1, $cell2) = explode(':', $range);
645  } else {
646  // TODO: use real error codes
647  throw new PHPExcel_Writer_Exception("Unknown range separator");
648  }
649 
650  // Convert the cell references
651  list($row1, $col1) = $this->_cellToPackedRowcol($cell1);
652  list($row2, $col2) = $this->_cellToPackedRowcol($cell2);
653 
654  // The ptg value depends on the class of the ptg.
655  if ($class == 0) {
656  $ptgArea = pack("C", $this->ptg['ptgArea']);
657  } elseif ($class == 1) {
658  $ptgArea = pack("C", $this->ptg['ptgAreaV']);
659  } elseif ($class == 2) {
660  $ptgArea = pack("C", $this->ptg['ptgAreaA']);
661  } else {
662  // TODO: use real error codes
663  throw new PHPExcel_Writer_Exception("Unknown class $class");
664  }
665  return $ptgArea . $row1 . $row2 . $col1. $col2;
666  }
_cellToPackedRowcol($cell)
pack() row and column into the required 3 or 4 byte format.
Definition: Parser.php:940
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _convertRange3d()

PHPExcel_Writer_Excel5_Parser::_convertRange3d (   $token)

Convert an Excel 3d range such as "Sheet1!A1:D4" or "Sheet1:Sheet2!A1:D4" to a ptgArea3d.

private

Parameters
string$tokenAn Excel range in the Sheet1!A1:A2 format.
Returns
mixed The packed ptgArea3d token on success.

Definition at line 676 of file Parser.php.

References _cellToPackedRowcol(), _getRefIndex(), and _rangeToPackedRange().

Referenced by _convert().

677  {
678 // $class = 0; // formulas like Sheet1!$A$1:$A$2 in list type data validation need this class (0x3B)
679 
680  // Split the ref at the ! symbol
681  list($ext_ref, $range) = explode('!', $token);
682 
683  // Convert the external reference part (different for BIFF8)
684  $ext_ref = $this->_getRefIndex($ext_ref);
685 
686  // Split the range into 2 cell refs
687  list($cell1, $cell2) = explode(':', $range);
688 
689  // Convert the cell references
690  if (preg_match("/^(\\$)?[A-Ia-i]?[A-Za-z](\\$)?(\d+)$/", $cell1)) {
691  list($row1, $col1) = $this->_cellToPackedRowcol($cell1);
692  list($row2, $col2) = $this->_cellToPackedRowcol($cell2);
693  } else { // It's a rows range (like 26:27)
694  list($row1, $col1, $row2, $col2) = $this->_rangeToPackedRange($cell1.':'.$cell2);
695  }
696 
697  // The ptg value depends on the class of the ptg.
698 // if ($class == 0) {
699  $ptgArea = pack("C", $this->ptg['ptgArea3d']);
700 // } elseif ($class == 1) {
701 // $ptgArea = pack("C", $this->ptg['ptgArea3dV']);
702 // } elseif ($class == 2) {
703 // $ptgArea = pack("C", $this->ptg['ptgArea3dA']);
704 // } else {
705 // throw new PHPExcel_Writer_Exception("Unknown class $class");
706 // }
707 
708  return $ptgArea . $ext_ref . $row1 . $row2 . $col1. $col2;
709  }
_rangeToPackedRange($range)
pack() row range into the required 3 or 4 byte format.
Definition: Parser.php:969
_cellToPackedRowcol($cell)
pack() row and column into the required 3 or 4 byte format.
Definition: Parser.php:940
_getRefIndex($ext_ref)
Look up the REF index that corresponds to an external sheet name (or range).
Definition: Parser.php:849
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _convertRef2d()

PHPExcel_Writer_Excel5_Parser::_convertRef2d (   $cell)

Convert an Excel reference such as A1, $B2, C$3 or $D$4 to a ptgRefV.

private

Parameters
string$cellAn Excel cell reference
Returns
string The cell in packed() format with the corresponding ptg

Definition at line 718 of file Parser.php.

References $row, and _cellToPackedRowcol().

Referenced by _convert().

719  {
720 // $class = 2; // as far as I know, this is magick.
721 
722  // Convert the cell reference
723  $cell_array = $this->_cellToPackedRowcol($cell);
724  list($row, $col) = $cell_array;
725 
726  // The ptg value depends on the class of the ptg.
727 // if ($class == 0) {
728 // $ptgRef = pack("C", $this->ptg['ptgRef']);
729 // } elseif ($class == 1) {
730 // $ptgRef = pack("C", $this->ptg['ptgRefV']);
731 // } elseif ($class == 2) {
732  $ptgRef = pack("C", $this->ptg['ptgRefA']);
733 // } else {
734 // // TODO: use real error codes
735 // throw new PHPExcel_Writer_Exception("Unknown class $class");
736 // }
737  return $ptgRef.$row.$col;
738  }
_cellToPackedRowcol($cell)
pack() row and column into the required 3 or 4 byte format.
Definition: Parser.php:940
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _convertRef3d()

PHPExcel_Writer_Excel5_Parser::_convertRef3d (   $cell)

Convert an Excel 3d reference such as "Sheet1!A1" or "Sheet1:Sheet2!A1" to a ptgRef3d.

private

Parameters
string$cellAn Excel cell reference
Returns
mixed The packed ptgRef3d token on success.

Definition at line 748 of file Parser.php.

References $row, _cellToPackedRowcol(), and _getRefIndex().

Referenced by _convert().

749  {
750 // $class = 2; // as far as I know, this is magick.
751 
752  // Split the ref at the ! symbol
753  list($ext_ref, $cell) = explode('!', $cell);
754 
755  // Convert the external reference part (different for BIFF8)
756  $ext_ref = $this->_getRefIndex($ext_ref);
757 
758  // Convert the cell reference part
759  list($row, $col) = $this->_cellToPackedRowcol($cell);
760 
761  // The ptg value depends on the class of the ptg.
762 // if ($class == 0) {
763 // $ptgRef = pack("C", $this->ptg['ptgRef3d']);
764 // } elseif ($class == 1) {
765 // $ptgRef = pack("C", $this->ptg['ptgRef3dV']);
766 // } elseif ($class == 2) {
767  $ptgRef = pack("C", $this->ptg['ptgRef3dA']);
768 // } else {
769 // throw new PHPExcel_Writer_Exception("Unknown class $class");
770 // }
771 
772  return $ptgRef . $ext_ref. $row . $col;
773  }
_cellToPackedRowcol($cell)
pack() row and column into the required 3 or 4 byte format.
Definition: Parser.php:940
_getRefIndex($ext_ref)
Look up the REF index that corresponds to an external sheet name (or range).
Definition: Parser.php:849
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _convertString()

PHPExcel_Writer_Excel5_Parser::_convertString (   $string)

Convert a string token to ptgStr.

private

Parameters
string$stringA string for conversion to its ptg value.
Returns
mixed the converted token on success

Definition at line 596 of file Parser.php.

References PHPExcel_Shared_String\UTF8toBIFF8UnicodeShort().

Referenced by _convert().

597  {
598  // chop away beggining and ending quotes
599  $string = substr($string, 1, strlen($string) - 2);
600  if (strlen($string) > 255) {
601  throw new PHPExcel_Writer_Exception("String is too long");
602  }
603 
604  return pack('C', $this->ptg['ptgStr']) . PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($string);
605  }
static UTF8toBIFF8UnicodeShort($value, $arrcRuns=array())
Converts a UTF-8 string into BIFF8 Unicode string data (8-bit string length) Writes the string using ...
Definition: String.php:434
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _createTree()

PHPExcel_Writer_Excel5_Parser::_createTree (   $value,
  $left,
  $right 
)

Creates a tree.

In fact an array which may have one or two arrays (sub-trees) as elements.

private

Parameters
mixed$valueThe value of this node.
mixed$leftThe left array (sub-tree) or a final node.
mixed$rightThe right array (sub-tree) or a final node.
Returns
array A tree

Definition at line 1508 of file Parser.php.

References array.

Referenced by _condition(), _expression(), _fact(), _func(), _parenthesizedExpression(), and _term().

1509  {
1510  return array('value' => $value, 'left' => $left, 'right' => $right);
1511  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ _expression()

PHPExcel_Writer_Excel5_Parser::_expression ( )

It parses a expression.

It assumes the following rule: Expr -> Term [("+" | "-") Term] -> "string" -> "-" Term : Negative value -> "+" Term : Positive value -> Error code

private

Returns
mixed The parsed ptg'd tree on success

Definition at line 1267 of file Parser.php.

References $result, _advance(), _createTree(), and _term().

Referenced by _condition(), and _parenthesizedExpression().

1268  {
1269  // If it's a string return a string node
1270  if (preg_match("/\"([^\"]|\"\"){0,255}\"/", $this->_current_token)) {
1271  $tmp = str_replace('""', '"', $this->_current_token);
1272  if (($tmp == '"') || ($tmp == '')) $tmp = '""'; // Trap for "" that has been used for an empty string
1273  $result = $this->_createTree($tmp, '', '');
1274  $this->_advance();
1275  return $result;
1276  // If it's an error code
1277  } elseif (preg_match("/^#[A-Z0\/]{3,5}[!?]{1}$/", $this->_current_token) or $this->_current_token == '#N/A'){
1278  $result = $this->_createTree($this->_current_token, 'ptgErr', '');
1279  $this->_advance();
1280  return $result;
1281  // If it's a negative value
1282  } elseif ($this->_current_token == "-") {
1283  // catch "-" Term
1284  $this->_advance();
1285  $result2 = $this->_expression();
1286  $result = $this->_createTree('ptgUminus', $result2, '');
1287  return $result;
1288  // If it's a positive value
1289  } elseif ($this->_current_token == "+") {
1290  // catch "+" Term
1291  $this->_advance();
1292  $result2 = $this->_expression();
1293  $result = $this->_createTree('ptgUplus', $result2, '');
1294  return $result;
1295  }
1296  $result = $this->_term();
1297  while (($this->_current_token == "+") or
1298  ($this->_current_token == "-") or
1299  ($this->_current_token == "^")) {
1300 
1301  if ($this->_current_token == "+") {
1302  $this->_advance();
1303  $result2 = $this->_term();
1304  $result = $this->_createTree('ptgAdd', $result, $result2);
1305  } elseif ($this->_current_token == "-") {
1306  $this->_advance();
1307  $result2 = $this->_term();
1308  $result = $this->_createTree('ptgSub', $result, $result2);
1309  } else {
1310  $this->_advance();
1311  $result2 = $this->_term();
1312  $result = $this->_createTree('ptgPower', $result, $result2);
1313  }
1314  }
1315  return $result;
1316  }
$result
_term()
It parses a term.
Definition: Parser.php:1339
_createTree($value, $left, $right)
Creates a tree.
Definition: Parser.php:1508
_expression()
It parses a expression.
Definition: Parser.php:1267
_advance()
Advance to the next valid token.
Definition: Parser.php:1040
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _fact()

PHPExcel_Writer_Excel5_Parser::_fact ( )

It parses a factor.

It assumes the following rule: Fact -> ( Expr ) | CellRef | CellRange | Number | Function

private

Returns
mixed The parsed ptg'd tree on success

Definition at line 1369 of file Parser.php.

References $result, _advance(), _createTree(), _func(), and _parenthesizedExpression().

Referenced by _term().

1370  {
1371  if ($this->_current_token == "(") {
1372  $this->_advance(); // eat the "("
1373  $result = $this->_parenthesizedExpression();
1374  if ($this->_current_token != ")") {
1375  throw new PHPExcel_Writer_Exception("')' token expected.");
1376  }
1377  $this->_advance(); // eat the ")"
1378  return $result;
1379  }
1380  // if it's a reference
1381  if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$this->_current_token))
1382  {
1383  $result = $this->_createTree($this->_current_token, '', '');
1384  $this->_advance();
1385  return $result;
1386  }
1387  // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1 or Sheet1!$A$1 or Sheet1:Sheet2!$A$1)
1388  elseif (preg_match("/^" . self::REGEX_SHEET_TITLE_UNQUOTED . "(\:" . self::REGEX_SHEET_TITLE_UNQUOTED . ")?\!\\$?[A-Ia-i]?[A-Za-z]\\$?[0-9]+$/u",$this->_current_token))
1389  {
1390  $result = $this->_createTree($this->_current_token, '', '');
1391  $this->_advance();
1392  return $result;
1393  }
1394  // If it's an external reference ('Sheet1'!A1 or 'Sheet1:Sheet2'!A1 or 'Sheet1'!$A$1 or 'Sheet1:Sheet2'!$A$1)
1395  elseif (preg_match("/^'" . self::REGEX_SHEET_TITLE_QUOTED . "(\:" . self::REGEX_SHEET_TITLE_QUOTED . ")?'\!\\$?[A-Ia-i]?[A-Za-z]\\$?[0-9]+$/u",$this->_current_token))
1396  {
1397  $result = $this->_createTree($this->_current_token, '', '');
1398  $this->_advance();
1399  return $result;
1400  }
1401  // if it's a range A1:B2 or $A$1:$B$2
1402  elseif (preg_match('/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/',$this->_current_token) or
1403  preg_match('/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/',$this->_current_token))
1404  {
1405  // must be an error?
1406  $result = $this->_createTree($this->_current_token, '', '');
1407  $this->_advance();
1408  return $result;
1409  }
1410  // If it's an external range (Sheet1!A1:B2 or Sheet1:Sheet2!A1:B2 or Sheet1!$A$1:$B$2 or Sheet1:Sheet2!$A$1:$B$2)
1411  elseif (preg_match("/^" . self::REGEX_SHEET_TITLE_UNQUOTED . "(\:" . self::REGEX_SHEET_TITLE_UNQUOTED . ")?\!\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+:\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+$/u",$this->_current_token))
1412  {
1413  // must be an error?
1414  //$result = $this->_current_token;
1415  $result = $this->_createTree($this->_current_token, '', '');
1416  $this->_advance();
1417  return $result;
1418  }
1419  // If it's an external range ('Sheet1'!A1:B2 or 'Sheet1'!A1:B2 or 'Sheet1'!$A$1:$B$2 or 'Sheet1'!$A$1:$B$2)
1420  elseif (preg_match("/^'" . self::REGEX_SHEET_TITLE_QUOTED . "(\:" . self::REGEX_SHEET_TITLE_QUOTED . ")?'\!\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+:\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+$/u",$this->_current_token))
1421  {
1422  // must be an error?
1423  //$result = $this->_current_token;
1424  $result = $this->_createTree($this->_current_token, '', '');
1425  $this->_advance();
1426  return $result;
1427  }
1428  // If it's a number or a percent
1429  elseif (is_numeric($this->_current_token))
1430  {
1431  if($this->_lookahead == '%'){
1432  $result = $this->_createTree('ptgPercent', $this->_current_token, '');
1433  $this->_advance(); // Skip the percentage operator once we've pre-built that tree
1434  } else {
1435  $result = $this->_createTree($this->_current_token, '', '');
1436  }
1437  $this->_advance();
1438  return $result;
1439  }
1440  // if it's a function call
1441  elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$this->_current_token))
1442  {
1443  $result = $this->_func();
1444  return $result;
1445  }
1446  throw new PHPExcel_Writer_Exception("Syntax error: ".$this->_current_token.
1447  ", lookahead: ".$this->_lookahead.
1448  ", current char: ".$this->_current_char);
1449  }
$result
_createTree($value, $left, $right)
Creates a tree.
Definition: Parser.php:1508
_advance()
Advance to the next valid token.
Definition: Parser.php:1040
_parenthesizedExpression()
This function just introduces a ptgParen element in the tree, so that Excel doesn&#39;t get confused when...
Definition: Parser.php:1326
_func()
It parses a function call.
Definition: Parser.php:1458
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _func()

PHPExcel_Writer_Excel5_Parser::_func ( )

It parses a function call.

It assumes the following rule: Func -> ( Expr [,Expr]* )

private

Returns
mixed The parsed ptg'd tree on success

Definition at line 1458 of file Parser.php.

References $result, _advance(), _condition(), and _createTree().

Referenced by _fact().

1459  {
1460  $num_args = 0; // number of arguments received
1461  $function = strtoupper($this->_current_token);
1462  $result = ''; // initialize result
1463  $this->_advance();
1464  $this->_advance(); // eat the "("
1465  while ($this->_current_token != ')') {
1466 
1467  if ($num_args > 0) {
1468  if ($this->_current_token == "," or
1469  $this->_current_token == ";")
1470  {
1471  $this->_advance(); // eat the "," or ";"
1472  } else {
1473  throw new PHPExcel_Writer_Exception("Syntax error: comma expected in ".
1474  "function $function, arg #{$num_args}");
1475  }
1476  $result2 = $this->_condition();
1477  $result = $this->_createTree('arg', $result, $result2);
1478  } else { // first argument
1479  $result2 = $this->_condition();
1480  $result = $this->_createTree('arg', '', $result2);
1481  }
1482  ++$num_args;
1483  }
1484  if (!isset($this->_functions[$function])) {
1485  throw new PHPExcel_Writer_Exception("Function $function() doesn't exist");
1486  }
1487  $args = $this->_functions[$function][1];
1488  // If fixed number of args eg. TIME($i,$j,$k). Check that the number of args is valid.
1489  if (($args >= 0) and ($args != $num_args)) {
1490  throw new PHPExcel_Writer_Exception("Incorrect number of arguments in function $function() ");
1491  }
1492 
1493  $result = $this->_createTree($function, $result, $num_args);
1494  $this->_advance(); // eat the ")"
1495  return $result;
1496  }
_condition()
It parses a condition.
Definition: Parser.php:1221
$result
_createTree($value, $left, $right)
Creates a tree.
Definition: Parser.php:1508
_advance()
Advance to the next valid token.
Definition: Parser.php:1040
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getRefIndex()

PHPExcel_Writer_Excel5_Parser::_getRefIndex (   $ext_ref)

Look up the REF index that corresponds to an external sheet name (or range).

If it doesn't exist yet add it to the workbook's references array. It assumes all sheet names given must exist.

private

Parameters
string$ext_refThe name of the external reference
Returns
mixed The reference index in packed() format on success

Definition at line 849 of file Parser.php.

References _getSheetIndex(), and array.

Referenced by _convertRange3d(), and _convertRef3d().

850  {
851  $ext_ref = preg_replace("/^'/", '', $ext_ref); // Remove leading ' if any.
852  $ext_ref = preg_replace("/'$/", '', $ext_ref); // Remove trailing ' if any.
853  $ext_ref = str_replace('\'\'', '\'', $ext_ref); // Replace escaped '' with '
854 
855  // Check if there is a sheet range eg., Sheet1:Sheet2.
856  if (preg_match("/:/", $ext_ref)) {
857  list($sheet_name1, $sheet_name2) = explode(':', $ext_ref);
858 
859  $sheet1 = $this->_getSheetIndex($sheet_name1);
860  if ($sheet1 == -1) {
861  throw new PHPExcel_Writer_Exception("Unknown sheet name $sheet_name1 in formula");
862  }
863  $sheet2 = $this->_getSheetIndex($sheet_name2);
864  if ($sheet2 == -1) {
865  throw new PHPExcel_Writer_Exception("Unknown sheet name $sheet_name2 in formula");
866  }
867 
868  // Reverse max and min sheet numbers if necessary
869  if ($sheet1 > $sheet2) {
870  list($sheet1, $sheet2) = array($sheet2, $sheet1);
871  }
872  } else { // Single sheet name only.
873  $sheet1 = $this->_getSheetIndex($ext_ref);
874  if ($sheet1 == -1) {
875  throw new PHPExcel_Writer_Exception("Unknown sheet name $ext_ref in formula");
876  }
877  $sheet2 = $sheet1;
878  }
879 
880  // assume all references belong to this document
881  $supbook_index = 0x00;
882  $ref = pack('vvv', $supbook_index, $sheet1, $sheet2);
883  $total_references = count($this->_references);
884  $index = -1;
885  for ($i = 0; $i < $total_references; ++$i) {
886  if ($ref == $this->_references[$i]) {
887  $index = $i;
888  break;
889  }
890  }
891  // if REF was not found add it to references array
892  if ($index == -1) {
893  $this->_references[$total_references] = $ref;
894  $index = $total_references;
895  }
896 
897  return pack('v', $index);
898  }
_getSheetIndex($sheet_name)
Look up the index that corresponds to an external sheet name.
Definition: Parser.php:909
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getSheetIndex()

PHPExcel_Writer_Excel5_Parser::_getSheetIndex (   $sheet_name)

Look up the index that corresponds to an external sheet name.

The hash of sheet names is updated by the addworksheet() method of the PHPExcel_Writer_Excel5_Workbook class.

private

Parameters
string$sheet_nameSheet name
Returns
integer The sheet index, -1 if the sheet was not found

Definition at line 909 of file Parser.php.

Referenced by _getRefIndex(), and _packExtRef().

910  {
911  if (!isset($this->_ext_sheets[$sheet_name])) {
912  return -1;
913  } else {
914  return $this->_ext_sheets[$sheet_name];
915  }
916  }
+ Here is the caller graph for this function:

◆ _initializeHashes()

PHPExcel_Writer_Excel5_Parser::_initializeHashes ( )

Initialize the ptg and function hashes.

private

Definition at line 139 of file Parser.php.

References array.

Referenced by __construct().

140  {
141  // The Excel ptg indices
142  $this->ptg = array(
143  'ptgExp' => 0x01,
144  'ptgTbl' => 0x02,
145  'ptgAdd' => 0x03,
146  'ptgSub' => 0x04,
147  'ptgMul' => 0x05,
148  'ptgDiv' => 0x06,
149  'ptgPower' => 0x07,
150  'ptgConcat' => 0x08,
151  'ptgLT' => 0x09,
152  'ptgLE' => 0x0A,
153  'ptgEQ' => 0x0B,
154  'ptgGE' => 0x0C,
155  'ptgGT' => 0x0D,
156  'ptgNE' => 0x0E,
157  'ptgIsect' => 0x0F,
158  'ptgUnion' => 0x10,
159  'ptgRange' => 0x11,
160  'ptgUplus' => 0x12,
161  'ptgUminus' => 0x13,
162  'ptgPercent' => 0x14,
163  'ptgParen' => 0x15,
164  'ptgMissArg' => 0x16,
165  'ptgStr' => 0x17,
166  'ptgAttr' => 0x19,
167  'ptgSheet' => 0x1A,
168  'ptgEndSheet' => 0x1B,
169  'ptgErr' => 0x1C,
170  'ptgBool' => 0x1D,
171  'ptgInt' => 0x1E,
172  'ptgNum' => 0x1F,
173  'ptgArray' => 0x20,
174  'ptgFunc' => 0x21,
175  'ptgFuncVar' => 0x22,
176  'ptgName' => 0x23,
177  'ptgRef' => 0x24,
178  'ptgArea' => 0x25,
179  'ptgMemArea' => 0x26,
180  'ptgMemErr' => 0x27,
181  'ptgMemNoMem' => 0x28,
182  'ptgMemFunc' => 0x29,
183  'ptgRefErr' => 0x2A,
184  'ptgAreaErr' => 0x2B,
185  'ptgRefN' => 0x2C,
186  'ptgAreaN' => 0x2D,
187  'ptgMemAreaN' => 0x2E,
188  'ptgMemNoMemN' => 0x2F,
189  'ptgNameX' => 0x39,
190  'ptgRef3d' => 0x3A,
191  'ptgArea3d' => 0x3B,
192  'ptgRefErr3d' => 0x3C,
193  'ptgAreaErr3d' => 0x3D,
194  'ptgArrayV' => 0x40,
195  'ptgFuncV' => 0x41,
196  'ptgFuncVarV' => 0x42,
197  'ptgNameV' => 0x43,
198  'ptgRefV' => 0x44,
199  'ptgAreaV' => 0x45,
200  'ptgMemAreaV' => 0x46,
201  'ptgMemErrV' => 0x47,
202  'ptgMemNoMemV' => 0x48,
203  'ptgMemFuncV' => 0x49,
204  'ptgRefErrV' => 0x4A,
205  'ptgAreaErrV' => 0x4B,
206  'ptgRefNV' => 0x4C,
207  'ptgAreaNV' => 0x4D,
208  'ptgMemAreaNV' => 0x4E,
209  'ptgMemNoMemN' => 0x4F,
210  'ptgFuncCEV' => 0x58,
211  'ptgNameXV' => 0x59,
212  'ptgRef3dV' => 0x5A,
213  'ptgArea3dV' => 0x5B,
214  'ptgRefErr3dV' => 0x5C,
215  'ptgAreaErr3d' => 0x5D,
216  'ptgArrayA' => 0x60,
217  'ptgFuncA' => 0x61,
218  'ptgFuncVarA' => 0x62,
219  'ptgNameA' => 0x63,
220  'ptgRefA' => 0x64,
221  'ptgAreaA' => 0x65,
222  'ptgMemAreaA' => 0x66,
223  'ptgMemErrA' => 0x67,
224  'ptgMemNoMemA' => 0x68,
225  'ptgMemFuncA' => 0x69,
226  'ptgRefErrA' => 0x6A,
227  'ptgAreaErrA' => 0x6B,
228  'ptgRefNA' => 0x6C,
229  'ptgAreaNA' => 0x6D,
230  'ptgMemAreaNA' => 0x6E,
231  'ptgMemNoMemN' => 0x6F,
232  'ptgFuncCEA' => 0x78,
233  'ptgNameXA' => 0x79,
234  'ptgRef3dA' => 0x7A,
235  'ptgArea3dA' => 0x7B,
236  'ptgRefErr3dA' => 0x7C,
237  'ptgAreaErr3d' => 0x7D
238  );
239 
240  // Thanks to Michael Meeks and Gnumeric for the initial arg values.
241  //
242  // The following hash was generated by "function_locale.pl" in the distro.
243  // Refer to function_locale.pl for non-English function names.
244  //
245  // The array elements are as follow:
246  // ptg: The Excel function ptg code.
247  // args: The number of arguments that the function takes:
248  // >=0 is a fixed number of arguments.
249  // -1 is a variable number of arguments.
250  // class: The reference, value or array class of the function args.
251  // vol: The function is volatile.
252  //
253  $this->_functions = array(
254  // function ptg args class vol
255  'COUNT' => array( 0, -1, 0, 0 ),
256  'IF' => array( 1, -1, 1, 0 ),
257  'ISNA' => array( 2, 1, 1, 0 ),
258  'ISERROR' => array( 3, 1, 1, 0 ),
259  'SUM' => array( 4, -1, 0, 0 ),
260  'AVERAGE' => array( 5, -1, 0, 0 ),
261  'MIN' => array( 6, -1, 0, 0 ),
262  'MAX' => array( 7, -1, 0, 0 ),
263  'ROW' => array( 8, -1, 0, 0 ),
264  'COLUMN' => array( 9, -1, 0, 0 ),
265  'NA' => array( 10, 0, 0, 0 ),
266  'NPV' => array( 11, -1, 1, 0 ),
267  'STDEV' => array( 12, -1, 0, 0 ),
268  'DOLLAR' => array( 13, -1, 1, 0 ),
269  'FIXED' => array( 14, -1, 1, 0 ),
270  'SIN' => array( 15, 1, 1, 0 ),
271  'COS' => array( 16, 1, 1, 0 ),
272  'TAN' => array( 17, 1, 1, 0 ),
273  'ATAN' => array( 18, 1, 1, 0 ),
274  'PI' => array( 19, 0, 1, 0 ),
275  'SQRT' => array( 20, 1, 1, 0 ),
276  'EXP' => array( 21, 1, 1, 0 ),
277  'LN' => array( 22, 1, 1, 0 ),
278  'LOG10' => array( 23, 1, 1, 0 ),
279  'ABS' => array( 24, 1, 1, 0 ),
280  'INT' => array( 25, 1, 1, 0 ),
281  'SIGN' => array( 26, 1, 1, 0 ),
282  'ROUND' => array( 27, 2, 1, 0 ),
283  'LOOKUP' => array( 28, -1, 0, 0 ),
284  'INDEX' => array( 29, -1, 0, 1 ),
285  'REPT' => array( 30, 2, 1, 0 ),
286  'MID' => array( 31, 3, 1, 0 ),
287  'LEN' => array( 32, 1, 1, 0 ),
288  'VALUE' => array( 33, 1, 1, 0 ),
289  'TRUE' => array( 34, 0, 1, 0 ),
290  'FALSE' => array( 35, 0, 1, 0 ),
291  'AND' => array( 36, -1, 0, 0 ),
292  'OR' => array( 37, -1, 0, 0 ),
293  'NOT' => array( 38, 1, 1, 0 ),
294  'MOD' => array( 39, 2, 1, 0 ),
295  'DCOUNT' => array( 40, 3, 0, 0 ),
296  'DSUM' => array( 41, 3, 0, 0 ),
297  'DAVERAGE' => array( 42, 3, 0, 0 ),
298  'DMIN' => array( 43, 3, 0, 0 ),
299  'DMAX' => array( 44, 3, 0, 0 ),
300  'DSTDEV' => array( 45, 3, 0, 0 ),
301  'VAR' => array( 46, -1, 0, 0 ),
302  'DVAR' => array( 47, 3, 0, 0 ),
303  'TEXT' => array( 48, 2, 1, 0 ),
304  'LINEST' => array( 49, -1, 0, 0 ),
305  'TREND' => array( 50, -1, 0, 0 ),
306  'LOGEST' => array( 51, -1, 0, 0 ),
307  'GROWTH' => array( 52, -1, 0, 0 ),
308  'PV' => array( 56, -1, 1, 0 ),
309  'FV' => array( 57, -1, 1, 0 ),
310  'NPER' => array( 58, -1, 1, 0 ),
311  'PMT' => array( 59, -1, 1, 0 ),
312  'RATE' => array( 60, -1, 1, 0 ),
313  'MIRR' => array( 61, 3, 0, 0 ),
314  'IRR' => array( 62, -1, 0, 0 ),
315  'RAND' => array( 63, 0, 1, 1 ),
316  'MATCH' => array( 64, -1, 0, 0 ),
317  'DATE' => array( 65, 3, 1, 0 ),
318  'TIME' => array( 66, 3, 1, 0 ),
319  'DAY' => array( 67, 1, 1, 0 ),
320  'MONTH' => array( 68, 1, 1, 0 ),
321  'YEAR' => array( 69, 1, 1, 0 ),
322  'WEEKDAY' => array( 70, -1, 1, 0 ),
323  'HOUR' => array( 71, 1, 1, 0 ),
324  'MINUTE' => array( 72, 1, 1, 0 ),
325  'SECOND' => array( 73, 1, 1, 0 ),
326  'NOW' => array( 74, 0, 1, 1 ),
327  'AREAS' => array( 75, 1, 0, 1 ),
328  'ROWS' => array( 76, 1, 0, 1 ),
329  'COLUMNS' => array( 77, 1, 0, 1 ),
330  'OFFSET' => array( 78, -1, 0, 1 ),
331  'SEARCH' => array( 82, -1, 1, 0 ),
332  'TRANSPOSE' => array( 83, 1, 1, 0 ),
333  'TYPE' => array( 86, 1, 1, 0 ),
334  'ATAN2' => array( 97, 2, 1, 0 ),
335  'ASIN' => array( 98, 1, 1, 0 ),
336  'ACOS' => array( 99, 1, 1, 0 ),
337  'CHOOSE' => array( 100, -1, 1, 0 ),
338  'HLOOKUP' => array( 101, -1, 0, 0 ),
339  'VLOOKUP' => array( 102, -1, 0, 0 ),
340  'ISREF' => array( 105, 1, 0, 0 ),
341  'LOG' => array( 109, -1, 1, 0 ),
342  'CHAR' => array( 111, 1, 1, 0 ),
343  'LOWER' => array( 112, 1, 1, 0 ),
344  'UPPER' => array( 113, 1, 1, 0 ),
345  'PROPER' => array( 114, 1, 1, 0 ),
346  'LEFT' => array( 115, -1, 1, 0 ),
347  'RIGHT' => array( 116, -1, 1, 0 ),
348  'EXACT' => array( 117, 2, 1, 0 ),
349  'TRIM' => array( 118, 1, 1, 0 ),
350  'REPLACE' => array( 119, 4, 1, 0 ),
351  'SUBSTITUTE' => array( 120, -1, 1, 0 ),
352  'CODE' => array( 121, 1, 1, 0 ),
353  'FIND' => array( 124, -1, 1, 0 ),
354  'CELL' => array( 125, -1, 0, 1 ),
355  'ISERR' => array( 126, 1, 1, 0 ),
356  'ISTEXT' => array( 127, 1, 1, 0 ),
357  'ISNUMBER' => array( 128, 1, 1, 0 ),
358  'ISBLANK' => array( 129, 1, 1, 0 ),
359  'T' => array( 130, 1, 0, 0 ),
360  'N' => array( 131, 1, 0, 0 ),
361  'DATEVALUE' => array( 140, 1, 1, 0 ),
362  'TIMEVALUE' => array( 141, 1, 1, 0 ),
363  'SLN' => array( 142, 3, 1, 0 ),
364  'SYD' => array( 143, 4, 1, 0 ),
365  'DDB' => array( 144, -1, 1, 0 ),
366  'INDIRECT' => array( 148, -1, 1, 1 ),
367  'CALL' => array( 150, -1, 1, 0 ),
368  'CLEAN' => array( 162, 1, 1, 0 ),
369  'MDETERM' => array( 163, 1, 2, 0 ),
370  'MINVERSE' => array( 164, 1, 2, 0 ),
371  'MMULT' => array( 165, 2, 2, 0 ),
372  'IPMT' => array( 167, -1, 1, 0 ),
373  'PPMT' => array( 168, -1, 1, 0 ),
374  'COUNTA' => array( 169, -1, 0, 0 ),
375  'PRODUCT' => array( 183, -1, 0, 0 ),
376  'FACT' => array( 184, 1, 1, 0 ),
377  'DPRODUCT' => array( 189, 3, 0, 0 ),
378  'ISNONTEXT' => array( 190, 1, 1, 0 ),
379  'STDEVP' => array( 193, -1, 0, 0 ),
380  'VARP' => array( 194, -1, 0, 0 ),
381  'DSTDEVP' => array( 195, 3, 0, 0 ),
382  'DVARP' => array( 196, 3, 0, 0 ),
383  'TRUNC' => array( 197, -1, 1, 0 ),
384  'ISLOGICAL' => array( 198, 1, 1, 0 ),
385  'DCOUNTA' => array( 199, 3, 0, 0 ),
386  'USDOLLAR' => array( 204, -1, 1, 0 ),
387  'FINDB' => array( 205, -1, 1, 0 ),
388  'SEARCHB' => array( 206, -1, 1, 0 ),
389  'REPLACEB' => array( 207, 4, 1, 0 ),
390  'LEFTB' => array( 208, -1, 1, 0 ),
391  'RIGHTB' => array( 209, -1, 1, 0 ),
392  'MIDB' => array( 210, 3, 1, 0 ),
393  'LENB' => array( 211, 1, 1, 0 ),
394  'ROUNDUP' => array( 212, 2, 1, 0 ),
395  'ROUNDDOWN' => array( 213, 2, 1, 0 ),
396  'ASC' => array( 214, 1, 1, 0 ),
397  'DBCS' => array( 215, 1, 1, 0 ),
398  'RANK' => array( 216, -1, 0, 0 ),
399  'ADDRESS' => array( 219, -1, 1, 0 ),
400  'DAYS360' => array( 220, -1, 1, 0 ),
401  'TODAY' => array( 221, 0, 1, 1 ),
402  'VDB' => array( 222, -1, 1, 0 ),
403  'MEDIAN' => array( 227, -1, 0, 0 ),
404  'SUMPRODUCT' => array( 228, -1, 2, 0 ),
405  'SINH' => array( 229, 1, 1, 0 ),
406  'COSH' => array( 230, 1, 1, 0 ),
407  'TANH' => array( 231, 1, 1, 0 ),
408  'ASINH' => array( 232, 1, 1, 0 ),
409  'ACOSH' => array( 233, 1, 1, 0 ),
410  'ATANH' => array( 234, 1, 1, 0 ),
411  'DGET' => array( 235, 3, 0, 0 ),
412  'INFO' => array( 244, 1, 1, 1 ),
413  'DB' => array( 247, -1, 1, 0 ),
414  'FREQUENCY' => array( 252, 2, 0, 0 ),
415  'ERROR.TYPE' => array( 261, 1, 1, 0 ),
416  'REGISTER.ID' => array( 267, -1, 1, 0 ),
417  'AVEDEV' => array( 269, -1, 0, 0 ),
418  'BETADIST' => array( 270, -1, 1, 0 ),
419  'GAMMALN' => array( 271, 1, 1, 0 ),
420  'BETAINV' => array( 272, -1, 1, 0 ),
421  'BINOMDIST' => array( 273, 4, 1, 0 ),
422  'CHIDIST' => array( 274, 2, 1, 0 ),
423  'CHIINV' => array( 275, 2, 1, 0 ),
424  'COMBIN' => array( 276, 2, 1, 0 ),
425  'CONFIDENCE' => array( 277, 3, 1, 0 ),
426  'CRITBINOM' => array( 278, 3, 1, 0 ),
427  'EVEN' => array( 279, 1, 1, 0 ),
428  'EXPONDIST' => array( 280, 3, 1, 0 ),
429  'FDIST' => array( 281, 3, 1, 0 ),
430  'FINV' => array( 282, 3, 1, 0 ),
431  'FISHER' => array( 283, 1, 1, 0 ),
432  'FISHERINV' => array( 284, 1, 1, 0 ),
433  'FLOOR' => array( 285, 2, 1, 0 ),
434  'GAMMADIST' => array( 286, 4, 1, 0 ),
435  'GAMMAINV' => array( 287, 3, 1, 0 ),
436  'CEILING' => array( 288, 2, 1, 0 ),
437  'HYPGEOMDIST' => array( 289, 4, 1, 0 ),
438  'LOGNORMDIST' => array( 290, 3, 1, 0 ),
439  'LOGINV' => array( 291, 3, 1, 0 ),
440  'NEGBINOMDIST' => array( 292, 3, 1, 0 ),
441  'NORMDIST' => array( 293, 4, 1, 0 ),
442  'NORMSDIST' => array( 294, 1, 1, 0 ),
443  'NORMINV' => array( 295, 3, 1, 0 ),
444  'NORMSINV' => array( 296, 1, 1, 0 ),
445  'STANDARDIZE' => array( 297, 3, 1, 0 ),
446  'ODD' => array( 298, 1, 1, 0 ),
447  'PERMUT' => array( 299, 2, 1, 0 ),
448  'POISSON' => array( 300, 3, 1, 0 ),
449  'TDIST' => array( 301, 3, 1, 0 ),
450  'WEIBULL' => array( 302, 4, 1, 0 ),
451  'SUMXMY2' => array( 303, 2, 2, 0 ),
452  'SUMX2MY2' => array( 304, 2, 2, 0 ),
453  'SUMX2PY2' => array( 305, 2, 2, 0 ),
454  'CHITEST' => array( 306, 2, 2, 0 ),
455  'CORREL' => array( 307, 2, 2, 0 ),
456  'COVAR' => array( 308, 2, 2, 0 ),
457  'FORECAST' => array( 309, 3, 2, 0 ),
458  'FTEST' => array( 310, 2, 2, 0 ),
459  'INTERCEPT' => array( 311, 2, 2, 0 ),
460  'PEARSON' => array( 312, 2, 2, 0 ),
461  'RSQ' => array( 313, 2, 2, 0 ),
462  'STEYX' => array( 314, 2, 2, 0 ),
463  'SLOPE' => array( 315, 2, 2, 0 ),
464  'TTEST' => array( 316, 4, 2, 0 ),
465  'PROB' => array( 317, -1, 2, 0 ),
466  'DEVSQ' => array( 318, -1, 0, 0 ),
467  'GEOMEAN' => array( 319, -1, 0, 0 ),
468  'HARMEAN' => array( 320, -1, 0, 0 ),
469  'SUMSQ' => array( 321, -1, 0, 0 ),
470  'KURT' => array( 322, -1, 0, 0 ),
471  'SKEW' => array( 323, -1, 0, 0 ),
472  'ZTEST' => array( 324, -1, 0, 0 ),
473  'LARGE' => array( 325, 2, 0, 0 ),
474  'SMALL' => array( 326, 2, 0, 0 ),
475  'QUARTILE' => array( 327, 2, 0, 0 ),
476  'PERCENTILE' => array( 328, 2, 0, 0 ),
477  'PERCENTRANK' => array( 329, -1, 0, 0 ),
478  'MODE' => array( 330, -1, 2, 0 ),
479  'TRIMMEAN' => array( 331, 2, 0, 0 ),
480  'TINV' => array( 332, 2, 1, 0 ),
481  'CONCATENATE' => array( 336, -1, 1, 0 ),
482  'POWER' => array( 337, 2, 1, 0 ),
483  'RADIANS' => array( 342, 1, 1, 0 ),
484  'DEGREES' => array( 343, 1, 1, 0 ),
485  'SUBTOTAL' => array( 344, -1, 0, 0 ),
486  'SUMIF' => array( 345, -1, 0, 0 ),
487  'COUNTIF' => array( 346, 2, 0, 0 ),
488  'COUNTBLANK' => array( 347, 1, 0, 0 ),
489  'ISPMT' => array( 350, 4, 1, 0 ),
490  'DATEDIF' => array( 351, 3, 1, 0 ),
491  'DATESTRING' => array( 352, 1, 1, 0 ),
492  'NUMBERSTRING' => array( 353, 2, 1, 0 ),
493  'ROMAN' => array( 354, -1, 1, 0 ),
494  'GETPIVOTDATA' => array( 358, -1, 0, 0 ),
495  'HYPERLINK' => array( 359, -1, 1, 0 ),
496  'PHONETIC' => array( 360, 1, 0, 0 ),
497  'AVERAGEA' => array( 361, -1, 0, 0 ),
498  'MAXA' => array( 362, -1, 0, 0 ),
499  'MINA' => array( 363, -1, 0, 0 ),
500  'STDEVPA' => array( 364, -1, 0, 0 ),
501  'VARPA' => array( 365, -1, 0, 0 ),
502  'STDEVA' => array( 366, -1, 0, 0 ),
503  'VARA' => array( 367, -1, 0, 0 ),
504  'BAHTTEXT' => array( 368, 1, 0, 0 ),
505  );
506  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ _match()

PHPExcel_Writer_Excel5_Parser::_match (   $token)

Checks if it's a valid token.

private

Parameters
mixed$tokenThe token to check.
Returns
mixed The checked token or false on failure

Definition at line 1091 of file Parser.php.

Referenced by _advance().

1092  {
1093  switch($token) {
1094  case "+":
1095  case "-":
1096  case "*":
1097  case "/":
1098  case "(":
1099  case ")":
1100  case ",":
1101  case ";":
1102  case ">=":
1103  case "<=":
1104  case "=":
1105  case "<>":
1106  case "^":
1107  case "&":
1108  case "%":
1109  return $token;
1110  break;
1111  case ">":
1112  if ($this->_lookahead == '=') { // it's a GE token
1113  break;
1114  }
1115  return $token;
1116  break;
1117  case "<":
1118  // it's a LE or a NE token
1119  if (($this->_lookahead == '=') or ($this->_lookahead == '>')) {
1120  break;
1121  }
1122  return $token;
1123  break;
1124  default:
1125  // if it's a reference A1 or $A$1 or $A1 or A$1
1126  if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$token) and
1127  !preg_match("/[0-9]/",$this->_lookahead) and
1128  ($this->_lookahead != ':') and ($this->_lookahead != '.') and
1129  ($this->_lookahead != '!'))
1130  {
1131  return $token;
1132  }
1133  // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1 or Sheet1!$A$1 or Sheet1:Sheet2!$A$1)
1134  elseif (preg_match("/^" . self::REGEX_SHEET_TITLE_UNQUOTED . "(\:" . self::REGEX_SHEET_TITLE_UNQUOTED . ")?\!\\$?[A-Ia-i]?[A-Za-z]\\$?[0-9]+$/u",$token) and
1135  !preg_match("/[0-9]/",$this->_lookahead) and
1136  ($this->_lookahead != ':') and ($this->_lookahead != '.'))
1137  {
1138  return $token;
1139  }
1140  // If it's an external reference ('Sheet1'!A1 or 'Sheet1:Sheet2'!A1 or 'Sheet1'!$A$1 or 'Sheet1:Sheet2'!$A$1)
1141  elseif (preg_match("/^'" . self::REGEX_SHEET_TITLE_QUOTED . "(\:" . self::REGEX_SHEET_TITLE_QUOTED . ")?'\!\\$?[A-Ia-i]?[A-Za-z]\\$?[0-9]+$/u",$token) and
1142  !preg_match("/[0-9]/",$this->_lookahead) and
1143  ($this->_lookahead != ':') and ($this->_lookahead != '.'))
1144  {
1145  return $token;
1146  }
1147  // if it's a range A1:A2 or $A$1:$A$2
1148  elseif (preg_match('/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/', $token) and
1149  !preg_match("/[0-9]/",$this->_lookahead))
1150  {
1151  return $token;
1152  }
1153  // If it's an external range like Sheet1!A1:B2 or Sheet1:Sheet2!A1:B2 or Sheet1!$A$1:$B$2 or Sheet1:Sheet2!$A$1:$B$2
1154  elseif (preg_match("/^" . self::REGEX_SHEET_TITLE_UNQUOTED . "(\:" . self::REGEX_SHEET_TITLE_UNQUOTED . ")?\!\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+:\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+$/u",$token) and
1155  !preg_match("/[0-9]/",$this->_lookahead))
1156  {
1157  return $token;
1158  }
1159  // If it's an external range like 'Sheet1'!A1:B2 or 'Sheet1:Sheet2'!A1:B2 or 'Sheet1'!$A$1:$B$2 or 'Sheet1:Sheet2'!$A$1:$B$2
1160  elseif (preg_match("/^'" . self::REGEX_SHEET_TITLE_QUOTED . "(\:" . self::REGEX_SHEET_TITLE_QUOTED . ")?'\!\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+:\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+$/u",$token) and
1161  !preg_match("/[0-9]/",$this->_lookahead))
1162  {
1163  return $token;
1164  }
1165  // If it's a number (check that it's not a sheet name or range)
1166  elseif (is_numeric($token) and
1167  (!is_numeric($token.$this->_lookahead) or ($this->_lookahead == '')) and
1168  ($this->_lookahead != '!') and ($this->_lookahead != ':'))
1169  {
1170  return $token;
1171  }
1172  // If it's a string (of maximum 255 characters)
1173  elseif (preg_match("/\"([^\"]|\"\"){0,255}\"/",$token) and $this->_lookahead != '"' and (substr_count($token, '"')%2 == 0))
1174  {
1175  return $token;
1176  }
1177  // If it's an error code
1178  elseif (preg_match("/^#[A-Z0\/]{3,5}[!?]{1}$/", $token) or $token == '#N/A')
1179  {
1180  return $token;
1181  }
1182  // if it's a function call
1183  elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$token) and ($this->_lookahead == "("))
1184  {
1185  return $token;
1186  }
1187  // It's an argument of some description (e.g. a named range),
1188  // precise nature yet to be determined
1189  elseif(substr($token,-1) == ')') {
1190  return $token;
1191  }
1192  return '';
1193  }
1194  }
+ Here is the caller graph for this function:

◆ _packExtRef()

PHPExcel_Writer_Excel5_Parser::_packExtRef (   $ext_ref)

Convert the sheet name part of an external reference, for example "Sheet1" or "Sheet1:Sheet2", to a packed structure.

private

Parameters
string$ext_refThe name of the external reference
Returns
string The reference index in packed() format

Definition at line 804 of file Parser.php.

References _getSheetIndex(), and array.

805  {
806  $ext_ref = preg_replace("/^'/", '', $ext_ref); // Remove leading ' if any.
807  $ext_ref = preg_replace("/'$/", '', $ext_ref); // Remove trailing ' if any.
808 
809  // Check if there is a sheet range eg., Sheet1:Sheet2.
810  if (preg_match("/:/", $ext_ref)) {
811  list($sheet_name1, $sheet_name2) = explode(':', $ext_ref);
812 
813  $sheet1 = $this->_getSheetIndex($sheet_name1);
814  if ($sheet1 == -1) {
815  throw new PHPExcel_Writer_Exception("Unknown sheet name $sheet_name1 in formula");
816  }
817  $sheet2 = $this->_getSheetIndex($sheet_name2);
818  if ($sheet2 == -1) {
819  throw new PHPExcel_Writer_Exception("Unknown sheet name $sheet_name2 in formula");
820  }
821 
822  // Reverse max and min sheet numbers if necessary
823  if ($sheet1 > $sheet2) {
824  list($sheet1, $sheet2) = array($sheet2, $sheet1);
825  }
826  } else { // Single sheet name only.
827  $sheet1 = $this->_getSheetIndex($ext_ref);
828  if ($sheet1 == -1) {
829  throw new PHPExcel_Writer_Exception("Unknown sheet name $ext_ref in formula");
830  }
831  $sheet2 = $sheet1;
832  }
833 
834  // References are stored relative to 0xFFFF.
835  $offset = -1 - $sheet1;
836 
837  return pack('vdvv', $offset, 0x00, $sheet1, $sheet2);
838  }
_getSheetIndex($sheet_name)
Look up the index that corresponds to an external sheet name.
Definition: Parser.php:909
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ _parenthesizedExpression()

PHPExcel_Writer_Excel5_Parser::_parenthesizedExpression ( )

This function just introduces a ptgParen element in the tree, so that Excel doesn't get confused when working with a parenthesized formula afterwards.

private

See also
_fact()
Returns
array The parsed ptg'd tree

Definition at line 1326 of file Parser.php.

References $result, _createTree(), and _expression().

Referenced by _fact().

1327  {
1328  $result = $this->_createTree('ptgParen', $this->_expression(), '');
1329  return $result;
1330  }
$result
_createTree($value, $left, $right)
Creates a tree.
Definition: Parser.php:1508
_expression()
It parses a expression.
Definition: Parser.php:1267
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _rangeToPackedRange()

PHPExcel_Writer_Excel5_Parser::_rangeToPackedRange (   $range)

pack() row range into the required 3 or 4 byte format.

Just using maximum col/rows, which is probably not the correct solution

private

Parameters
string$rangeThe Excel range to be packed
Returns
array Array containing (row1,col1,row2,col2) in packed() format

Definition at line 969 of file Parser.php.

References array.

Referenced by _convertRange3d().

970  {
971  preg_match('/(\$)?(\d+)\:(\$)?(\d+)/', $range, $match);
972  // return absolute rows if there is a $ in the ref
973  $row1_rel = empty($match[1]) ? 1 : 0;
974  $row1 = $match[2];
975  $row2_rel = empty($match[3]) ? 1 : 0;
976  $row2 = $match[4];
977  // Convert 1-index to zero-index
978  --$row1;
979  --$row2;
980  // Trick poor inocent Excel
981  $col1 = 0;
982  $col2 = 65535; // FIXME: maximum possible value for Excel 5 (change this!!!)
983 
984  // FIXME: this changes for BIFF8
985  if (($row1 >= 65536) or ($row2 >= 65536)) {
986  throw new PHPExcel_Writer_Exception("Row in: $range greater than 65536 ");
987  }
988 
989  // Set the high bits to indicate if rows are relative.
990  $col1 |= $row1_rel << 15;
991  $col2 |= $row2_rel << 15;
992  $col1 = pack('v', $col1);
993  $col2 = pack('v', $col2);
994 
995  $row1 = pack('v', $row1);
996  $row2 = pack('v', $row2);
997 
998  return array($row1, $col1, $row2, $col2);
999  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ _term()

PHPExcel_Writer_Excel5_Parser::_term ( )

It parses a term.

It assumes the following rule: Term -> Fact [("*" | "/") Fact]

private

Returns
mixed The parsed ptg'd tree on success

Definition at line 1339 of file Parser.php.

References $result, _advance(), _createTree(), and _fact().

Referenced by _expression().

1340  {
1341  $result = $this->_fact();
1342  while (($this->_current_token == "*") or
1343  ($this->_current_token == "/")) {
1344 
1345  if ($this->_current_token == "*") {
1346  $this->_advance();
1347  $result2 = $this->_fact();
1348  $result = $this->_createTree('ptgMul', $result, $result2);
1349  } else {
1350  $this->_advance();
1351  $result2 = $this->_fact();
1352  $result = $this->_createTree('ptgDiv', $result, $result2);
1353  }
1354  }
1355  return $result;
1356  }
$result
_createTree($value, $left, $right)
Creates a tree.
Definition: Parser.php:1508
_advance()
Advance to the next valid token.
Definition: Parser.php:1040
_fact()
It parses a factor.
Definition: Parser.php:1369
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse()

PHPExcel_Writer_Excel5_Parser::parse (   $formula)

The parsing method.

It parses a formula.

public

Parameters
string$formulaThe formula to parse, without the initial equal sign (=).
Returns
mixed true on success

Definition at line 1204 of file Parser.php.

References _advance(), and _condition().

1205  {
1206  $this->_current_char = 0;
1207  $this->_formula = $formula;
1208  $this->_lookahead = isset($formula{1}) ? $formula{1} : '';
1209  $this->_advance();
1210  $this->_parse_tree = $this->_condition();
1211  return true;
1212  }
_condition()
It parses a condition.
Definition: Parser.php:1221
_advance()
Advance to the next valid token.
Definition: Parser.php:1040
+ Here is the call graph for this function:

◆ setExtSheet()

PHPExcel_Writer_Excel5_Parser::setExtSheet (   $name,
  $index 
)

This method is used to update the array of sheet names.

It is called by the addWorksheet() method of the PHPExcel_Writer_Excel5_Workbook class.

public

See also
PHPExcel_Writer_Excel5_Workbook::addWorksheet()
Parameters
string$nameThe name of the worksheet being added
integer$indexThe index of the worksheet being added

Definition at line 928 of file Parser.php.

929  {
930  $this->_ext_sheets[$name] = $index;
931  }

◆ toReversePolish()

PHPExcel_Writer_Excel5_Parser::toReversePolish (   $tree = array())

Builds a string containing the tree in reverse polish notation (What you would use in a HP calculator stack).

The following tree:

  • / \ 2 3

produces: "23+"

The following tree:

  • / \ 3 * / \ 6 A1

produces: "36A1*+"

In fact all operands, functions, references, etc... are written as ptg's

public

Parameters
array$treeThe optional tree to convert.
Returns
string The tree in reverse polish notation

Definition at line 1540 of file Parser.php.

References $_parse_tree, and _convert().

1541  {
1542  $polish = ""; // the string we are going to return
1543  if (empty($tree)) { // If it's the first call use _parse_tree
1544  $tree = $this->_parse_tree;
1545  }
1546 
1547  if (is_array($tree['left'])) {
1548  $converted_tree = $this->toReversePolish($tree['left']);
1549  $polish .= $converted_tree;
1550  } elseif ($tree['left'] != '') { // It's a final node
1551  $converted_tree = $this->_convert($tree['left']);
1552  $polish .= $converted_tree;
1553  }
1554  if (is_array($tree['right'])) {
1555  $converted_tree = $this->toReversePolish($tree['right']);
1556  $polish .= $converted_tree;
1557  } elseif ($tree['right'] != '') { // It's a final node
1558  $converted_tree = $this->_convert($tree['right']);
1559  $polish .= $converted_tree;
1560  }
1561  // if it's a function convert it here (so we can set it's arguments)
1562  if (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/",$tree['value']) and
1563  !preg_match('/^([A-Ia-i]?[A-Za-z])(\d+)$/',$tree['value']) and
1564  !preg_match("/^[A-Ia-i]?[A-Za-z](\d+)\.\.[A-Ia-i]?[A-Za-z](\d+)$/",$tree['value']) and
1565  !is_numeric($tree['value']) and
1566  !isset($this->ptg[$tree['value']]))
1567  {
1568  // left subtree for a function is always an array.
1569  if ($tree['left'] != '') {
1570  $left_tree = $this->toReversePolish($tree['left']);
1571  } else {
1572  $left_tree = '';
1573  }
1574  // add it's left subtree and return.
1575  return $left_tree.$this->_convertFunction($tree['value'], $tree['right']);
1576  } else {
1577  $converted_tree = $this->_convert($tree['value']);
1578  }
1579  $polish .= $converted_tree;
1580  return $polish;
1581  }
toReversePolish($tree=array())
Builds a string containing the tree in reverse polish notation (What you would use in a HP calculator...
Definition: Parser.php:1540
_convert($token)
Convert a token to the proper ptg value.
Definition: Parser.php:515
+ Here is the call graph for this function:

Field Documentation

◆ $_current_char

PHPExcel_Writer_Excel5_Parser::$_current_char

Definition at line 80 of file Parser.php.

Referenced by _advance().

◆ $_current_token

PHPExcel_Writer_Excel5_Parser::$_current_token

Definition at line 86 of file Parser.php.

◆ $_ext_sheets

PHPExcel_Writer_Excel5_Parser::$_ext_sheets

Definition at line 110 of file Parser.php.

◆ $_formula

PHPExcel_Writer_Excel5_Parser::$_formula

Definition at line 92 of file Parser.php.

◆ $_lookahead

PHPExcel_Writer_Excel5_Parser::$_lookahead

Definition at line 98 of file Parser.php.

◆ $_parse_tree

PHPExcel_Writer_Excel5_Parser::$_parse_tree

Definition at line 104 of file Parser.php.

Referenced by toReversePolish().

◆ $_references

PHPExcel_Writer_Excel5_Parser::$_references

Definition at line 116 of file Parser.php.

◆ REGEX_SHEET_TITLE_QUOTED

const PHPExcel_Writer_Excel5_Parser::REGEX_SHEET_TITLE_QUOTED = '(([^\*\:\/\\\\\?\[\]\\\'])+|(\\\'\\\')+)+'

Definition at line 74 of file Parser.php.

◆ REGEX_SHEET_TITLE_UNQUOTED

const PHPExcel_Writer_Excel5_Parser::REGEX_SHEET_TITLE_UNQUOTED = '[^\*\:\/\\\\\?\[\]\+\-\% \\\'\^\&<>\=\,\;\#\(\)\"\{\}]+'

Constants.

Definition at line 68 of file Parser.php.


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