{"record":{"id":"c79e6f49686f48f5","repo":"iOfficeAI/OfficeCLI","slug":"target-sheet-has-no-data","errorCode":null,"errorMessage":"Target sheet has no data","messagePattern":"Target sheet has no data","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.cs","lineNumber":289,"sourceCode":"            ?? 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\");\n        }\n\n        // Find and move the row\n        var rowMatch = Regex.Match(elementRef, @\"^row\\[(\\d+)\\]$\");\n        if (rowMatch.Success)\n        {\n            var rowIdx = int.Parse(rowMatch.Groups[1].Value);\n            // Try ordinal lookup first (Nth row element), then fall back to RowIndex\n            var allRows = sheetData.Elements<Row>().ToList();\n            var row = (rowIdx >= 1 && rowIdx <= allRows.Count ? allRows[PathIndex.ToArrayIndex(rowIdx)] : null)\n                ?? sheetData.Elements<Row>().FirstOrDefault(r => r.RowIndex?.Value == (uint)rowIdx)\n                ?? throw new ArgumentException($\"Row {rowIdx} not found\");\n\n            // Resolve --before / --after anchors to a 0-based document-order\n            // position in the target sheet. Anchor must be /<TargetSheet>/row[K].\n            // Resolved BEFORE removing the moved row so the anchor is found by\n            // its current position.\n            int? targetIndex = index;","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.cs#L271-L307","documentation":"Thrown when the resolved target worksheet (for a cross-sheet row move) has no <sheetData> element. Even though the target sheet exists, it carries no data container, so there is nowhere to insert the moved row. This is the target-side equivalent of 'Sheet has no data'.","triggerScenarios":"Moving a row into a freshly-created or empty target sheet that was never populated; target sheet whose data was stripped; minimal template sheet used as a destination.","commonSituations":"Destination created by Add('sheet') but not yet written to; template sheets with only column defaults; exporter that omits <sheetData> on empty sheets.","solutions":["Populate the target sheet with at least one row before moving into it.","Choose a target sheet that already contains data.","If the target is brand new, seed it with a placeholder row then move."],"exampleFix":"// before\nh.Move(\"/Data/row[1]\", \"/Fresh\", null); // Fresh has no <sheetData>\n// after\nh.Add(\"/Fresh\", \"row\", null, new());            // seed so SheetData exists\nh.Move(\"/Data/row[1]\", \"/Fresh\", InsertPosition.AtIndex(1));","handlingStrategy":"try-catch","validationCode":"// Confirm the target sheet already holds data before moving into it.\nvar tgt = targetParentPath!.TrimStart('/').Split('/', 2)[0];\nvar node = handler.Get(tgt, depth: 2);\nif (!node.Children.Any(c => c.Type == \"row\"))\n    throw new InvalidOperationException(\"Target sheet has no data; seed it first\");","typeGuard":null,"tryCatchPattern":"try { handler.Move(src, target, pos); }\ncatch (ArgumentException ex) when (ex.Message == \"Target sheet has no data\")\n{ /* seed the target with a row, then retry the move */ }","preventionTips":["Seed empty target sheets with a placeholder row before moving into them.","Prefer data-bearing sheets as move destinations.","For brand-new sheets, Add a row first to materialize <sheetData>."],"tags":["excel","openxml","move","row-move","target-sheet","empty-sheet"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}