{"record":{"id":"20b0c208f8d9d09c","repo":"iOfficeAI/OfficeCLI","slug":"picture-shape-key-is-out-of-range-for-a-onecell","errorCode":null,"errorMessage":"Picture/shape {key} is out of range for a oneCell/absolute drawing anchor: {emu} EMU exceeds the OOXML limit 2147483647 EMU (~23.5in per axis).","messagePattern":"Picture/shape (.+?) is out of range for a oneCell/absolute drawing anchor: (.+?) EMU exceeds the OOXML limit 2147483647 EMU \\(~23\\.5in per axis\\)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs","lineNumber":913,"sourceCode":"        return node;\n    }\n\n    // ==================== Shared Anchor Helpers ====================\n\n    /// <summary>\n    /// Set position/size properties (x, y, width, height) on a TwoCellAnchor.\n    /// Returns true if the key was handled, false otherwise.\n    /// </summary>\n    // OOXML spreadsheet-drawing extents/positions (<xdr:ext>, <xdr:pos>) are\n    // Int32-bounded EMU (ST_PositiveCoordinate32). Values beyond that pass\n    // SDK save silently but fail schema validation (MaxInclusive) and make\n    // real Excel refuse the workbook (0x800A03EC) — reject at input instead\n    // of persisting an unopenable file. Only oneCell/absolute anchors hit\n    // this: twoCell anchors split spans into whole-column/row markers.\n    internal static long ValidateDrawingCoordEmu(long emu, string key)\n    {\n        if (emu > int.MaxValue)\n            throw new ArgumentException(\n                $\"Picture/shape {key} is out of range for a oneCell/absolute drawing anchor: \" +\n                $\"{emu} EMU exceeds the OOXML limit 2147483647 EMU (~23.5in per axis).\");\n        return emu;\n    }\n\n    // Anchor-kind dispatch mirroring ReadAnchorPosition: oneCell keeps x/y as\n    // cell indices but sizes via <xdr:ext> EMU; absolute positions and sizes\n    // are all EMU (ParseEmu accepts \"2cm\"/\"1in\"/\"NNNemu\"/bare EMU).\n    private static bool TrySetAnchorPosition(OpenXmlCompositeElement anchorEl, string key, string value)\n    {\n        switch (anchorEl)\n        {\n            case XDR.TwoCellAnchor two:\n                return TrySetAnchorPosition(two, key, value);\n            case XDR.OneCellAnchor one:\n                switch (key)\n                {\n                    case \"x\":","sourceCodeStart":895,"sourceCodeEnd":931,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs#L895-L931","documentation":"Thrown by ValidateDrawingCoordEmu when a oneCell or absolute anchor coordinate/extent exceeds Int32.MaxValue (2147483647 EMU, ~23.5in). OOXML <xdr:ext> and <xdr:pos> are ST_PositiveCoordinate32 (Int32-bounded); values above pass OpenXML SDK save but fail schema validation (MaxInclusive) and make Excel refuse the workbook with 0x800A03EC. Only oneCell/absolute anchors hit this because twoCell anchors express spans via column/row markers, not raw EMU.","triggerScenarios":"Passing x/width (or y/height) on a oneCell or absolute anchor with a unit value over ~23.5 inches per axis, e.g. width='25in', x='600cm', or a raw EMU integer > 2147483647 like width='3000000000emu'. Also triggered by accidentally passing a cell count as a unit-less huge integer that the anchor path treats as EMU.","commonSituations":"Confusing cell-count units with EMU/inch units on oneCell anchors; AI assistants emitting 'width=30in' for a banner image; computing a size programmatically and feeding the raw pixel*9525 product without clamping; importing a drawing whose source document used a different coordinate space.","solutions":["Keep each axis under ~23.5in: cap unit values (e.g. width='23in') or raw EMU to <= 2147483647.","If you genuinely need a larger span, switch to a twoCell anchor (anchor='twoCell' / cell-range) which uses column/row markers and bypasses the EMU Int32 bound.","Double-check that you are not passing a cell index where EMU is expected (or vice-versa) on a oneCell/absolute anchor.","Clamp programmatically: emu = Math.Min(emu, int.MaxValue) before calling the API."],"exampleFix":"// before\nshape anchor=oneCell x=1in width=30in\n// after\nshape anchor=oneCell x=1in width=20in\n// or use a twoCell anchor for large spans\nshape anchor=twoCell anchor=B2:F2","handlingStrategy":"validation","validationCode":"const long OoxmlEmuMax = int.MaxValue; // 2147483647\nlong ClampEmuCoord(long emu) => emu > OoxmlEmuMax\n    ? throw new ArgumentOutOfRangeException(nameof(emu), $\"{emu} EMU exceeds OOXML Int32 limit.\")\n    : emu;\n\n// before calling the anchor API on a oneCell/absolute anchor:\nemu = ClampEmuCoord(emu);","typeGuard":"static bool IsWithinOoxmlEmuRange(long emu) => emu <= int.MaxValue;","tryCatchPattern":"try { ValidateDrawingCoordEmu(emu, key); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"exceeds the OOXML limit\"))\n{\n    // reduce the size, or switch to a twoCell anchor that uses cell markers\n}","preventionTips":["Keep each oneCell/absolute axis under ~23.5in (2147483647 EMU).","Use a twoCell anchor (cell range) for large spans to bypass the EMU Int32 bound.","Clamp programmatically: Math.Min(emu, int.MaxValue).","Double-check you are not feeding a cell index into an EMU-expected field."],"tags":["excel","drawing","anchor","emu","ooxml","validation","onecell","absolute"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}