Handle the case of an invalid formula by defaulting to ptgInt + 0, which will avoid breaking the file

This commit is contained in:
MarkBaker 2022-03-13 10:53:07 +01:00
parent 83161de91e
commit a6e792082b
3 changed files with 9 additions and 9 deletions

View File

@ -102,9 +102,9 @@ $expressionWizard->expression('ISEVEN(A1)')
->setStyle($yellowStyle); ->setStyle($yellowStyle);
$conditionalStyles[] = $expressionWizard->getConditional(); $conditionalStyles[] = $expressionWizard->getConditional();
//$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
// ->getStyle($expressionWizard->getCellRange()) ->getStyle($expressionWizard->getCellRange())
// ->setConditionalStyles($conditionalStyles); ->setConditionalStyles($conditionalStyles);
// Set rules for Sales Grid Row match against Country Comparison // Set rules for Sales Grid Row match against Country Comparison
$cellRange = 'A17:D22'; $cellRange = 'A17:D22';

View File

@ -55,11 +55,11 @@ class ConditionalHelper
$formula = Wizard\WizardAbstract::reverseAdjustCellRef((string) $condition, $cellRange); $formula = Wizard\WizardAbstract::reverseAdjustCellRef((string) $condition, $cellRange);
$this->parser->parse($formula); $this->parser->parse($formula);
$this->tokens = $this->parser->toReversePolish(); $this->tokens = $this->parser->toReversePolish();
$this->size = strlen($this->tokens); $this->size = strlen($this->tokens ?? '');
} catch (PhpSpreadsheetException $e) { } catch (PhpSpreadsheetException $e) {
var_dump("PARSER EXCEPTION: {$e->getMessage()}"); // In the event of a parser error with a formula value, we set the expression to ptgInt + 0
$this->tokens = null; $this->tokens = pack('Cv', 0x1E, 0);
$this->size = 0; $this->size = 3;
} }
} }
} }