\PHPExcel_Writer_Excel5_Parser

PHPExcel_Writer_Excel5_Parser

Copyright (c) 2006 - 2015 PHPExcel

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Summary

Methods
Properties
Constants
__construct()
setExtSheet()
parse()
toReversePolish()
$currentCharacter
$currentToken
$lookAhead
$references
REGEX_SHEET_TITLE_UNQUOTED
REGEX_SHEET_TITLE_QUOTED
No protected methods found
No protected properties found
N/A
initializeHashes()
convert()
convertNumber()
convertString()
convertFunction()
convertRange2d()
convertRange3d()
convertRef2d()
convertRef3d()
convertError()
packExtRef()
getRefIndex()
getSheetIndex()
cellToPackedRowcol()
rangeToPackedRange()
cellToRowcol()
advance()
match()
condition()
expression()
parenthesizedExpression()
term()
fact()
func()
createTree()
$formula
$parseTree
$externalSheets
N/A

Constants

REGEX_SHEET_TITLE_UNQUOTED

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

REGEX_SHEET_TITLE_QUOTED

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

Properties

$currentCharacter

$currentCharacter : integer

The index of the character we are currently looking at

Type

integer

$currentToken

$currentToken : string

The token we are working on.

Type

string

$lookAhead

$lookAhead : string

The character ahead of the current char

Type

string

$references

$references : array

Array of sheet references in the form of REF structures

Type

array

$formula

$formula : string

The formula to parse

Type

string

$parseTree

$parseTree : string

The parse tree to be generated

Type

string

$externalSheets

$externalSheets : array

Array of external sheets

Type

array

Methods

__construct()

__construct() 

The class constructor

setExtSheet()

setExtSheet(string  $name, integer  $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.

Parameters

string $name

The name of the worksheet being added

integer $index

The index of the worksheet being added

parse()

parse(string  $formula) : mixed

The parsing method. It parses a formula.

Parameters

string $formula

The formula to parse, without the initial equal sign (=).

Returns

mixed —

true on success

toReversePolish()

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

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

Parameters

array $tree

The optional tree to convert.

Returns

string —

The tree in reverse polish notation

initializeHashes()

initializeHashes() 

Initialize the ptg and function hashes.

convert()

convert(mixed  $token) : mixed

Convert a token to the proper ptg value.

Parameters

mixed $token

The token to convert.

Returns

mixed —

the converted token on success

convertNumber()

convertNumber(mixed  $num) 

Convert a number token to ptgInt or ptgNum

Parameters

mixed $num

an integer or double for conversion to its ptg value

convertString()

convertString(string  $string) : mixed

Convert a string token to ptgStr

Parameters

string $string

A string for conversion to its ptg value.

Returns

mixed —

the converted token on success

convertFunction()

convertFunction(string  $token, integer  $num_args) : string

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

Parameters

string $token

The name of the function for convertion to ptg value.

integer $num_args

The number of arguments the function receives.

Returns

string —

The packed ptg for the function

convertRange2d()

convertRange2d(string  $range, integer  $class) 

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

Parameters

string $range

An Excel range in the A1:A2

integer $class

convertRange3d()

convertRange3d(string  $token) : mixed

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

Parameters

string $token

An Excel range in the Sheet1!A1:A2 format.

Returns

mixed —

The packed ptgArea3d token on success.

convertRef2d()

convertRef2d(string  $cell) : string

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

Parameters

string $cell

An Excel cell reference

Returns

string —

The cell in packed() format with the corresponding ptg

convertRef3d()

convertRef3d(string  $cell) : mixed

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

Parameters

string $cell

An Excel cell reference

Returns

mixed —

The packed ptgRef3d token on success.

convertError()

convertError(string  $errorCode) : string

Convert an error code to a ptgErr

Parameters

string $errorCode

The error code for conversion to its ptg value

Returns

string —

The error code ptgErr

packExtRef()

packExtRef(string  $ext_ref) : string

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

Parameters

string $ext_ref

The name of the external reference

Returns

string —

The reference index in packed() format

getRefIndex()

getRefIndex(string  $ext_ref) : mixed

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.

Parameters

string $ext_ref

The name of the external reference

Returns

mixed —

The reference index in packed() format on success

getSheetIndex()

getSheetIndex(string  $sheet_name) : integer

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.

Parameters

string $sheet_name

Sheet name

Returns

integer —

The sheet index, -1 if the sheet was not found

cellToPackedRowcol()

cellToPackedRowcol(string  $cell) : array

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

Parameters

string $cell

The Excel cell reference to be packed

Returns

array —

Array containing the row and column in packed() format

rangeToPackedRange()

rangeToPackedRange(string  $range) : array

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

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

Parameters

string $range

The Excel range to be packed

Returns

array —

Array containing (row1,col1,row2,col2) in packed() format

cellToRowcol()

cellToRowcol(string  $cell) : array

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.

Parameters

string $cell

The Excel cell reference in A1 format.

Returns

array

advance()

advance() 

Advance to the next valid token.

match()

match(mixed  $token) : mixed

Checks if it's a valid token.

Parameters

mixed $token

The token to check.

Returns

mixed —

The checked token or false on failure

condition()

condition() : mixed

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

Returns

mixed —

The parsed ptg'd tree on success

expression()

expression() : mixed

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

Returns

mixed —

The parsed ptg'd tree on success

parenthesizedExpression()

parenthesizedExpression() : array

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

Returns

array —

The parsed ptg'd tree

term()

term() : mixed

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

Returns

mixed —

The parsed ptg'd tree on success

fact()

fact() : mixed

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

Returns

mixed —

The parsed ptg'd tree on success

func()

func() : mixed

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

Returns

mixed —

The parsed ptg'd tree on success

createTree()

createTree(mixed  $value, mixed  $left, mixed  $right) : array

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

Parameters

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.

Returns

array —

A tree