PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Calculation\Exception

Formulae with more than two array arguments are not supporte

Error message

Formulae with more than two array arguments are not supported

What it means

PhpSpreadsheet's array-argument engine handles at most two array (multi-cell) arguments per function call. ArrayArgumentHelper::initialize() counts arguments whose rows>1 or columns>1 after flattening single-cell arrays, and throws this exception as soon as a third array argument appears, instead of evaluating the formula. It is a deliberate engine limitation, not an input-formatting mistake.

Source

Thrown at src/PhpSpreadsheet/Calculation/Engine/ArrayArgumentHelper.php:37

    /** @var int[] */
    protected array $columns;

    /** @param mixed[] $arguments */
    public function initialise(array $arguments): void
    {
        $keys = array_keys($arguments);
        $this->indexStart = (int) array_shift($keys);
        $this->rows = $this->rows($arguments);
        $this->columns = $this->columns($arguments);

        $this->argumentCount = count($arguments);
        $this->arguments = $this->flattenSingleCellArrays($arguments, $this->rows, $this->columns);

        $this->rows = $this->rows($arguments);
        $this->columns = $this->columns($arguments);

        if ($this->arrayArguments() > 2) {
            throw new Exception('Formulae with more than two array arguments are not supported');
        }
    }

    /** @return mixed[] */
    public function arguments(): array
    {
        return $this->arguments;
    }

    public function hasArrayArgument(): bool
    {
        return $this->arrayArguments() > 0;
    }

    public function getFirstArrayArgumentNumber(): int
    {
        $rowArrays = $this->filterArray($this->rows);
        $columnArrays = $this->filterArray($this->columns);

View on GitHub (pinned to 65b080eef4)

Solutions

  1. Rewrite the formula to use at most two array arguments per operation - e.g. =SUMPRODUCT(A1:A3*B1:B3*C1:C3) (SUMPRODUCT natively takes multiple ranges) or nest/chunk the multiplication.
  2. Split the computation into intermediate helper columns/cells and aggregate the scalars afterwards.
  3. When importing untrusted workbooks, wrap calculation in try/catch on PhpOffice\PhpSpreadsheet\Calculation\Exception and report the offending cell for manual rework.
  4. Pre-scan formula strings for three or more range operands (A1:B2 patterns) before calculating to flag risky cells.

Example fix

// before - throws 'Formulae with more than two array arguments are not supported'
$sheet->getCell('E1')->setValue('=SUM(A1:A3*B1:B3*C1:C3)');

// after - SUMPRODUCT accepts any number of arrays
$sheet->getCell('E1')->setValue('=SUMPRODUCT(A1:A3*B1:B3*C1:C3)');
Defensive patterns

Strategy: try-catch

Validate before calling

// Cheap pre-flight when importing formulas: flag cells whose formula shows
// three or more range operands in one expression.
function hasTooManyArrayOperands(string $formula): bool
{
    preg_match_all('/[A-Za-z]+!?\$?[A-Z]{1,3}\$?\d+:\$?[A-Z]{1,3}\$?\d+/', $formula, $m);
    return count(array_unique($m[0])) > 2;
}

Try / catch

use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;

try {
    $value = $cell->calculate(); // evaluates the cell's formula
} catch (CalcException $e) {
    // 'Formulae with more than two array arguments are not supported'
    $logger->warning('Unsupported array formula at ' . $cell->getCoordinate() . ': ' . $e->getMessage());
    $value = null;
}

Prevention

When it happens

Trigger: Array formulas like =SUM(A1:A3*B1:B3*C1:C3) where three ranges feed one operation; expressions like =ROUND(A1:A3+B1:B3*C1:C3, D1:D3); calling any ArrayEnabled calculation function directly with three array parameters (it routes through evaluateArrayArguments -> ArrayArgumentProcessor -> this check).

Common situations: Porting Excel workbooks that rely on legacy CSE array formulas or dynamic arrays with three-plus ranges; array-heavy financial models; upgrading from PHPExcel-era code where such formulas degraded to scalar behaviour instead of throwing.

Related errors


AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17). Data as JSON: /api/errors/8f18479c5bde1eab. Report an issue: GitHub.