{"record":{"id":"8f5a3a2d7187b319","repo":"iOfficeAI/OfficeCLI","slug":"picture-shape-name-column-row-index-must-be-in","errorCode":null,"errorMessage":"Picture/shape {name} column/row index must be in [0, {MaxCellIndex - 1}] (got '{value}'). For EMU-scale sizes use a unit-qualified value like '1in' / '6cm' / '72pt'.","messagePattern":"Picture/shape (.+?) column/row index must be in \\[0, (.+?)\\] \\(got '(.+?)'\\)\\. For EMU-scale sizes use a unit-qualified value like '1in' / '6cm' / '72pt'\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs","lineNumber":1514,"sourceCode":"            // `width=-5` silently rounded to 0 (still invalid) and produced\n            // an Excel-rejected file with cx=0/cy=0 anchors.\n            if (plainInt <= 0)\n                throw new ArgumentException($\"Picture/shape {name} must be positive (got '{value}').\");\n            // Bare integers are interpreted as cell counts (original grammar),\n            // but values that exceed Excel's column max (16384) are clearly\n            // EMU — for either axis. Using a single threshold (instead of\n            // axis-specific MaxRows=1048576) keeps the heuristic symmetric\n            // with ParseAnchorOriginCell so x/y/width/height all flip to\n            // EMU at the same boundary.\n            const int MaxCellIndex = 16384;\n            // R39-2: cell-count form is rejected above the grid limit so\n            // mistakes like `width=20000` raise a clear error instead of\n            // being silently treated as raw EMU. Users passing EMU should\n            // use a unit-qualified form (`914400emu`, `1in`) which is parsed\n            // through EmuConverter further down. CONSISTENCY with\n            // ParseAnchorOriginCell.\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 sizes use a unit-qualified value like '1in' / '6cm' / '72pt'.\");\n            long perCell = (name == \"height\") ? EmuPerRowApprox : EmuPerColApprox;\n            return plainInt * perCell;\n        }\n\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 count or a unit-qualified size (e.g. '6cm', '2in') for {name}, got '{value}'.\");\n        }\n        // R30-1: unit-qualified negatives (e.g. \"-5cm\") parse to a negative\n        // EMU; reject so we don't write `<xdr:to><xdr:col>-2</xdr:col>...`\n        // anchors that crash Excel on open.\n        if (emu <= 0)","sourceCodeStart":1496,"sourceCodeEnd":1532,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs#L1496-L1532","documentation":"Thrown by ParseAnchorDimensionEmu when a bare-integer width/height exceeds Excel's column max (16383, i.e. MaxCellIndex-1). Previously such values hit a 'large bare int = EMU' heuristic and were silently treated as raw EMU, which surprised users. R39-2 rejects above-grid cell-count input outright and tells the user to use a unit-qualified form for EMU-scale sizes, keeping the heuristic symmetric across x/y/width/height.","triggerScenarios":"Passing width=20000 or height=100000 as a bare integer (above 16383). The parser refuses to guess whether the user meant a huge cell count or raw EMU; users wanting EMU must use a unit suffix.","commonSituations":"Passing a raw EMU value (e.g. 914400 for 1 inch) without the 'emu'/'in' suffix; confusing pixel or EMU magnitudes with cell counts; AI assistants emitting large dimensionless numbers.","solutions":["If you meant a cell count, keep it within [1, 16383]: width=10.","If you meant an EMU-scale size, add a unit suffix: width='914400emu', width='1in', width='6cm', or width='72pt'.","Use anchor='B2:K2' (a cell range) for large spans instead of a numeric width.","Double-check whether your value is in cells, EMU, inches, or pixels before passing."],"exampleFix":"// before\nshape width=914400\n// after\nshape width=1in","handlingStrategy":"validation","validationCode":"const int MaxCellIndex = 16384;\nbool IsValidBareCellCount(string value)\n    => long.TryParse(value, out var l) && l > 0 && l <= MaxCellIndex - 1;\n\nbool IsEmuScaleSize(string value)\n    => OfficeCli.Core.EmuConverter.TryParseEmu(value, out _);\n\n// for EMU-scale sizes, require a unit suffix:\nbool AcceptsDimension(string value)\n    => IsValidBareCellCount(value) || (IsEmuScaleSize(value) && value.EndsWithAny(new[]{\"in\",\"cm\",\"mm\",\"pt\",\"pc\",\"px\",\"Q\",\"emu\"}));","typeGuard":"static bool IsWithinGridCellCount(string s)\n    => long.TryParse(s, out var l) && l > 0 && l <= 16383;","tryCatchPattern":"try { ParseAnchorDimensionEmu(value, \"width\"); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"column/row index must be in [0,\"))\n{\n    // add a unit suffix for EMU-scale sizes, or clamp to <= 16383 for cell counts\n}","preventionTips":["Keep bare-integer cell counts within [1, 16383].","Add a unit suffix ('1in','6cm','72pt','914400emu') for EMU-scale sizes.","Use a cell-range anchor for large spans.","Verify whether the value is in cells, EMU, inches, or pixels before passing."],"tags":["excel","drawing","anchor","dimension","emu","validation","grid-limit"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}