{"record":{"id":"55b6eda7f130c0d5","repo":"iOfficeAI/OfficeCLI","slug":"sheet-not-found-sheetname-55b6ed","errorCode":null,"errorMessage":"Sheet not found: {sheetName}","messagePattern":"Sheet not found: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Import.cs","lineNumber":28,"sourceCode":"\npublic partial class ExcelHandler\n{\n    /// <summary>\n    /// Import CSV/TSV data into a worksheet starting at the given cell.\n    /// </summary>\n    /// <param name=\"parentPath\">Sheet path, e.g. \"/Sheet1\"</param>\n    /// <param name=\"csvContent\">Raw CSV/TSV string content</param>\n    /// <param name=\"delimiter\">Field delimiter: ',' for CSV, '\\t' for TSV</param>\n    /// <param name=\"hasHeader\">If true, set AutoFilter and freeze pane on first row</param>\n    /// <param name=\"startCell\">Starting cell reference, e.g. \"A1\"</param>\n    /// <returns>Summary of rows/cols imported</returns>\n    public string Import(string parentPath, string csvContent, char delimiter, bool hasHeader, string startCell)\n    {\n        parentPath = NormalizeExcelPath(parentPath);\n        parentPath = ResolveSheetIndexInPath(parentPath);\n        var sheetName = parentPath.TrimStart('/').Split('/', 2)[0];\n        var worksheet = FindWorksheet(sheetName)\n            ?? throw new ArgumentException($\"Sheet not found: {sheetName}\");\n\n        var ws = GetSheet(worksheet);\n        var sheetData = ws.GetFirstChild<SheetData>()\n            ?? ws.AppendChild(new SheetData());\n\n        // Parse start cell\n        var (startCol, startRow) = ParseCellReference(startCell.ToUpperInvariant());\n        var startColIdx = ColumnNameToIndex(startCol);\n\n        // Parse CSV\n        var rows = ParseCsv(csvContent, delimiter);\n        if (rows.Count == 0)\n            return \"No data to import\";\n\n        int maxCols = 0;\n        for (int r = 0; r < rows.Count; r++)\n            if (rows[r].Count > maxCols) maxCols = rows[r].Count;\n","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Import.cs#L10-L46","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nexcel.Import(\"/SalesData\", csv, ',', true, \"A1\");   // sheet does not exist\n\n// after\nexcel.Add(\"/SalesData\", \"sheet\");\nexcel.Import(\"/SalesData\", csv, ',', true, \"A1\");","handlingStrategy":"validation","validationCode":"var sheetName = parentPath.TrimStart('/').Split('/', 2)[0];\nif (excel.FindWorksheet(sheetName) == null)\n    throw new ArgumentException($\"Sheet '{sheetName}' does not exist. Create it first.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["excel","import","validation","sheet-not-found"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}