iOfficeAI/OfficeCLI · error · ArgumentException
Sheet not found: {sheetName}
Error message
Sheet not found: {sheetName} What it means
Thrown by ExcelHandler.Import when the sheet name parsed from the parentPath does not resolve to any worksheet via FindWorksheet. The parentPath's first segment (after stripping leading '/') is treated as the sheet name; a missing or misspelled name fails here before any CSV parsing begins.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Import.cs:28
public partial class ExcelHandler
{
/// <summary>
/// Import CSV/TSV data into a worksheet starting at the given cell.
/// </summary>
/// <param name="parentPath">Sheet path, e.g. "/Sheet1"</param>
/// <param name="csvContent">Raw CSV/TSV string content</param>
/// <param name="delimiter">Field delimiter: ',' for CSV, '\t' for TSV</param>
/// <param name="hasHeader">If true, set AutoFilter and freeze pane on first row</param>
/// <param name="startCell">Starting cell reference, e.g. "A1"</param>
/// <returns>Summary of rows/cols imported</returns>
public string Import(string parentPath, string csvContent, char delimiter, bool hasHeader, string startCell)
{
parentPath = NormalizeExcelPath(parentPath);
parentPath = ResolveSheetIndexInPath(parentPath);
var sheetName = parentPath.TrimStart('/').Split('/', 2)[0];
var worksheet = FindWorksheet(sheetName)
?? throw new ArgumentException($"Sheet not found: {sheetName}");
var ws = GetSheet(worksheet);
var sheetData = ws.GetFirstChild<SheetData>()
?? ws.AppendChild(new SheetData());
// Parse start cell
var (startCol, startRow) = ParseCellReference(startCell.ToUpperInvariant());
var startColIdx = ColumnNameToIndex(startCol);
// Parse CSV
var rows = ParseCsv(csvContent, delimiter);
if (rows.Count == 0)
return "No data to import";
int maxCols = 0;
for (int r = 0; r < rows.Count; r++)
if (rows[r].Count > maxCols) maxCols = rows[r].Count;
View on GitHub (pinned to 1ced45e900)
Solutions
- Verify the sheet exists first via Get / (it lists all sheets) and use the exact name returned.
- Create the sheet before importing (add /NewSheet --type sheet), then import into /NewSheet.
- If using sheet[N] index syntax, confirm the index is in range; prefer the explicit sheet name.
- Check for accidental leading/trailing whitespace or quotes in the parentPath.
Example fix
// before
excel.Import("/SalesData", csv, ',', true, "A1"); // sheet does not exist
// after
excel.Add("/SalesData", "sheet");
excel.Import("/SalesData", csv, ',', true, "A1"); Defensive patterns
Strategy: validation
Validate before calling
var sheetName = parentPath.TrimStart('/').Split('/', 2)[0];
if (excel.FindWorksheet(sheetName) == null)
throw new ArgumentException($"Sheet '{sheetName}' does not exist. Create it first."); Prevention
- List sheets via Get('/') before importing and use the exact name returned.
- Create the target sheet before importing into it.
- Prefer explicit sheet names over index syntax to avoid stale references.
When it happens
Trigger: Calling Import with parentPath='/Nonexistent', '/Sheet1 ' (trailing space after normalization edge), a typo'd sheet name, or a path that resolves to a sheet index that does not exist (ResolveSheetIndexInPath returned a name FindWorksheet cannot match).
Common situations: Importing into a sheet that has not been created yet; case-sensitivity confusion after NormalizeExcelPath; reading the sheet name from a config field that was empty; targeting a hidden/very-deeply-named sheet by a stale label.
Related errors
- unsupported_type
- Sheet not found: {sheetName}
- Sheet not found: {fbSheetName}
- Sheet not found: {oleSheetName}
- Sheet not found: {picSheetName}
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/55b6eda7f130c0d5.
Report an issue: GitHub.