Class Spreadsheet_Excel_Writer_Parser

Description

Class for parsing Excel formulas

Located in /libraries/pear/Spreadsheet/Excel/Writer/Parser.php (line 106)

PEAR
   |
   --Spreadsheet_Excel_Writer_Parser
Variable Summary
 integer $_BIFF_version
 integer $_byte_order
 integer $_current_char
 array $_ext_sheets
 string $_formula
 string $_lookahead
 string $_parse_tree
 array $_references
Method Summary
 Spreadsheet_Excel_Writer_Parser Spreadsheet_Excel_Writer_Parser (integer $byte_order, mixed $biff_version)
 mixed parse (string $formula)
 void setExtSheet (string $name, integer $index)
 string toReversePolish ([array $tree = array()])
 void _advance ()
 array _cellToPackedRowcol (string $cell)
 array _cellToRowcol (string $cell)
 mixed _condition ()
 mixed _convert (mixed $token)
 string _convertFunction (string $token, integer $num_args)
 void _convertNumber (mixed $num)
 void _convertRange2d (string $range)
 mixed _convertRange3d (string $token)
 string _convertRef2d (string $cell)
 mixed _convertRef3d (string $cell)
 mixed _convertString (string $string)
 array _createTree (mixed $value, mixed $left, mixed $right)
 mixed _expression ()
 mixed _fact ()
 mixed _func ()
 mixed _getRefIndex (string $ext_ref)
 integer _getSheetIndex (mixed $sheet_name)
 mixed _match (mixed $token)
 string _packExtRef (string $ext_ref)
 array _rangeToPackedRange (string $range)
 mixed _term ()
Variables
integer $_BIFF_version (line 160)

The BIFF version for the workbook

integer $_byte_order (line 142)

The byte order. 1 => big endian, 0 => little endian.

integer $_current_char (line 112)

The index of the character we are currently looking at

string $_current_token (line 118)

The token we are working on.

array $_ext_sheets (line 148)

Array of external sheets

string $_formula (line 124)

The formula to parse

string $_lookahead (line 130)

The character ahead of the current char

string $_parse_tree (line 136)

The parse tree to be generated

array $_references (line 154)

Array of sheet references in the form of REF structures

Methods
Constructor Spreadsheet_Excel_Writer_Parser (line 168)

The class constructor

Spreadsheet_Excel_Writer_Parser Spreadsheet_Excel_Writer_Parser (integer $byte_order, mixed $biff_version)
  • integer $byte_order: The byte order (Little endian or Big endian) of the architecture
parse (line 1324)

The parsing method. It parses a formula.

  • return: true on success, PEAR_Error on failure
  • access: public
mixed parse (string $formula)
  • string $formula: The formula to parse, without the initial equal sign (=).
setExtSheet (line 1018)

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.

void setExtSheet (string $name, integer $index)
  • string $name: The name of the worksheet being added
  • integer $index: The index of the worksheet being added
toReversePolish (line 1690)

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

  • return: The tree in reverse polish notation
  • access: public
string toReversePolish ([array $tree = array()])
  • array $tree: The optional tree to convert.
_advance (line 1144)

Advance to the next valid token.

  • access: private
void _advance ()
_cellToPackedRowcol (line 1030)

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

  • return: Array containing the row and column in packed() format
  • access: private
array _cellToPackedRowcol (string $cell)
  • string $cell: The Excel cell reference to be packed
_cellToRowcol (line 1114)

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.

  • access: private
array _cellToRowcol (string $cell)
  • string $cell: The Excel cell reference in A1 format.
_condition (line 1344)

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

  • return: The parsed ptg'd tree on success, PEAR_Error on failure
  • access: private
mixed _condition ()
_convert (line 539)

Convert a token to the proper ptg value.

  • return: the converted token on success. PEAR_Error if the token is not recognized
  • access: private
mixed _convert (mixed $token)
  • mixed $token: The token to convert.
_convertFunction (line 656)

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

  • return: The packed ptg for the function
  • access: private
string _convertFunction (string $token, integer $num_args)
  • string $token: The name of the function for convertion to ptg value.
  • integer $num_args: The number of arguments the function receives.
_convertNumber (line 608)

Convert a number token to ptgInt or ptgNum

  • access: private
void _convertNumber (mixed $num)
  • mixed $num: an integer or double for conversion to its ptg value
_convertRange2d (line 677)

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

  • access: private
void _convertRange2d (string $range)
  • string $range: An Excel range in the A1:A2 or A1..A2 format.
_convertRange3d (line 731)

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

  • return: The packed ptgArea3d token on success, PEAR_Error on failure.
  • access: private
mixed _convertRange3d (string $token)
  • string $token: An Excel range in the Sheet1!A1:A2 format.
_convertRef2d (line 801)

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

  • return: The cell in packed() format with the corresponding ptg
  • access: private
string _convertRef2d (string $cell)
  • string $cell: An Excel cell reference
_convertRef3d (line 837)

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

  • return: The packed ptgRef3d token on success, PEAR_Error on failure.
  • access: private
mixed _convertRef3d (string $cell)
  • string $cell: An Excel cell reference
_convertString (line 631)

Convert a string token to ptgStr

  • return: the converted token on success. PEAR_Error if the string is longer than 255 characters.
  • access: private
mixed _convertString (string $string)
  • string $string: A string for conversion to its ptg value.
_createTree (line 1658)

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

  • return: A tree
  • access: private
array _createTree (mixed $value, mixed $left, mixed $right)
  • mixed $value: The value of this node.
  • mixed $left: The left array (sub-tree) or a final node.
  • mixed $right: The right array (sub-tree) or a final node.
_expression (line 1416)

It parses a expression. It assumes the following rule:

Expr -> Term [("+" | "-") Term] -> "string" -> "-" Term

  • return: The parsed ptg'd tree on success, PEAR_Error on failure
  • access: private
mixed _expression ()
_fact (line 1523)

It parses a factor. It assumes the following rule:

Fact -> ( Expr ) | CellRef | CellRange | Number | Function

  • return: The parsed ptg'd tree on success, PEAR_Error on failure
  • access: private
mixed _fact ()
_func (line 1602)

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

  • return: The parsed ptg'd tree on success, PEAR_Error on failure
  • access: private
mixed _func ()
_getRefIndex (line 935)

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.

  • return: The reference index in packed() format on success, PEAR_Error on failure
  • access: private
mixed _getRefIndex (string $ext_ref)
  • string $ext_ref: The name of the external reference
_getSheetIndex (line 998)

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: The sheet index, -1 if the sheet was not found
  • access: private
integer _getSheetIndex (mixed $sheet_name)
_initializeHashes (line 187)

Initialize the ptg and function hashes.

  • access: private
void _initializeHashes ()
_match (line 1195)

Checks if it's a valid token.

  • return: The checked token or false on failure
  • access: private
mixed _match (mixed $token)
  • mixed $token: The token to check.
_packExtRef (line 886)

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

  • return: The reference index in packed() format
  • access: private
string _packExtRef (string $ext_ref)
  • string $ext_ref: The name of the external reference
_parenthesizedExpression (line 1468)

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

array _parenthesizedExpression ()
_rangeToPackedRange (line 1066)

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

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

  • return: Array containing (row1,col1,row2,col2) in packed() format
  • access: private
array _rangeToPackedRange (string $range)
  • string $range: The Excel range to be packed
_term (line 1481)

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

  • return: The parsed ptg'd tree on success, PEAR_Error on failure
  • access: private
mixed _term ()

Documentation generated on Fri, 11 Feb 2005 18:13:48 +0000 by phpDocumentor 1.3.0RC3