Parser
in package
Table of Contents
Constants
- REGEX_SHEET_TITLE_QUOTED = '(([^\*\:\/\\\\\\?\[\]\\\'])+|(\\\'\\\')+)+'
- REGEX_SHEET_TITLE_UNQUOTED = '[^\*\:\/\\\\\\?\[\]\+\-\% \\\'\^\&\<\>\=\,\;\#\(\)\"\{\}]+'
- Constants
Properties
- $currentCharacter : int
- The index of the character we are currently looking at.
- $currentToken : string
- The token we are working on.
- $lookAhead : string
- The character ahead of the current char.
- $parseTree : array<string|int, mixed>|string
- The parse tree to be generated.
- $references : array<string|int, mixed>
- Array of sheet references in the form of REF structures.
- $externalSheets : array<string|int, mixed>
- Array of external sheets.
- $formula : string
- The formula to parse.
- $functions : array<string|int, mixed>
- Thanks to Michael Meeks and Gnumeric for the initial arg values.
- $ptg : array<string|int, mixed>
- The Excel ptg indices.
- $spreadsheet : Spreadsheet
- $tryDefinedName : bool
Methods
- __construct() : mixed
- The class constructor.
- parse() : bool
- The parsing method. It parses a formula.
- setExtSheet() : void
- This method is used to update the array of sheet names. It is called by the addWorksheet() method of the \PhpOffice\PhpSpreadsheet\Writer\Xls\Workbook class.
- toReversePolish() : string
- Builds a string containing the tree in reverse polish notation (What you would use in a HP calculator stack).
- advance() : void
- Advance to the next valid token.
- cellToPackedRowcol() : array<string|int, mixed>
- pack() row and column into the required 3 or 4 byte format.
- cellToRowcol() : array<string|int, mixed>
- 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.
- condition() : array<string|int, mixed>
- It parses a condition. It assumes the following rule: Cond -> Expr [(">" | "<") Expr].
- convert() : string
- Convert a token to the proper ptg value.
- convertBool() : string
- convertDefinedName() : string
- convertError() : string
- Convert an error code to a ptgErr.
- convertFunction() : string
- Convert a function to a ptgFunc or ptgFuncVarV depending on the number of args that it takes.
- convertNumber() : string
- Convert a number token to ptgInt or ptgNum.
- convertRange2d() : string
- Convert an Excel range such as A1:D4 to a ptgRefV.
- convertRange3d() : string
- Convert an Excel 3d range such as "Sheet1!A1:D4" or "Sheet1:Sheet2!A1:D4" to a ptgArea3d.
- convertRef2d() : string
- Convert an Excel reference such as A1, $B2, C$3 or $D$4 to a ptgRefV.
- convertRef3d() : string
- Convert an Excel 3d reference such as "Sheet1!A1" or "Sheet1:Sheet2!A1" to a ptgRef3d.
- convertString() : string
- Convert a string token to ptgStr.
- createTree() : array<string|int, mixed>
- Creates a tree. In fact an array which may have one or two arrays (sub-trees) as elements.
- expression() : array<string|int, mixed>
- It parses a expression. It assumes the following rule: Expr -> Term [("+" | "-") Term] -> "string" -> "-" Term : Negative value -> "+" Term : Positive value -> Error code.
- fact() : array<string|int, mixed>
- It parses a factor. It assumes the following rule: Fact -> ( Expr ) | CellRef | CellRange | Number | Function.
- func() : array<string|int, mixed>
- It parses a function call. It assumes the following rule: Func -> ( Expr [,Expr]* ).
- getRefIndex() : string
- 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.
- getSheetIndex() : int
- Look up the index that corresponds to an external sheet name. The hash of sheet names is updated by the addworksheet() method of the \PhpOffice\PhpSpreadsheet\Writer\Xls\Workbook class.
- match() : string
- Checks if it's a valid token.
- parenthesizedExpression() : array<string|int, mixed>
- This function just introduces a ptgParen element in the tree, so that Excel doesn't get confused when working with a parenthesized formula afterwards.
- rangeToPackedRange() : array<string|int, mixed>
- pack() row range into the required 3 or 4 byte format.
- term() : array<string|int, mixed>
- It parses a term. It assumes the following rule: Term -> Fact [("*" | "/") Fact].
Constants
REGEX_SHEET_TITLE_QUOTED
public
mixed
REGEX_SHEET_TITLE_QUOTED
= '(([^\*\:\/\\\\\\?\[\]\\\'])+|(\\\'\\\')+)+'
REGEX_SHEET_TITLE_UNQUOTED
Constants
public
mixed
REGEX_SHEET_TITLE_UNQUOTED
= '[^\*\:\/\\\\\\?\[\]\+\-\% \\\'\^\&\<\>\=\,\;\#\(\)\"\{\}]+'
Properties
$currentCharacter
The index of the character we are currently looking at.
public
int
$currentCharacter
$currentToken
The token we are working on.
public
string
$currentToken
$lookAhead
The character ahead of the current char.
public
string
$lookAhead
$parseTree
The parse tree to be generated.
public
array<string|int, mixed>|string
$parseTree
$references
Array of sheet references in the form of REF structures.
public
array<string|int, mixed>
$references
$externalSheets
Array of external sheets.
private
array<string|int, mixed>
$externalSheets
$formula
The formula to parse.
private
string
$formula
$functions
Thanks to Michael Meeks and Gnumeric for the initial arg values.
private
array<string|int, mixed>
$functions
= [
// function ptg args class vol
'COUNT' => [0, -1, 0, 0],
'IF' => [1, -1, 1, 0],
'ISNA' => [2, 1, 1, 0],
'ISERROR' => [3, 1, 1, 0],
'SUM' => [4, -1, 0, 0],
'AVERAGE' => [5, -1, 0, 0],
'MIN' => [6, -1, 0, 0],
'MAX' => [7, -1, 0, 0],
'ROW' => [8, -1, 0, 0],
'COLUMN' => [9, -1, 0, 0],
'NA' => [10, 0, 0, 0],
'NPV' => [11, -1, 1, 0],
'STDEV' => [12, -1, 0, 0],
'DOLLAR' => [13, -1, 1, 0],
'FIXED' => [14, -1, 1, 0],
'SIN' => [15, 1, 1, 0],
'COS' => [16, 1, 1, 0],
'TAN' => [17, 1, 1, 0],
'ATAN' => [18, 1, 1, 0],
'PI' => [19, 0, 1, 0],
'SQRT' => [20, 1, 1, 0],
'EXP' => [21, 1, 1, 0],
'LN' => [22, 1, 1, 0],
'LOG10' => [23, 1, 1, 0],
'ABS' => [24, 1, 1, 0],
'INT' => [25, 1, 1, 0],
'SIGN' => [26, 1, 1, 0],
'ROUND' => [27, 2, 1, 0],
'LOOKUP' => [28, -1, 0, 0],
'INDEX' => [29, -1, 0, 1],
'REPT' => [30, 2, 1, 0],
'MID' => [31, 3, 1, 0],
'LEN' => [32, 1, 1, 0],
'VALUE' => [33, 1, 1, 0],
'TRUE' => [34, 0, 1, 0],
'FALSE' => [35, 0, 1, 0],
'AND' => [36, -1, 0, 0],
'OR' => [37, -1, 0, 0],
'NOT' => [38, 1, 1, 0],
'MOD' => [39, 2, 1, 0],
'DCOUNT' => [40, 3, 0, 0],
'DSUM' => [41, 3, 0, 0],
'DAVERAGE' => [42, 3, 0, 0],
'DMIN' => [43, 3, 0, 0],
'DMAX' => [44, 3, 0, 0],
'DSTDEV' => [45, 3, 0, 0],
'VAR' => [46, -1, 0, 0],
'DVAR' => [47, 3, 0, 0],
'TEXT' => [48, 2, 1, 0],
'LINEST' => [49, -1, 0, 0],
'TREND' => [50, -1, 0, 0],
'LOGEST' => [51, -1, 0, 0],
'GROWTH' => [52, -1, 0, 0],
'PV' => [56, -1, 1, 0],
'FV' => [57, -1, 1, 0],
'NPER' => [58, -1, 1, 0],
'PMT' => [59, -1, 1, 0],
'RATE' => [60, -1, 1, 0],
'MIRR' => [61, 3, 0, 0],
'IRR' => [62, -1, 0, 0],
'RAND' => [63, 0, 1, 1],
'MATCH' => [64, -1, 0, 0],
'DATE' => [65, 3, 1, 0],
'TIME' => [66, 3, 1, 0],
'DAY' => [67, 1, 1, 0],
'MONTH' => [68, 1, 1, 0],
'YEAR' => [69, 1, 1, 0],
'WEEKDAY' => [70, -1, 1, 0],
'HOUR' => [71, 1, 1, 0],
'MINUTE' => [72, 1, 1, 0],
'SECOND' => [73, 1, 1, 0],
'NOW' => [74, 0, 1, 1],
'AREAS' => [75, 1, 0, 1],
'ROWS' => [76, 1, 0, 1],
'COLUMNS' => [77, 1, 0, 1],
'OFFSET' => [78, -1, 0, 1],
'SEARCH' => [82, -1, 1, 0],
'TRANSPOSE' => [83, 1, 1, 0],
'TYPE' => [86, 1, 1, 0],
'ATAN2' => [97, 2, 1, 0],
'ASIN' => [98, 1, 1, 0],
'ACOS' => [99, 1, 1, 0],
'CHOOSE' => [100, -1, 1, 0],
'HLOOKUP' => [101, -1, 0, 0],
'VLOOKUP' => [102, -1, 0, 0],
'ISREF' => [105, 1, 0, 0],
'LOG' => [109, -1, 1, 0],
'CHAR' => [111, 1, 1, 0],
'LOWER' => [112, 1, 1, 0],
'UPPER' => [113, 1, 1, 0],
'PROPER' => [114, 1, 1, 0],
'LEFT' => [115, -1, 1, 0],
'RIGHT' => [116, -1, 1, 0],
'EXACT' => [117, 2, 1, 0],
'TRIM' => [118, 1, 1, 0],
'REPLACE' => [119, 4, 1, 0],
'SUBSTITUTE' => [120, -1, 1, 0],
'CODE' => [121, 1, 1, 0],
'FIND' => [124, -1, 1, 0],
'CELL' => [125, -1, 0, 1],
'ISERR' => [126, 1, 1, 0],
'ISTEXT' => [127, 1, 1, 0],
'ISNUMBER' => [128, 1, 1, 0],
'ISBLANK' => [129, 1, 1, 0],
'T' => [130, 1, 0, 0],
'N' => [131, 1, 0, 0],
'DATEVALUE' => [140, 1, 1, 0],
'TIMEVALUE' => [141, 1, 1, 0],
'SLN' => [142, 3, 1, 0],
'SYD' => [143, 4, 1, 0],
'DDB' => [144, -1, 1, 0],
'INDIRECT' => [148, -1, 1, 1],
'CALL' => [150, -1, 1, 0],
'CLEAN' => [162, 1, 1, 0],
'MDETERM' => [163, 1, 2, 0],
'MINVERSE' => [164, 1, 2, 0],
'MMULT' => [165, 2, 2, 0],
'IPMT' => [167, -1, 1, 0],
'PPMT' => [168, -1, 1, 0],
'COUNTA' => [169, -1, 0, 0],
'PRODUCT' => [183, -1, 0, 0],
'FACT' => [184, 1, 1, 0],
'DPRODUCT' => [189, 3, 0, 0],
'ISNONTEXT' => [190, 1, 1, 0],
'STDEVP' => [193, -1, 0, 0],
'VARP' => [194, -1, 0, 0],
'DSTDEVP' => [195, 3, 0, 0],
'DVARP' => [196, 3, 0, 0],
'TRUNC' => [197, -1, 1, 0],
'ISLOGICAL' => [198, 1, 1, 0],
'DCOUNTA' => [199, 3, 0, 0],
'USDOLLAR' => [204, -1, 1, 0],
'FINDB' => [205, -1, 1, 0],
'SEARCHB' => [206, -1, 1, 0],
'REPLACEB' => [207, 4, 1, 0],
'LEFTB' => [208, -1, 1, 0],
'RIGHTB' => [209, -1, 1, 0],
'MIDB' => [210, 3, 1, 0],
'LENB' => [211, 1, 1, 0],
'ROUNDUP' => [212, 2, 1, 0],
'ROUNDDOWN' => [213, 2, 1, 0],
'ASC' => [214, 1, 1, 0],
'DBCS' => [215, 1, 1, 0],
'RANK' => [216, -1, 0, 0],
'ADDRESS' => [219, -1, 1, 0],
'DAYS360' => [220, -1, 1, 0],
'TODAY' => [221, 0, 1, 1],
'VDB' => [222, -1, 1, 0],
'MEDIAN' => [227, -1, 0, 0],
'SUMPRODUCT' => [228, -1, 2, 0],
'SINH' => [229, 1, 1, 0],
'COSH' => [230, 1, 1, 0],
'TANH' => [231, 1, 1, 0],
'ASINH' => [232, 1, 1, 0],
'ACOSH' => [233, 1, 1, 0],
'ATANH' => [234, 1, 1, 0],
'DGET' => [235, 3, 0, 0],
'INFO' => [244, 1, 1, 1],
'DB' => [247, -1, 1, 0],
'FREQUENCY' => [252, 2, 0, 0],
'ERROR.TYPE' => [261, 1, 1, 0],
'REGISTER.ID' => [267, -1, 1, 0],
'AVEDEV' => [269, -1, 0, 0],
'BETADIST' => [270, -1, 1, 0],
'GAMMALN' => [271, 1, 1, 0],
'BETAINV' => [272, -1, 1, 0],
'BINOMDIST' => [273, 4, 1, 0],
'CHIDIST' => [274, 2, 1, 0],
'CHIINV' => [275, 2, 1, 0],
'COMBIN' => [276, 2, 1, 0],
'CONFIDENCE' => [277, 3, 1, 0],
'CRITBINOM' => [278, 3, 1, 0],
'EVEN' => [279, 1, 1, 0],
'EXPONDIST' => [280, 3, 1, 0],
'FDIST' => [281, 3, 1, 0],
'FINV' => [282, 3, 1, 0],
'FISHER' => [283, 1, 1, 0],
'FISHERINV' => [284, 1, 1, 0],
'FLOOR' => [285, 2, 1, 0],
'GAMMADIST' => [286, 4, 1, 0],
'GAMMAINV' => [287, 3, 1, 0],
'CEILING' => [288, 2, 1, 0],
'HYPGEOMDIST' => [289, 4, 1, 0],
'LOGNORMDIST' => [290, 3, 1, 0],
'LOGINV' => [291, 3, 1, 0],
'NEGBINOMDIST' => [292, 3, 1, 0],
'NORMDIST' => [293, 4, 1, 0],
'NORMSDIST' => [294, 1, 1, 0],
'NORMINV' => [295, 3, 1, 0],
'NORMSINV' => [296, 1, 1, 0],
'STANDARDIZE' => [297, 3, 1, 0],
'ODD' => [298, 1, 1, 0],
'PERMUT' => [299, 2, 1, 0],
'POISSON' => [300, 3, 1, 0],
'TDIST' => [301, 3, 1, 0],
'WEIBULL' => [302, 4, 1, 0],
'SUMXMY2' => [303, 2, 2, 0],
'SUMX2MY2' => [304, 2, 2, 0],
'SUMX2PY2' => [305, 2, 2, 0],
'CHITEST' => [306, 2, 2, 0],
'CORREL' => [307, 2, 2, 0],
'COVAR' => [308, 2, 2, 0],
'FORECAST' => [309, 3, 2, 0],
'FTEST' => [310, 2, 2, 0],
'INTERCEPT' => [311, 2, 2, 0],
'PEARSON' => [312, 2, 2, 0],
'RSQ' => [313, 2, 2, 0],
'STEYX' => [314, 2, 2, 0],
'SLOPE' => [315, 2, 2, 0],
'TTEST' => [316, 4, 2, 0],
'PROB' => [317, -1, 2, 0],
'DEVSQ' => [318, -1, 0, 0],
'GEOMEAN' => [319, -1, 0, 0],
'HARMEAN' => [320, -1, 0, 0],
'SUMSQ' => [321, -1, 0, 0],
'KURT' => [322, -1, 0, 0],
'SKEW' => [323, -1, 0, 0],
'ZTEST' => [324, -1, 0, 0],
'LARGE' => [325, 2, 0, 0],
'SMALL' => [326, 2, 0, 0],
'QUARTILE' => [327, 2, 0, 0],
'PERCENTILE' => [328, 2, 0, 0],
'PERCENTRANK' => [329, -1, 0, 0],
'MODE' => [330, -1, 2, 0],
'TRIMMEAN' => [331, 2, 0, 0],
'TINV' => [332, 2, 1, 0],
'CONCATENATE' => [336, -1, 1, 0],
'POWER' => [337, 2, 1, 0],
'RADIANS' => [342, 1, 1, 0],
'DEGREES' => [343, 1, 1, 0],
'SUBTOTAL' => [344, -1, 0, 0],
'SUMIF' => [345, -1, 0, 0],
'COUNTIF' => [346, 2, 0, 0],
'COUNTBLANK' => [347, 1, 0, 0],
'ISPMT' => [350, 4, 1, 0],
'DATEDIF' => [351, 3, 1, 0],
'DATESTRING' => [352, 1, 1, 0],
'NUMBERSTRING' => [353, 2, 1, 0],
'ROMAN' => [354, -1, 1, 0],
'GETPIVOTDATA' => [358, -1, 0, 0],
'HYPERLINK' => [359, -1, 1, 0],
'PHONETIC' => [360, 1, 0, 0],
'AVERAGEA' => [361, -1, 0, 0],
'MAXA' => [362, -1, 0, 0],
'MINA' => [363, -1, 0, 0],
'STDEVPA' => [364, -1, 0, 0],
'VARPA' => [365, -1, 0, 0],
'STDEVA' => [366, -1, 0, 0],
'VARA' => [367, -1, 0, 0],
'BAHTTEXT' => [368, 1, 0, 0],
]
The following hash was generated by "function_locale.pl" in the distro. Refer to function_locale.pl for non-English function names.
The array elements are as follow: ptg: The Excel function ptg code. args: The number of arguments that the function takes: >=0 is a fixed number of arguments. -1 is a variable number of arguments. class: The reference, value or array class of the function args. vol: The function is volatile.
$ptg
The Excel ptg indices.
private
array<string|int, mixed>
$ptg
= ['ptgExp' => 0x1, 'ptgTbl' => 0x2, 'ptgAdd' => 0x3, 'ptgSub' => 0x4, 'ptgMul' => 0x5, 'ptgDiv' => 0x6, 'ptgPower' => 0x7, 'ptgConcat' => 0x8, 'ptgLT' => 0x9, 'ptgLE' => 0xa, 'ptgEQ' => 0xb, 'ptgGE' => 0xc, 'ptgGT' => 0xd, 'ptgNE' => 0xe, 'ptgIsect' => 0xf, 'ptgUnion' => 0x10, 'ptgRange' => 0x11, 'ptgUplus' => 0x12, 'ptgUminus' => 0x13, 'ptgPercent' => 0x14, 'ptgParen' => 0x15, 'ptgMissArg' => 0x16, 'ptgStr' => 0x17, 'ptgAttr' => 0x19, 'ptgSheet' => 0x1a, 'ptgEndSheet' => 0x1b, 'ptgErr' => 0x1c, 'ptgBool' => 0x1d, 'ptgInt' => 0x1e, 'ptgNum' => 0x1f, 'ptgArray' => 0x20, 'ptgFunc' => 0x21, 'ptgFuncVar' => 0x22, 'ptgName' => 0x23, 'ptgRef' => 0x24, 'ptgArea' => 0x25, 'ptgMemArea' => 0x26, 'ptgMemErr' => 0x27, 'ptgMemNoMem' => 0x28, 'ptgMemFunc' => 0x29, 'ptgRefErr' => 0x2a, 'ptgAreaErr' => 0x2b, 'ptgRefN' => 0x2c, 'ptgAreaN' => 0x2d, 'ptgMemAreaN' => 0x2e, 'ptgMemNoMemN' => 0x2f, 'ptgNameX' => 0x39, 'ptgRef3d' => 0x3a, 'ptgArea3d' => 0x3b, 'ptgRefErr3d' => 0x3c, 'ptgAreaErr3d' => 0x3d, 'ptgArrayV' => 0x40, 'ptgFuncV' => 0x41, 'ptgFuncVarV' => 0x42, 'ptgNameV' => 0x43, 'ptgRefV' => 0x44, 'ptgAreaV' => 0x45, 'ptgMemAreaV' => 0x46, 'ptgMemErrV' => 0x47, 'ptgMemNoMemV' => 0x48, 'ptgMemFuncV' => 0x49, 'ptgRefErrV' => 0x4a, 'ptgAreaErrV' => 0x4b, 'ptgRefNV' => 0x4c, 'ptgAreaNV' => 0x4d, 'ptgMemAreaNV' => 0x4e, 'ptgMemNoMemNV' => 0x4f, 'ptgFuncCEV' => 0x58, 'ptgNameXV' => 0x59, 'ptgRef3dV' => 0x5a, 'ptgArea3dV' => 0x5b, 'ptgRefErr3dV' => 0x5c, 'ptgAreaErr3dV' => 0x5d, 'ptgArrayA' => 0x60, 'ptgFuncA' => 0x61, 'ptgFuncVarA' => 0x62, 'ptgNameA' => 0x63, 'ptgRefA' => 0x64, 'ptgAreaA' => 0x65, 'ptgMemAreaA' => 0x66, 'ptgMemErrA' => 0x67, 'ptgMemNoMemA' => 0x68, 'ptgMemFuncA' => 0x69, 'ptgRefErrA' => 0x6a, 'ptgAreaErrA' => 0x6b, 'ptgRefNA' => 0x6c, 'ptgAreaNA' => 0x6d, 'ptgMemAreaNA' => 0x6e, 'ptgMemNoMemNA' => 0x6f, 'ptgFuncCEA' => 0x78, 'ptgNameXA' => 0x79, 'ptgRef3dA' => 0x7a, 'ptgArea3dA' => 0x7b, 'ptgRefErr3dA' => 0x7c, 'ptgAreaErr3dA' => 0x7d]
$spreadsheet
private
Spreadsheet
$spreadsheet
$tryDefinedName
private
bool
$tryDefinedName
= false
Methods
__construct()
The class constructor.
public
__construct(Spreadsheet $spreadsheet) : mixed
Parameters
- $spreadsheet : Spreadsheet
parse()
The parsing method. It parses a formula.
public
parse(string $formula) : bool
Parameters
- $formula : string
-
the formula to parse, without the initial equal sign (=)
Return values
bool —true on success
setExtSheet()
This method is used to update the array of sheet names. It is called by the addWorksheet() method of the \PhpOffice\PhpSpreadsheet\Writer\Xls\Workbook class.
public
setExtSheet(string $name, int $index) : void
Parameters
- $name : string
-
The name of the worksheet being added
- $index : int
-
The index of the worksheet being added
Tags
toReversePolish()
Builds a string containing the tree in reverse polish notation (What you would use in a HP calculator stack).
public
toReversePolish([array<string|int, mixed> $tree = [] ]) : string
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
Parameters
- $tree : array<string|int, mixed> = []
-
the optional tree to convert
Return values
string —The tree in reverse polish notation
advance()
Advance to the next valid token.
private
advance() : void
cellToPackedRowcol()
pack() row and column into the required 3 or 4 byte format.
private
cellToPackedRowcol(string $cell) : array<string|int, mixed>
Parameters
- $cell : string
-
The Excel cell reference to be packed
Return values
array<string|int, mixed> —Array containing the row and column in packed() format
cellToRowcol()
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
cellToRowcol(string $cell) : array<string|int, mixed>
Parameters
- $cell : string
-
the Excel cell reference in A1 format
Return values
array<string|int, mixed>condition()
It parses a condition. It assumes the following rule: Cond -> Expr [(">" | "<") Expr].
private
condition() : array<string|int, mixed>
Return values
array<string|int, mixed> —The parsed ptg'd tree on success
convert()
Convert a token to the proper ptg value.
private
convert(string $token) : string
Parameters
- $token : string
-
the token to convert
Return values
string —the converted token on success
convertBool()
private
convertBool(int $num) : string
Parameters
- $num : int
Return values
stringconvertDefinedName()
private
convertDefinedName(string $name) : string
Parameters
- $name : string
Return values
stringconvertError()
Convert an error code to a ptgErr.
private
convertError(string $errorCode) : string
Parameters
- $errorCode : string
-
The error code for conversion to its ptg value
Return values
string —The error code ptgErr
convertFunction()
Convert a function to a ptgFunc or ptgFuncVarV depending on the number of args that it takes.
private
convertFunction(string $token, int $num_args) : string
Parameters
- $token : string
-
the name of the function for convertion to ptg value
- $num_args : int
-
the number of arguments the function receives
Return values
string —The packed ptg for the function
convertNumber()
Convert a number token to ptgInt or ptgNum.
private
convertNumber(float|int|string $num) : string
Parameters
- $num : float|int|string
-
an integer or double for conversion to its ptg value
Return values
stringconvertRange2d()
Convert an Excel range such as A1:D4 to a ptgRefV.
private
convertRange2d(string $range[, int $class = 0 ]) : string
Parameters
- $range : string
-
An Excel range in the A1:A2
- $class : int = 0
Return values
stringconvertRange3d()
Convert an Excel 3d range such as "Sheet1!A1:D4" or "Sheet1:Sheet2!A1:D4" to a ptgArea3d.
private
convertRange3d(string $token) : string
Parameters
- $token : string
-
an Excel range in the Sheet1!A1:A2 format
Return values
string —the packed ptgArea3d token on success
convertRef2d()
Convert an Excel reference such as A1, $B2, C$3 or $D$4 to a ptgRefV.
private
convertRef2d(string $cell) : string
Parameters
- $cell : string
-
An Excel cell reference
Return values
string —The cell in packed() format with the corresponding ptg
convertRef3d()
Convert an Excel 3d reference such as "Sheet1!A1" or "Sheet1:Sheet2!A1" to a ptgRef3d.
private
convertRef3d(string $cell) : string
Parameters
- $cell : string
-
An Excel cell reference
Return values
string —the packed ptgRef3d token on success
convertString()
Convert a string token to ptgStr.
private
convertString(string $string) : string
Parameters
- $string : string
-
a string for conversion to its ptg value
Return values
string —the converted token
createTree()
Creates a tree. In fact an array which may have one or two arrays (sub-trees) as elements.
private
createTree(mixed $value, mixed $left, mixed $right) : array<string|int, mixed>
Parameters
- $value : mixed
-
the value of this node
- $left : mixed
-
the left array (sub-tree) or a final node
- $right : mixed
-
the right array (sub-tree) or a final node
Return values
array<string|int, mixed> —A tree
expression()
It parses a expression. It assumes the following rule: Expr -> Term [("+" | "-") Term] -> "string" -> "-" Term : Negative value -> "+" Term : Positive value -> Error code.
private
expression() : array<string|int, mixed>
Return values
array<string|int, mixed> —The parsed ptg'd tree on success
fact()
It parses a factor. It assumes the following rule: Fact -> ( Expr ) | CellRef | CellRange | Number | Function.
private
fact() : array<string|int, mixed>
Return values
array<string|int, mixed> —The parsed ptg'd tree on success
func()
It parses a function call. It assumes the following rule: Func -> ( Expr [,Expr]* ).
private
func() : array<string|int, mixed>
Return values
array<string|int, mixed> —The parsed ptg'd tree on success
getRefIndex()
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
getRefIndex(string $ext_ref) : string
Parameters
- $ext_ref : string
-
The name of the external reference
Return values
string —The reference index in packed() format on success
getSheetIndex()
Look up the index that corresponds to an external sheet name. The hash of sheet names is updated by the addworksheet() method of the \PhpOffice\PhpSpreadsheet\Writer\Xls\Workbook class.
private
getSheetIndex(string $sheet_name) : int
Parameters
- $sheet_name : string
-
Sheet name
Return values
int —The sheet index, -1 if the sheet was not found
match()
Checks if it's a valid token.
private
match(string $token) : string
Parameters
- $token : string
-
the token to check
Return values
string —The checked token or empty string on failure
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
parenthesizedExpression() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —The parsed ptg'd tree
rangeToPackedRange()
pack() row range into the required 3 or 4 byte format.
private
rangeToPackedRange(string $range) : array<string|int, mixed>
Just using maximum col/rows, which is probably not the correct solution.
Parameters
- $range : string
-
The Excel range to be packed
Return values
array<string|int, mixed> —Array containing (row1,col1,row2,col2) in packed() format
term()
It parses a term. It assumes the following rule: Term -> Fact [("*" | "/") Fact].
private
term() : array<string|int, mixed>
Return values
array<string|int, mixed> —The parsed ptg'd tree on success