[ Index ]

PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09)

title

Body

[close]

/include/inc_ext/PEAR/Spreadsheet/Excel/Writer/ -> Parser.php (summary)

Class for parsing Excel formulas License Information:

File Size: 1689 lines (67 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Spreadsheet_Excel_Writer_Parser:: (28 methods):
  Spreadsheet_Excel_Writer_Parser()
  _initializeHashes()
  _convert()
  _convertNumber()
  _convertString()
  _convertFunction()
  _convertRange2d()
  _convertRange3d()
  _convertRef2d()
  _convertRef3d()
  _packExtRef()
  _getRefIndex()
  _getSheetIndex()
  setExtSheet()
  _cellToPackedRowcol()
  _rangeToPackedRange()
  _cellToRowcol()
  _advance()
  _match()
  parse()
  _condition()
  _expression()
  _parenthesizedExpression()
  _term()
  _fact()
  _func()
  _createTree()
  toReversePolish()


Class: Spreadsheet_Excel_Writer_Parser  - X-Ref

Class for parsing Excel formulas

Spreadsheet_Excel_Writer_Parser($byte_order, $biff_version)   X-Ref
The class constructor

param: integer $byte_order The byte order (Little endian or Big endian) of the architecture

_initializeHashes()   X-Ref
Initialize the ptg and function hashes.


_convert($token)   X-Ref
Convert a token to the proper ptg value.

param: mixed $token The token to convert.
return: mixed the converted token on success. PEAR_Error if the token

_convertNumber($num)   X-Ref
Convert a number token to ptgInt or ptgNum

param: mixed $num an integer or double for conversion to its ptg value

_convertString($string)   X-Ref
Convert a string token to ptgStr

param: string $string A string for conversion to its ptg value.
return: mixed the converted token on success. PEAR_Error if the string

_convertFunction($token, $num_args)   X-Ref
Convert a function to a ptgFunc or ptgFuncVarV depending on the number of
args that it takes.

param: string  $token    The name of the function for convertion to ptg value.
param: integer $num_args The number of arguments the function receives.
return: string The packed ptg for the function

_convertRange2d($range)   X-Ref
Convert an Excel range such as A1:D4 to a ptgRefV.

param: string $range An Excel range in the A1:A2 or A1..A2 format.

_convertRange3d($token)   X-Ref
Convert an Excel 3d range such as "Sheet1!A1:D4" or "Sheet1:Sheet2!A1:D4" to
a ptgArea3d.

param: string $token An Excel range in the Sheet1!A1:A2 format.
return: mixed The packed ptgArea3d token on success, PEAR_Error on failure.

_convertRef2d($cell)   X-Ref
Convert an Excel reference such as A1, $B2, C$3 or $D$4 to a ptgRefV.

param: string $cell An Excel cell reference
return: string The cell in packed() format with the corresponding ptg

_convertRef3d($cell)   X-Ref
Convert an Excel 3d reference such as "Sheet1!A1" or "Sheet1:Sheet2!A1" to a
ptgRef3d.

param: string $cell An Excel cell reference
return: mixed The packed ptgRef3d token on success, PEAR_Error on failure.

_packExtRef($ext_ref)   X-Ref
Convert the sheet name part of an external reference, for example "Sheet1" or
"Sheet1:Sheet2", to a packed structure.

param: string $ext_ref The name of the external reference
return: string The reference index in packed() format

_getRefIndex($ext_ref)   X-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.

param: string $ext_ref The name of the external reference
return: mixed The reference index in packed() format on success,

_getSheetIndex($sheet_name)   X-Ref
Look up the index that corresponds to an external sheet name. The hash of
sheet names is updated by the addworksheet() method of the
Spreadsheet_Excel_Writer_Workbook class.

return: integer The sheet index, -1 if the sheet was not found

setExtSheet($name, $index)   X-Ref
This method is used to update the array of sheet names. It is
called by the addWorksheet() method of the
Spreadsheet_Excel_Writer_Workbook class.

param: string  $name  The name of the worksheet being added
param: integer $index The index of the worksheet being added

_cellToPackedRowcol($cell)   X-Ref
pack() row and column into the required 3 or 4 byte format.

param: string $cell The Excel cell reference to be packed
return: array Array containing the row and column in packed() format

_rangeToPackedRange($range)   X-Ref
pack() row range into the required 3 or 4 byte format.
Just using maximum col/rows, which is probably not the correct solution

param: string $range The Excel range to be packed
return: array Array containing (row1,col1,row2,col2) in packed() format

_cellToRowcol($cell)   X-Ref
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.

param: string $cell The Excel cell reference in A1 format.
return: array

_advance()   X-Ref
Advance to the next valid token.


_match($token)   X-Ref
Checks if it's a valid token.

param: mixed $token The token to check.
return: mixed       The checked token or false on failure

parse($formula)   X-Ref
The parsing method. It parses a formula.

param: string $formula The formula to parse, without the initial equal
return: mixed true on success, PEAR_Error on failure

_condition()   X-Ref
It parses a condition. It assumes the following rule:
Cond -> Expr [(">" | "<") Expr]

return: mixed The parsed ptg'd tree on success, PEAR_Error on failure

_expression()   X-Ref
It parses a expression. It assumes the following rule:
Expr -> Term [("+" | "-") Term]
-> "string"
-> "-" Term

return: mixed The parsed ptg'd tree on success, PEAR_Error on failure

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

return: array The parsed ptg'd tree

_term()   X-Ref
It parses a term. It assumes the following rule:
Term -> Fact [("*" | "/") Fact]

return: mixed The parsed ptg'd tree on success, PEAR_Error on failure

_fact()   X-Ref
It parses a factor. It assumes the following rule:
Fact -> ( Expr )
| CellRef
| CellRange
| Number
| Function

return: mixed The parsed ptg'd tree on success, PEAR_Error on failure

_func()   X-Ref
It parses a function call. It assumes the following rule:
Func -> ( Expr [,Expr]* )

return: mixed The parsed ptg'd tree on success, PEAR_Error on failure

_createTree($value, $left, $right)   X-Ref
Creates a tree. In fact an array which may have one or two arrays (sub-trees)
as elements.

param: mixed $value The value of this node.
param: mixed $left  The left array (sub-tree) or a final node.
param: mixed $right The right array (sub-tree) or a final node.
return: array A tree

toReversePolish($tree = array()   X-Ref
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

param: array $tree The optional tree to convert.
return: string The tree in reverse polish notation



Generated: Wed Dec 30 05:55:15 2009 Cross-referenced by PHPXref 0.7