{"record":{"id":"165009b685cb3b18","repo":"iOfficeAI/OfficeCLI","slug":"sheet-has-no-data","errorCode":null,"errorMessage":"Sheet has no data","messagePattern":"Sheet has no data","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.cs","lineNumber":271,"sourceCode":"                {\n                    var lid = dn.LocalSheetId?.Value;\n                    if (lid == null || lid >= preMoveOrder.Count) continue;\n                    var newIdx = postMoveOrder.IndexOf(preMoveOrder[(int)lid.Value]);\n                    if (newIdx >= 0 && newIdx != lid.Value) dn.LocalSheetId = (uint)newIdx;\n                }\n            }\n\n            // Mark the document modified so Dispose flushes it. Without this,\n            // a `using (h) h.Move(...)` (no explicit Save) is silently dropped\n            // by the !Modified byte-preserving discard path in Dispose.\n            Modified = true;\n            workbook.Save();\n            return $\"/{sheetName}\";\n        }\n\n        var elementRef = segments[1];\n        var sheetData = GetSheet(worksheet).GetFirstChild<SheetData>()\n            ?? throw new ArgumentException(\"Sheet has no data\");\n\n        // Determine the target sheet's SheetData. The result path is built from\n        // the resolved target SHEET (below), NOT the raw --to: a row/col/cell\n        // lives directly under a sheet, so a non-sheet --to like /Sheet1/row[2]\n        // must not leak into the result path (it used to produce a doubled\n        // /Sheet1/row[2]/row[3]). Only the sheet segment of --to is meaningful.\n        SheetData targetSheetData;\n        if (string.IsNullOrEmpty(targetParentPath))\n        {\n            targetSheetData = sheetData;\n        }\n        else\n        {\n            var tgtSegments = targetParentPath.TrimStart('/').Split('/', 2);\n            var tgtWorksheet = FindWorksheet(tgtSegments[0])\n                ?? throw new ArgumentException($\"Target sheet not found: {tgtSegments[0]}\");\n            targetSheetData = GetSheet(tgtWorksheet).GetFirstChild<SheetData>()\n                ?? throw new ArgumentException(\"Target sheet has no data\");","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.cs#L253-L289","documentation":"Thrown for a row/column element move when the source worksheet's GetSheet(worksheet).GetFirstChild<SheetData>() is null. SheetData is the container that holds <Row>/<Cell> elements; a worksheet lacking it has never had data written (a freshly-created or empty sheet). The handler cannot move a row/col out of a sheet that has no data structure.","triggerScenarios":"Move(\"/Blank/row[1]\") on a sheet that was created but never populated; operating on a template sheet with only dimensions/defaults but no <sheetData>; a sheet whose data was fully removed.","commonSituations":"Newly-added sheet via Add before any Set/insert; sheet from a minimal template; expecting rows that exist only conceptually (used range) rather than as stored elements.","solutions":["Target a sheet that actually contains rows (check the sheet is non-empty first).","Populate the sheet (Add/Set a row) before attempting a row/col move from it.","If you meant to move the whole sheet, drop the '/row[N]' segment so the sheet-reorder path runs instead."],"exampleFix":"// before\nh.Move(\"/Empty/row[1]\", \"/Data\", null); // Empty has no <sheetData>\n// after\nh.Move(\"/Data/row[1]\", \"/Report\", null); // move from a populated sheet","handlingStrategy":"try-catch","validationCode":"// Check the sheet actually has rows via the public query surface.\nvar node = handler.Get(sourcePath.TrimStart('/').Split('/', 2)[0], depth: 2);\nif (!node.Children.Any(c => c.Type == \"row\"))\n    throw new InvalidOperationException(\"Source sheet has no data to move\");","typeGuard":null,"tryCatchPattern":"try { handler.Move(\"/Sheet/row[1]\", target, pos); }\ncatch (ArgumentException ex) when (ex.Message == \"Sheet has no data\")\n{ /* source sheet is empty; pick a populated sheet or populate it first */ }","preventionTips":["Verify the source sheet has rows (Get with depth 2) before a row/col move.","For a whole-sheet reorder, omit the element segment so the sheet path is used.","Populate newly-created sheets before moving from them."],"tags":["excel","openxml","move","sheet-data","empty-sheet"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}