Skip to content

Commit 42dde14

Browse files
author
MarkBaker
committed
Merge branch 'CalculationEngine-Array-Formulae-Initial-Work' into 2.0-Development
2 parents 0a34ce8 + a40c708 commit 42dde14

File tree

61 files changed

+2261
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2261
-267
lines changed

docs/topics/accessing-cells.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ Formats handled by the advanced value binder include:
131131
- TRUE or FALSE (dependent on locale settings) are converted to booleans.
132132
- Numeric strings identified as scientific (exponential) format are
133133
converted to numbers.
134-
- Fractions and vulgar fractions are converted to numbers, and
134+
- Fractions and "vulgar" fractions are converted to numbers, and
135135
an appropriate number format mask applied.
136-
- Percentages are converted
137-
to numbers, divided by 100, and an appropriate number format mask
136+
- Percentages are converted to numbers, divided by 100, and an
137+
appropriate number format mask
138138
applied.
139139
- Dates and times are converted to Excel timestamp values
140140
(numbers), and an appropriate number format mask applied.

docs/topics/calculation-engine.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ formula calculation capabilities. A cell can be of a value type
1010
which can be evaluated). For example, the formula `=SUM(A1:A10)`
1111
evaluates to the sum of values in A1, A2, ..., A10.
1212

13+
Calling `getValue()` on a cell that contains a formula will return the formula itself.
14+
1315
To calculate a formula, you can call the cell containing the formula’s
1416
method `getCalculatedValue()`, for example:
1517

@@ -22,6 +24,30 @@ with PhpSpreadsheet, it evaluates to the value "64":
2224

2325
![09-command-line-calculation.png](./images/09-command-line-calculation.png)
2426

27+
Calling `getCalculatedValue()` on a cell that doesn't contain a formula will simply return the value of that cell; but if the cell does contain a formula, then PhpSpreadsheet will evaluate that formula to calculate the result.
28+
29+
There are a few useful mehods to help identify whether a cell contains a formula or a simple value; and if a formula, to provide further information about it:
30+
31+
```php
32+
$spreadsheet->getActiveSheet()->getCell('E11')->isFormula();
33+
```
34+
will return a boolean true/false, telling you whether that cell contains a formula or not, so you can determine if a call to `getCalculatedVaue()` will need to perform an evaluation.
35+
36+
A formula can be either a simple formula, or an array formula; and another method will identify which it is:
37+
```php
38+
$spreadsheet->getActiveSheet()->getCell('E11')->isArrayFormula();
39+
```
40+
Finally, an array formula might result in a single cell result, or a result that can spill over into a range of cells; so for array formulae the following method also exists:
41+
```php
42+
$spreadsheet->getActiveSheet()->getCell('E11')->arrayFormulaRange();
43+
```
44+
which returns a string containing a cell reference (e.g. `E11`) or a cell range reference (e.g. `E11:G13`).
45+
46+
47+
For more details on working with array formulae, see the [the recipes documentationn](./recipes.md/#array-formulae).
48+
49+
### Adjustments to formulae when Inserting/Deleting Columns/Rows
50+
2551
Another nice feature of PhpSpreadsheet's formula parser, is that it can
2652
automatically adjust a formula when inserting/removing rows/columns.
2753
Here's an example:
@@ -79,6 +105,11 @@ formula calculation is subject to PHP's language characteristics.
79105
Not all functions are supported, for a comprehensive list, read the
80106
[function list by name](../references/function-list-by-name.md).
81107

108+
#### Array arguments for Function Calls in Formulae
109+
110+
While most of the Excel function implementations now support array arguments, there are a few that should accept arrays as arguments but don't do so.
111+
In these cases, the result may be a single value rather than an array; or it may be a `#VALUE!` error.
112+
82113
#### Operator precedence
83114

84115
In Excel `+` wins over `&`, just like `*` wins over `+` in ordinary
@@ -100,7 +131,7 @@ content.
100131

101132
- [Reference for this behaviour in PHP](https://php.net/manual/en/language.types.string.php#language.types.string.conversion)
102133

103-
#### Formulas don’t seem to be calculated in Excel2003 using compatibility pack?
134+
#### Formulae don’t seem to be calculated in Excel2003 using compatibility pack?
104135

105136
This is normal behaviour of the compatibility pack, Xlsx displays this
106137
correctly. Use `\PhpOffice\PhpSpreadsheet\Writer\Xls` if you really need
@@ -149,8 +180,7 @@ number of seconds from the PHP/Unix base date. The PHP/Unix base date
149180
(0) is 00:00 UST on 1st January 1970. This value can be positive or
150181
negative: so a value of -3600 would be 23:00 hrs on 31st December 1969;
151182
while a value of +3600 would be 01:00 hrs on 1st January 1970. This
152-
gives PHP a date range of between 14th December 1901 and 19th January
153-
2038.
183+
gives 32-bit PHP a date range of between 14th December 1901 and 19th January 2038.
154184

155185
#### PHP `DateTime` Objects
156186

Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)