iOfficeAI/OfficeCLI · error · ArgumentException

Picture/shape {name} column/row index must be in [0, {MaxCel

Error message

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'.

What it means

Thrown by ParseAnchorOriginCell when a bare-integer x/y origin exceeds Excel's column max (16383, MaxCellIndex-1). R39-2 added this guard because previously x=20000 hit the 'large bare int = EMU' heuristic, divided by 609600, and silently coerced the origin back to col=0 (or row=0) - a silent data-corrupting remap. Users wanting EMU-scale offsets must use a unit-qualified form.

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs:1682

            if (plainInt < 0)
                throw new ArgumentException($"Picture/shape {name} must be non-negative (got '{value}').");
            // Excel's column max (16384) is the tightest sheet-coordinate
            // bound — anything beyond that is unambiguously an EMU offset
            // (rows go to 1048576 but a row index that high is also clearly
            // EMU in practice). Use the same threshold for x and y so users
            // passing inch-EMU (914400) consistently land on a sensible cell
            // on either axis.
            const int MaxCellIndex = 16384;
            // R39-2: bare cell-count form must reject above-grid values
            // outright. Previously, x=20000 hit the "large bare int = EMU"
            // branch and divided by 609600, silently coercing the origin
            // back to col=0 (or row=0 for y). Cell-count input is small
            // by definition; if a user passes a number above the column
            // max, it's either a typo or an EMU value mistakenly fed
            // without a unit suffix. Either way, refuse rather than silently
            // remap. CONSISTENCY with R30-1 negative guard.
            if (plainInt > MaxCellIndex - 1)
                throw new ArgumentException(
                    $"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'.");
            return (int)plainInt;
        }

        // Unit-qualified ("1in", "2cm") → EMU → cell count via the same per-cell constants.
        long emu;
        try
        {
            emu = OfficeCli.Core.EmuConverter.ParseEmu(value);
        }
        catch
        {
            throw new ArgumentException($"Expected an integer cell index or a unit-qualified offset (e.g. '1in', '2cm') for {name}, got '{value}'.");
        }
        if (emu < 0)
            throw new ArgumentException($"Picture/shape {name} must be non-negative (got '{value}').");
        long perCellOut = (name == "y") ? EmuPerRowApprox : EmuPerColApprox;
        return (int)(emu / perCellOut);

View on GitHub (pinned to 1ced45e900)

Solutions

  1. If you meant a cell index, keep it in [0, 16383]: x=5.
  2. If you meant an EMU-scale offset, add a unit suffix: x='914400emu', x='1in', x='6cm', or x='72pt'.
  3. Use anchor='B2' (cell reference) for positional anchoring instead of numeric x/y.
  4. Verify whether your value is in cells, EMU, inches, or pixels before passing.

Example fix

// before
shape x=914400
// after
shape x=1in
Defensive patterns

Strategy: validation

Validate before calling

const int MaxCellIndex = 16384;
bool IsValidBareOriginCell(string value)
    => long.TryParse(value, out var l) && l >= 0 && l <= MaxCellIndex - 1;

bool IsEmuScaleOffset(string value)
    => OfficeCli.Core.EmuConverter.TryParseEmu(value, out _)
       && value.EndsWithAny(new[]{"in","cm","mm","pt","pc","px","Q","emu"});

Type guard

static bool IsWithinGridCellOrigin(string s)
    => long.TryParse(s, out var l) && l >= 0 && l <= 16383;

Try / catch

try { ParseAnchorOriginCell(value, "x"); }
catch (ArgumentException ex) when (ex.Message.Contains("column/row index must be in [0,"))
{
    // add a unit suffix for EMU-scale offsets, or clamp to <= 16383 for cell indices
}

Prevention

When it happens

Trigger: Passing x=20000 or y=100000 as a bare integer (above 16383). The parser refuses to guess EMU-vs-cell-count and tells the user to add a unit suffix for EMU-scale offsets.

Common situations: Passing a raw EMU value (e.g. 914400 for 1 inch) without a suffix; confusing pixel/EMU magnitudes with cell counts; AI assistants emitting large dimensionless numbers for x/y.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/3af0a49865c2dcc2. Report an issue: GitHub.