PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception

First argument needs to be a range

Error message

First argument needs to be a range

What it means

Error "First argument needs to be a range" thrown in PHPOffice/PhpSpreadsheet.

Source

Thrown at src/PhpSpreadsheet/Cell/Coordinate.php:347

        $data['localReference'] = str_replace('$', '', $matches['localReference']);

        return $data;
    }

    /**
     * Check if coordinate is inside a range.
     *
     * @param string $range Cell range, Single Cell, Row/Column Range (e.g. A1:A1, B2, B:C, 2:3)
     * @param string $coordinate Cell coordinate (e.g. A1)
     *
     * @return bool true if coordinate is inside range
     */
    public static function coordinateIsInsideRange(string $range, string $coordinate): bool
    {
        $range = Validations::convertWholeRowColumn($range);
        $rangeData = self::validateReferenceAndGetData($range);
        if ($rangeData['type'] === 'invalid') {
            throw new Exception('First argument needs to be a range');
        }

        $coordinateData = self::validateReferenceAndGetData($coordinate);
        if ($coordinateData['type'] === 'invalid') {
            throw new Exception('Second argument needs to be a single coordinate');
        }

        if (isset($coordinateData['worksheet']) && !isset($rangeData['worksheet'])) {
            return false;
        }
        if (!isset($coordinateData['worksheet']) && isset($rangeData['worksheet'])) {
            return false;
        }

        if (isset($coordinateData['worksheet'], $rangeData['worksheet'])) {
            if ($coordinateData['worksheet'] !== $rangeData['worksheet']) {
                return false;
            }

View on GitHub (pinned to 65b080eef4)

When it happens

Trigger: Thrown at src/PhpSpreadsheet/Cell/Coordinate.php:347 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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