{"record":{"id":"f91cb24bded71c31","repo":"iOfficeAI/OfficeCLI","slug":"expected-an-integer-cell-index-or-a-unit-qualified","errorCode":null,"errorMessage":"Expected an integer cell index or a unit-qualified offset (e.g. '1in', '2cm') for {name}, got '{value}'.","messagePattern":"Expected an integer cell index or a unit-qualified offset \\(e\\.g\\. '1in', '2cm'\\) for (.+?), got '(.+?)'\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs","lineNumber":1695,"sourceCode":"            // by definition; if a user passes a number above the column\n            // max, it's either a typo or an EMU value mistakenly fed\n            // without a unit suffix. Either way, refuse rather than silently\n            // remap. CONSISTENCY with R30-1 negative guard.\n            if (plainInt > MaxCellIndex - 1)\n                throw new ArgumentException(\n                    $\"Picture/shape {name} column/row index must be in [0, {MaxCellIndex - 1}] (got '{value}'). For EMU-scale offsets use a unit-qualified value like '1in' / '6cm' / '72pt'.\");\n            return (int)plainInt;\n        }\n\n        // Unit-qualified (\"1in\", \"2cm\") → EMU → cell count via the same per-cell constants.\n        long emu;\n        try\n        {\n            emu = OfficeCli.Core.EmuConverter.ParseEmu(value);\n        }\n        catch\n        {\n            throw new ArgumentException($\"Expected an integer cell index or a unit-qualified offset (e.g. '1in', '2cm') for {name}, got '{value}'.\");\n        }\n        if (emu < 0)\n            throw new ArgumentException($\"Picture/shape {name} must be non-negative (got '{value}').\");\n        long perCellOut = (name == \"y\") ? EmuPerRowApprox : EmuPerColApprox;\n        return (int)(emu / perCellOut);\n    }\n}\n","sourceCodeStart":1677,"sourceCodeEnd":1703,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs#L1677-L1703","documentation":"Thrown by ParseAnchorOriginCell when the value is neither a plain integer nor a unit-qualified offset parseable by EmuConverter.ParseEmu. This cell-origin parser accepts a non-negative cell index ('0','5') or a unit-qualified offset ('1in','2cm','72pt') converted to an approximate cell count. Any other syntax is invalid.","triggerScenarios":"Passing x='abc', x='B2' (cell references belong on anchor=, not x/y), x='50%', or x='5em'. The inner EmuConverter exception is wrapped and re-thrown with this clearer message.","commonSituations":"Confusing the x/y origin property with anchor=; using percentage or font-relative units; typos in unit suffixes; expecting percentage-based positioning.","solutions":["Pass a bare non-negative integer cell index: x=2.","Or pass a unit-qualified offset: x='1in', x='2cm'.","For cell-reference anchoring use anchor='B2' instead of x/y.","Avoid unsupported units (% em ex rem vw vh) and check suffix spelling."],"exampleFix":"// before\nshape x=abc\n// after\nshape x=2","handlingStrategy":"validation","validationCode":"bool IsValidAnchorOriginCell(string value)\n    => long.TryParse(value, out _)\n       || OfficeCli.Core.EmuConverter.TryParseEmu(value, out _);","typeGuard":"static bool IsAnchorOriginCellValue(string s)\n    => long.TryParse(s, out _) || OfficeCli.Core.EmuConverter.TryParseEmu(s, out _);","tryCatchPattern":"try { ParseAnchorOriginCell(value, \"x\"); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Expected an integer cell index\"))\n{\n    // not a cell index or unit-qualified offset; surface a user error\n}","preventionTips":["Pass either a bare non-negative integer cell index or a unit-qualified offset.","Do not pass cell references (use anchor=) or percentages.","Avoid unsupported units (% em ex rem vw vh).","Pre-validate with EmuConverter.TryParseEmu when sourcing from user input."],"tags":["excel","drawing","anchor","origin","emu","units","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}