Skip to content

Commit 190af74

Browse files
committed
Add FormulaRange to IgnoredErrors Possibilities
When I implemented IgnoredErrors (PR PHPOffice#3508), I dealt only with those that I understood well enough to come up with an example. I finally found an example for FormulaRange in the wild, so this PR adds it. Still unsupported are `calculatedColumn`, `emptyCellReferece`, `listDataValidation`, and `unlockedFormula`.
1 parent 875dc35 commit 190af74

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

src/PhpSpreadsheet/Cell/IgnoredErrors.php

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class IgnoredErrors
88

99
private bool $formula = false;
1010

11+
private bool $formulaRange = false;
12+
1113
private bool $twoDigitTextYear = false;
1214

1315
private bool $evalError = false;
@@ -36,6 +38,18 @@ public function getFormula(): bool
3638
return $this->formula;
3739
}
3840

41+
public function setFormulaRange(bool $value): self
42+
{
43+
$this->formulaRange = $value;
44+
45+
return $this;
46+
}
47+
48+
public function getFormulaRange(): bool
49+
{
50+
return $this->formulaRange;
51+
}
52+
3953
public function setTwoDigitTextYear(bool $value): self
4054
{
4155
$this->twoDigitTextYear = $value;

src/PhpSpreadsheet/Reader/Xlsx.php

+4
Original file line numberDiff line numberDiff line change
@@ -2374,6 +2374,7 @@ private function processIgnoredErrors(SimpleXMLElement $xml, Worksheet $sheet):
23742374
$sqref = (string) ($attributes['sqref'] ?? '');
23752375
$numberStoredAsText = (string) ($attributes['numberStoredAsText'] ?? '');
23762376
$formula = (string) ($attributes['formula'] ?? '');
2377+
$formulaRange = (string) ($attributes['formulaRange'] ?? '');
23772378
$twoDigitTextYear = (string) ($attributes['twoDigitTextYear'] ?? '');
23782379
$evalError = (string) ($attributes['evalError'] ?? '');
23792380
if (!empty($sqref)) {
@@ -2403,6 +2404,9 @@ private function processIgnoredErrors(SimpleXMLElement $xml, Worksheet $sheet):
24032404
if ($formula === '1') {
24042405
$sheet->getCell("$col$row")->getIgnoredErrors()->setFormula(true);
24052406
}
2407+
if ($formulaRange === '1') {
2408+
$sheet->getCell("$col$row")->getIgnoredErrors()->setFormulaRange(true);
2409+
}
24062410
if ($twoDigitTextYear === '1') {
24072411
$sheet->getCell("$col$row")->getIgnoredErrors()->setTwoDigitTextYear(true);
24082412
}

src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class Worksheet extends WriterPart
2727

2828
private string $formula = '';
2929

30+
private string $formulaRange = '';
31+
3032
private string $twoDigitTextYear = '';
3133

3234
private string $evalError = '';
@@ -50,6 +52,7 @@ public function writeWorksheet(PhpspreadsheetWorksheet $worksheet, array $string
5052
$worksheet->calculateArrays($this->getParentWriter()->getPreCalculateFormulas());
5153
$this->numberStoredAsText = '';
5254
$this->formula = '';
55+
$this->formulaRange = '';
5356
$this->twoDigitTextYear = '';
5457
$this->evalError = '';
5558
// Create XML writer
@@ -180,6 +183,7 @@ private function writeIgnoredErrors(XMLWriter $objWriter): void
180183
$started = false;
181184
$this->writeIgnoredError($objWriter, $started, 'numberStoredAsText', $this->numberStoredAsText);
182185
$this->writeIgnoredError($objWriter, $started, 'formula', $this->formula);
186+
$this->writeIgnoredError($objWriter, $started, 'formulaRange', $this->formulaRange);
183187
$this->writeIgnoredError($objWriter, $started, 'twoDigitTextYear', $this->twoDigitTextYear);
184188
$this->writeIgnoredError($objWriter, $started, 'evalError', $this->evalError);
185189
if ($started) {
@@ -1392,6 +1396,9 @@ private function writeSheetData(XMLWriter $objWriter, PhpspreadsheetWorksheet $w
13921396
if ($worksheet->getCell($coord)->getIgnoredErrors()->getFormula()) {
13931397
$this->formula .= " $coord";
13941398
}
1399+
if ($worksheet->getCell($coord)->getIgnoredErrors()->getFormulaRange()) {
1400+
$this->formulaRange .= " $coord";
1401+
}
13951402
if ($worksheet->getCell($coord)->getIgnoredErrors()->getTwoDigitTextYear()) {
13961403
$this->twoDigitTextYear .= " $coord";
13971404
}

tests/PhpSpreadsheetTests/Reader/Xlsx/IgnoredErrorTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public function testIgnoredError(): void
3838

3939
self::assertFalse($sheet->getCell('C12')->getIgnoredErrors()->getEvalError());
4040
self::assertTrue($sheet->getCell('C11')->getIgnoredErrors()->getEvalError());
41+
self::assertFalse($sheet->getCell('E14')->getIgnoredErrors()->getFormulaRange());
42+
self::assertTrue($sheet->getCell('F14')->getIgnoredErrors()->getFormulaRange());
4143

4244
$sheetLast = $spreadsheet->getSheetByNameOrThrow('Last');
4345
self::assertFalse($sheetLast->getCell('D2')->getIgnoredErrors()->getFormula());
-574 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)