nopSolutions/nopCommerce · error · NopException
No worksheet found
Error message
No worksheet found
What it means
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.
Source
Thrown at src/Libraries/Nop.Services/ExportImport/ImportManager.cs:1856
}
}
#endregion
#region Methods
/// <summary>
/// Get excel workbook metadata
/// </summary>
/// <typeparam name="T">Type of object</typeparam>
/// <param name="workbook">Excel workbook</param>
/// <param name="languages">Languages</param>
/// <returns>Workbook metadata</returns>
public static WorkbookMetadata<T> GetWorkbookMetadata<T>(IXLWorkbook workbook, IList<Language> languages)
{
// get the first worksheet in the workbook
var worksheet = workbook.Worksheets.FirstOrDefault()
?? throw new NopException("No worksheet found");
var properties = new List<PropertyByName<T>>();
var localizedProperties = new List<PropertyByName<T>>();
var localizedWorksheets = new List<IXLWorksheet>();
var poz = 1;
while (true)
{
try
{
var cell = worksheet.Row(1).Cell(poz);
if (string.IsNullOrEmpty(cell?.Value.ToString()))
break;
poz += 1;
properties.Add(new PropertyByName<T>(cell.Value.ToString()));
}
View on GitHub (pinned to 64bdf2ff08)
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.
Example fix
// before
var metadata = ImportManager.GetWorkbookMetadata<Product>(workbook, languages);
// after — guard against an empty workbook
if (!workbook.Worksheets.Any())
throw new InvalidOperationException("The uploaded workbook has no worksheets. Re-export a valid XLSX template and try again.");
var metadata = ImportManager.GetWorkbookMetadata<Product>(workbook, languages); Defensive patterns
Strategy: validation
Validate before calling
// Ensure the workbook has at least one worksheet before reading metadata
if (workbook == null || !workbook.Worksheets.Any())
throw new InvalidOperationException("The uploaded workbook has no worksheets. Re-export a valid XLSX and retry.");
var metadata = ImportManager.GetWorkbookMetadata<Product>(workbook, languages); Type guard
static bool HasReadableWorksheet(IXLWorkbook wb) => wb?.Worksheets?.Any() == true;
Try / catch
try { metadata = ImportManager.GetWorkbookMetadata<Product>(workbook, languages); }
catch (NopException ex) when (ex.Message == "No worksheet found")
{ /* ask the user to re-upload a valid XLSX with at least one sheet */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Admin.Catalog.Products.RelatedProducts.CyclicallyRelated ({c
- Wrong file format
- Wrong file format
- Email is not valid.
- {titleRequiredLocale} (localized, formatted with languageNam
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/5c8e033e80418c56.
Report an issue: GitHub.