Skip to content

Commit fe12201

Browse files
committed
Documentation Update
1 parent 1e6668f commit fe12201

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/topics/accessing-cells.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ $spreadsheet->getActiveSheet()
4242
If you make a call to `getCell()`, and the cell doesn't already exist, then
4343
PhpSpreadsheet will create that cell for you.
4444

45+
### Copying a Cell's Value And Style Adjusting Formulas
46+
47+
If cell A1 contains `5`, cell A2 contains `10`, and cell `B1` contains `=A1`, the formula in B1 will be evaluated as `5`. In Excel, if you copy B1 to B2, B2 will wind up with the adjusted formula `=A2` and will be evaluated as 10. Until release 5.1.0, PhpSpreadsheet requires the program to perform its own formula adjustment. In 5.1.0, a new method is introduced to handle formula adjustments:
48+
```php
49+
$worksheet->copyformula($fromCell, $toCell);
50+
```
51+
This will behave as Excel does. If $fromCell does not contain a formula, its contents will be copied as-is.
52+
53+
If you also want to copy $fromCell's style, as Excel does, you can use the following (available in all supported releases):
54+
```php
55+
$worksheet->duplicateStyle($fromCell->getStyle(), $toCell);
56+
```
57+
4558
### BEWARE: Cells and Styles assigned to variables as a Detached Reference
4659

4760
As an "in-memory" model, PHPSpreadsheet can be very demanding of memory,

0 commit comments

Comments
 (0)