Skip to content

suppressFormulaErrors is not configurable #1531

Closed
@lekoala

Description

@lekoala

This is:

- [ ] a bug report
- [x] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

If a formula is invalid, the behaviour is controlled by Calculation::raiseFormulaError that either throws an exception or triggers an error

This is controlled by the suppressFormulaErrors public variable, but there is no easy way to configure that variable at the spreadsheet level. More over, having a public variable is a bit strange (why not a config option on the spreadsheet with proper getters/setters?). Also the doc blocks of raiseFormulaError are not in line with regular docblocks

// trigger an error, but nicely, if need be
protected function raiseFormulaError($errorMessage)

It would be nice to actually allow suppressing errors to allow excel generation and not block the process because of one error in a formula (currently, both errors and exception will block the generation of the file)

As an added bonus, it would be nice if the error message could include the actual formula, in large excel file in can be a real mess to find back which formula is causing the error and why it's invalid. having the cell reference is nice, but the actual formula would be super helpful in my opinion.

What is the current behavior?

If a formula contains an error, it will trigger an error. I don't see how to throw an exception, although it wouldn't suppress anything (contrary to what the variable name would let me believe)

If you want to skip errors, you have to comment out everything in the raiseFormulaError method

// trigger an error, but nicely, if need be
protected function raiseFormulaError($errorMessage)
{
    $this->formulaError = $errorMessage;
    $this->cyclicReferenceStack->clear();
    // if (!$this->suppressFormulaErrors) {
        // throw new Exception($errorMessage);
    // }
    // trigger_error($errorMessage, E_USER_ERROR);

    return false;
}

What are the steps to reproduce?

Just make any sheet with a formula error in it, it will show a Formula Error

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// add code that show the issue here...
$sheet->setCellValueByColumnAndRow(1, 1, '=SOMEERRORFUNCTION(A1:A10)');

$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');

Which versions of PhpSpreadsheet and PHP are affected?

1.8.2 to 1.13

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions