{"record":{"id":"f2e0208603fa76aa","repo":"iOfficeAI/OfficeCLI","slug":"move-not-supported-for-elementref-supported-r","errorCode":null,"errorMessage":"Move not supported for: {elementRef}. Supported: row[N], col[L]","messagePattern":"Move not supported for: (.+?)\\. Supported: row\\[N\\], col\\[L\\]","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.cs","lineNumber":542,"sourceCode":"                    }\n                }\n                // Sort col entries ascending for OOXML schema validity.\n                var sortedCols = columns.Elements<Column>()\n                    .OrderBy(c => c.Min?.Value ?? 0).ToList();\n                columns.RemoveAllChildren<Column>();\n                foreach (var c in sortedCols) columns.AppendChild(c);\n            }\n\n            // Remap formulas + range-bearing structures via the col shifter.\n            ApplyColRenumberToSheet(worksheet, sheetName, colMap);\n\n            DeleteCalcChainIfPresent();\n            SaveWorksheet(worksheet);\n            int newSrcIdx = colMap[srcColIdx];\n            return $\"/{sheetName}/col[{IndexToColumnName(newSrcIdx)}]\";\n        }\n\n        throw new ArgumentException($\"Move not supported for: {elementRef}. Supported: row[N], col[L]\");\n    }\n\n    /// <summary>\n    /// Build {old → new} row-index map from a snapshot taken before the\n    /// move + renumber. Rows whose old and new index match are omitted (the\n    /// shifter treats absent keys as no-op).\n    /// </summary>\n    private static Dictionary<int, int> BuildRowRenumberMap(Dictionary<Row, int> oldIdxByRow)\n    {\n        var map = new Dictionary<int, int>(oldIdxByRow.Count);\n        foreach (var (row, oldIdx) in oldIdxByRow)\n        {\n            int newIdx = (int)(row.RowIndex?.Value ?? 0u);\n            if (newIdx != 0 && newIdx != oldIdx)\n                map[oldIdx] = newIdx;\n        }\n        return map;\n    }","sourceCodeStart":524,"sourceCodeEnd":560,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.cs#L524-L560","documentation":"Thrown at the end of Move when elementRef (the second path segment) matches neither row[N] nor col[L]. Move supports only whole-row and whole-column relocations; any other element shape (cells, ranges, charts, tables) is unsupported and the method refuses to guess.","triggerScenarios":"Move(\"/Sheet1/cell[A1]\"), Move(\"/Sheet1/A1:B2\"), or Move(\"/Sheet1/chart1\"); a path whose element segment is a cell reference or an unsupported object.","commonSituations":"Assuming Move works on cells (it does not; use Set/cut-paste instead); passing a query-selector fragment as a path; copy-paste of a cell range into Move.","solutions":["Restrict Move to row[N] or col[L] element paths.","To relocate a cell's value, use Set/copy semantics or move the enclosing row/column instead.","Validate elementRef against ^(row\\[\\d+\\]|col\\[[A-Za-z]+\\])$ before calling Move."],"exampleFix":"// before\nh.Move(\"/Sheet1/A1\", null, InsertPosition.AtIndex(0)); // cell not supported\n// after\nh.Move(\"/Sheet1/row[1]\", null, InsertPosition.AtIndex(0)); // move the whole row","handlingStrategy":"validation","validationCode":"var elementRef = sourcePath.TrimStart('/').Split('/', 2)[1];\nif (!System.Text.RegularExpressions.Regex.IsMatch(elementRef, @\"^(row\\[\\d+\\]|col\\[[A-Za-z]+\\])$\"))\n    throw new NotSupportedException($\"Move only supports row[N] or col[L]; got '{elementRef}'\");","typeGuard":"static bool IsSupportedMoveElement(string path)\n{\n    var segs = path.TrimStart('/').Split('/', 2);\n    return segs.Length >= 2\n        && System.Text.RegularExpressions.Regex.IsMatch(segs[1], @\"^(row\\[\\d+\\]|col\\[[A-Za-z]+\\])$\");\n}","tryCatchPattern":null,"preventionTips":["Restrict Move paths to row[N] / col[L]; never cells or ranges.","Gate Move with a supported-element regex.","Use Set/copy semantics to relocate cell values, not Move."],"tags":["excel","openxml","move","unsupported","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}