{"record":{"id":"5c8e033e80418c56","repo":"nopSolutions/nopCommerce","slug":"no-worksheet-found","errorCode":null,"errorMessage":"No worksheet found","messagePattern":"No worksheet found","errorType":"validation","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/ExportImport/ImportManager.cs","lineNumber":1856,"sourceCode":"        }\r\n    }\r\n\r\n    #endregion\r\n\r\n    #region Methods\r\n\r\n    /// <summary>\r\n    /// Get excel workbook metadata\r\n    /// </summary>\r\n    /// <typeparam name=\"T\">Type of object</typeparam>\r\n    /// <param name=\"workbook\">Excel workbook</param>\r\n    /// <param name=\"languages\">Languages</param>\r\n    /// <returns>Workbook metadata</returns>\r\n    public static WorkbookMetadata<T> GetWorkbookMetadata<T>(IXLWorkbook workbook, IList<Language> languages)\r\n    {\r\n        // get the first worksheet in the workbook\r\n        var worksheet = workbook.Worksheets.FirstOrDefault()\r\n                        ?? throw new NopException(\"No worksheet found\");\r\n\r\n        var properties = new List<PropertyByName<T>>();\r\n        var localizedProperties = new List<PropertyByName<T>>();\r\n        var localizedWorksheets = new List<IXLWorksheet>();\r\n\r\n        var poz = 1;\r\n        while (true)\r\n        {\r\n            try\r\n            {\r\n                var cell = worksheet.Row(1).Cell(poz);\r\n\r\n                if (string.IsNullOrEmpty(cell?.Value.ToString()))\r\n                    break;\r\n\r\n                poz += 1;\r\n                properties.Add(new PropertyByName<T>(cell.Value.ToString()));\r\n            }\r","sourceCodeStart":1838,"sourceCodeEnd":1874,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/ExportImport/ImportManager.cs#L1838-L1874","documentation":"Thrown by the static GetWorkbookMetadata<T> helper when the supplied IXLWorkbook contains no worksheets (workbook.Worksheets.FirstOrDefault() returns null). nopCommerce needs at least one worksheet to read the import template's header row, so an empty workbook is rejected with a NopException.","triggerScenarios":"Calling GetWorkbookMetadata with an IXLWorkbook that has zero worksheets — e.g. an empty/corrupt XLSX, a file that is not actually XLSX, or a programmatically created workbook to which no sheet was added. Reached during category/product/order import setup.","commonSituations":"Uploading a zero-byte or wrong-type file (e.g. CSV renamed to .xlsx, a PDF, or an HTML export); a workbook constructed in code without adding a worksheet; a corrupted download/export; an older Office version saving a format ClosedXML cannot read as a worksheet.","solutions":["Validate the file is a real XLSX and opens in Excel; re-export from nopCommerce's own export to get a known-good template.","If generating the workbook in code, add at least one worksheet (workbook.AddWorksheet('Sheet1')) before calling GetWorkbookMetadata.","Check the uploaded file is not empty/corrupt (stream.Length > 0 and valid ZIP/XLSX magic bytes).","Wrap the call and surface a user-friendly 'the uploaded file has no sheets' message."],"exampleFix":"// before\nvar metadata = ImportManager.GetWorkbookMetadata<Product>(workbook, languages);\n\n// after — guard against an empty workbook\nif (!workbook.Worksheets.Any())\n    throw new InvalidOperationException(\"The uploaded workbook has no worksheets. Re-export a valid XLSX template and try again.\");\nvar metadata = ImportManager.GetWorkbookMetadata<Product>(workbook, languages);","handlingStrategy":"validation","validationCode":"// Ensure the workbook has at least one worksheet before reading metadata\nif (workbook == null || !workbook.Worksheets.Any())\n    throw new InvalidOperationException(\"The uploaded workbook has no worksheets. Re-export a valid XLSX and retry.\");\nvar metadata = ImportManager.GetWorkbookMetadata<Product>(workbook, languages);","typeGuard":"static bool HasReadableWorksheet(IXLWorkbook wb) => wb?.Worksheets?.Any() == true;","tryCatchPattern":"try { metadata = ImportManager.GetWorkbookMetadata<Product>(workbook, languages); }\ncatch (NopException ex) when (ex.Message == \"No worksheet found\")\n{ /* ask the user to re-upload a valid XLSX with at least one sheet */ }","preventionTips":["Validate the uploaded file is a real XLSX (ZIP magic bytes) before parsing.","When building workbooks in code, always add a worksheet first.","Re-export templates from nopCommerce to guarantee a known-good structure."],"tags":["import","excel","closedxml","validation","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}