Skip to content

Commit a6e7920

Browse files
author
MarkBaker
committed
Handle the case of an invalid formula by defaulting to ptgInt + 0, which will avoid breaking the file
1 parent 83161de commit a6e7920

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

samples/ConditionalFormatting/07_Expression_Comparisons.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@
102102
->setStyle($yellowStyle);
103103
$conditionalStyles[] = $expressionWizard->getConditional();
104104

105-
//$spreadsheet->getActiveSheet()
106-
// ->getStyle($expressionWizard->getCellRange())
107-
// ->setConditionalStyles($conditionalStyles);
105+
$spreadsheet->getActiveSheet()
106+
->getStyle($expressionWizard->getCellRange())
107+
->setConditionalStyles($conditionalStyles);
108108

109109
// Set rules for Sales Grid Row match against Country Comparison
110110
$cellRange = 'A17:D22';

src/PhpSpreadsheet/Writer/Xls/ConditionalHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ public function processCondition($condition, string $cellRange): void
5555
$formula = Wizard\WizardAbstract::reverseAdjustCellRef((string) $condition, $cellRange);
5656
$this->parser->parse($formula);
5757
$this->tokens = $this->parser->toReversePolish();
58-
$this->size = strlen($this->tokens);
58+
$this->size = strlen($this->tokens ?? '');
5959
} catch (PhpSpreadsheetException $e) {
60-
var_dump("PARSER EXCEPTION: {$e->getMessage()}");
61-
$this->tokens = null;
62-
$this->size = 0;
60+
// In the event of a parser error with a formula value, we set the expression to ptgInt + 0
61+
$this->tokens = pack('Cv', 0x1E, 0);
62+
$this->size = 3;
6363
}
6464
}
6565
}

src/PhpSpreadsheet/Writer/Xls/Worksheet.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,8 +2787,8 @@ private function writeCFRule(
27872787
string $cellRange
27882788
): void {
27892789
$record = 0x01B1; // Record identifier
2790-
$type = null; // Type of the CF
2791-
$operatorType = null; // Comparison operator
2790+
$type = null; // Type of the CF
2791+
$operatorType = null; // Comparison operator
27922792

27932793
if ($conditional->getConditionType() == Conditional::CONDITION_EXPRESSION) {
27942794
$type = 0x02;

0 commit comments

Comments
 (0)