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 sizes use a unit-qualified value like '1in' / '6cm' / '72pt'. What it means
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.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs:1514
// `width=-5` silently rounded to 0 (still invalid) and produced
// an Excel-rejected file with cx=0/cy=0 anchors.
if (plainInt <= 0)
throw new ArgumentException($"Picture/shape {name} must be positive (got '{value}').");
// Bare integers are interpreted as cell counts (original grammar),
// but values that exceed Excel's column max (16384) are clearly
// EMU — for either axis. Using a single threshold (instead of
// axis-specific MaxRows=1048576) keeps the heuristic symmetric
// with ParseAnchorOriginCell so x/y/width/height all flip to
// EMU at the same boundary.
const int MaxCellIndex = 16384;
// R39-2: cell-count form is rejected above the grid limit so
// mistakes like `width=20000` raise a clear error instead of
// being silently treated as raw EMU. Users passing EMU should
// use a unit-qualified form (`914400emu`, `1in`) which is parsed
// through EmuConverter further down. CONSISTENCY with
// ParseAnchorOriginCell.
if (plainInt > MaxCellIndex - 1)
throw new ArgumentException(
$"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'.");
long perCell = (name == "height") ? EmuPerRowApprox : EmuPerColApprox;
return plainInt * perCell;
}
long emu;
try
{
emu = OfficeCli.Core.EmuConverter.ParseEmu(value);
}
catch
{
throw new ArgumentException($"Expected an integer cell count or a unit-qualified size (e.g. '6cm', '2in') for {name}, got '{value}'.");
}
// R30-1: unit-qualified negatives (e.g. "-5cm") parse to a negative
// EMU; reject so we don't write `<xdr:to><xdr:col>-2</xdr:col>...`
// anchors that crash Excel on open.
if (emu <= 0)View on GitHub (pinned to 1ced45e900)
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.
Example fix
// before shape width=914400 // after shape width=1in
Defensive patterns
Strategy: validation
Validate before calling
const int MaxCellIndex = 16384;
bool IsValidBareCellCount(string value)
=> long.TryParse(value, out var l) && l > 0 && l <= MaxCellIndex - 1;
bool IsEmuScaleSize(string value)
=> OfficeCli.Core.EmuConverter.TryParseEmu(value, out _);
// for EMU-scale sizes, require a unit suffix:
bool AcceptsDimension(string value)
=> IsValidBareCellCount(value) || (IsEmuScaleSize(value) && value.EndsWithAny(new[]{"in","cm","mm","pt","pc","px","Q","emu"})); Type guard
static bool IsWithinGridCellCount(string s)
=> long.TryParse(s, out var l) && l > 0 && l <= 16383; Try / catch
try { ParseAnchorDimensionEmu(value, "width"); }
catch (ArgumentException ex) when (ex.Message.Contains("column/row index must be in [0,"))
{
// add a unit suffix for EMU-scale sizes, or clamp to <= 16383 for cell counts
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Expected an integer cell count or a unit-qualified size (e.g
- Picture/shape {name} column/row index must be in [0, {MaxCel
- Picture/shape {key} is out of range for a oneCell/absolute d
- Expected a non-negative cell index or a unit-qualified offse
- Picture/shape {name} must be positive (got '{value}').
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/8f5a3a2d7187b319.
Report an issue: GitHub.