{"record":{"id":"bdf73726950e4266","repo":"PHPOffice/PhpSpreadsheet","slug":"filename-is-an-invalid-spreadsheet-file-bdf737","errorCode":null,"errorMessage":"$filename is an Invalid Spreadsheet file.","messagePattern":"\\$filename is an Invalid Spreadsheet file\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Reader\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Reader/Xml.php","lineNumber":189,"sourceCode":"        $xml_ss = $xml->children(self::NAMESPACES_SS);\n        foreach ($xml_ss->Worksheet as $worksheet) {\n            $worksheet_ss = self::getAttributes($worksheet, self::NAMESPACES_SS);\n            $worksheetNames[] = (string) $worksheet_ss['Name'];\n        }\n\n        return $worksheetNames;\n    }\n\n    /**\n     * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns).\n     *\n     * @return array<int, array{worksheetName: string, lastColumnLetter: string, lastColumnIndex: int, totalRows: int, totalColumns: int, sheetState: string}>\n     */\n    public function listWorksheetInfo(string $filename): array\n    {\n        File::assertFile($filename);\n        if (!$this->canRead($filename)) {\n            throw new Exception($filename . ' is an Invalid Spreadsheet file.');\n        }\n\n        $worksheetInfo = [];\n\n        $xml = $this->trySimpleXMLLoadStringPrivate($filename);\n        if ($xml === false) {\n            throw new Exception(\"Problem reading {$filename}\");\n        }\n\n        $worksheetID = 1;\n        $xml_ss = $xml->children(self::NAMESPACES_SS);\n        foreach ($xml_ss->Worksheet as $worksheet) {\n            $worksheet_ss = self::getAttributes($worksheet, self::NAMESPACES_SS);\n\n            $tmpInfo = [];\n            $tmpInfo['worksheetName'] = '';\n            $tmpInfo['lastColumnLetter'] = 'A';\n            $tmpInfo['lastColumnIndex'] = 0;","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Reader/Xml.php#L171-L207","documentation":"listWorksheetInfo() performs the same canRead() signature check as the other Xml entry points; missing XML declaration or missing Office spreadssheet namespace makes the reader refuse the file before parsing sheet metadata.","triggerScenarios":"Passing a non-SpreadsheetML file (binary .xls, .xlsx zip, generic XML, HTML) to the Xml reader's listWorksheetInfo(); files whose namespace prefix differs (no xmlns:ss binding).","commonSituations":"Format-detection skipped in favor of a hardcoded reader; uploads whose extension does not match content; XML from non-Microsoft tools lacking the Office namespace.","solutions":["Branch on IOFactory::identify() and only call listWorksheetInfo() when the type is 'Xml'","Pre-check with canRead() and reject early with a clear message","Convert genuine Excel files to SpreadsheetML or use the Xls/Xlsx readers"],"exampleFix":"// before\n$info = (new \\PhpOffice\\PhpSpreadsheet\\Reader\\Xml())->listWorksheetInfo('data.xls');\n\n// after\n$reader = new \\PhpOffice\\PhpSpreadsheet\\Reader\\Xml();\nif (!$reader->canRead('data.xls')) {\n    throw new RuntimeException('Please upload an Excel 2003 XML Spreadsheet');\n}\n$info = $reader->listWorksheetInfo('data.xls');","handlingStrategy":"validation","validationCode":"$reader = new \\PhpOffice\\PhpSpreadsheet\\Reader\\Xml();\nif (!$reader->canRead($path)) {\n    throw new InvalidArgumentException('Unsupported format; SpreadsheetML required');\n}\n$info = $reader->listWorksheetInfo($path);","typeGuard":"function isSpreadsheetMl(string $path): bool\n{\n    return (new \\PhpOffice\\PhpSpreadsheet\\Reader\\Xml())->canRead($path);\n}","tryCatchPattern":null,"preventionTips":["Branch on IOFactory::identify() before choosing a reader","Check canRead() and fail fast with a user-facing format message","Convert genuine Excel files rather than forcing them through the XML reader"],"tags":["xml","spreadsheetml","format-detection","phpspreadsheet"],"backgroundTag":"wrong-file-format","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}