iOfficeAI/OfficeCLI · error · ArgumentException
Invalid {field} '{value}': row '{cm.Groups[2].Value}' is out
Error message
Invalid {field} '{value}': row '{cm.Groups[2].Value}' is outside Excel's grid (1..1048576). What it means
Thrown by ValidateSqref when a shape-valid token has a row component outside Excel's grid (must be 1..1048576). Real Excel refuses files with out-of-grid sqref (0x800A03EC), so the library bounds-checks every row component after the shape check.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Helpers.Validation.cs:68
// rejects. Bounds-check every cell/row/column component.
foreach (var tok in trimmed.Split(' ', StringSplitOptions.RemoveEmptyEntries))
{
foreach (System.Text.RegularExpressions.Match cm in
System.Text.RegularExpressions.Regex.Matches(tok, @"\$?([A-Z]+)?\$?([0-9]+)?",
System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
if (cm.Length == 0) continue;
if (cm.Groups[1].Success && cm.Groups[1].Value.Length > 0)
{
var colIdx = ColumnNameToIndex(cm.Groups[1].Value.ToUpperInvariant());
if (colIdx < 1 || colIdx > 16384)
throw new ArgumentException(
$"Invalid {field} '{value}': column '{cm.Groups[1].Value}' is outside Excel's grid (A..XFD).");
}
if (cm.Groups[2].Success && cm.Groups[2].Value.Length > 0)
{
if (!long.TryParse(cm.Groups[2].Value, out var rowNum) || rowNum < 1 || rowNum > 1048576)
throw new ArgumentException(
$"Invalid {field} '{value}': row '{cm.Groups[2].Value}' is outside Excel's grid (1..1048576).");
}
}
}
// Canonicalize inverted tokens (F5:D3 → D3:F5, per axis) — merge
// rejects them and table normalizes them, but CF/DV wrote them
// verbatim, leaving a non-canonical sqref whose behavior in real
// Excel is undefined. Same convention as the drawing-anchor and
// table-range normalization.
var normTokens = trimmed.Split(' ', StringSplitOptions.RemoveEmptyEntries)
.Select(tok =>
{
var cm = System.Text.RegularExpressions.Regex.Match(tok,
@"^(\$?)([A-Z]+)(\$?)([0-9]+):(\$?)([A-Z]+)(\$?)([0-9]+)$",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (cm.Success)
{
var c1 = ColumnNameToIndex(cm.Groups[2].Value.ToUpperInvariant());View on GitHub (pinned to 1ced45e900)
Solutions
- Clamp row numbers to 1..1048576 when generating.
- Reject row 0 explicitly — rows are 1-based.
- Validate with the validationCode before sending.
Example fix
// before
string sqref = $"A{row}"; // row could be 0 or > 1048576
// after
long r = Math.Clamp(row, 1, 1048576);
string sqref = $"A{r}"; Defensive patterns
Strategy: validation
Validate before calling
static bool RowInGrid(string digits)
=> long.TryParse(digits, out long r) && r >= 1 && r <= 1048576; Type guard
null
Try / catch
try { ValidateSqref(value, field); }
catch (ArgumentException ex) when (ex.Message.Contains("row") && ex.Message.Contains("outside Excel's grid"))
{ /* clamp the offending row to 1..1048576 and retry */ } Prevention
- Rows are 1-based; 0 is invalid. Row ceiling is 1048576.
- Bounds-check generated row numbers before use.
- Excel silently persists out-of-grid refs but refuses to open the file.
When it happens
Trigger: Calling a CF/DV API with sqref='A1048577' (row past the ceiling), sqref='A0' (zero is invalid), sqref='A9999999', or any token with a row number outside 1..1048576.
Common situations: Generating ranges programmatically with an unbounded row counter; user input with very large numbers; off-by-one from a loop that includes the ceiling+1.
Related errors
- Invalid {field} '{value}': column '{cm.Groups[1].Value}' is
- Invalid {field} '{value}': empty A1 range.
- Invalid {field} '{value}': expected an A1 reference (e.g. 'A
- Unknown CF type '{cfTypeRaw}'. Valid: databar, iconset, colo
- Unknown CF type '{cfTypeProp}'. Valid: databar, iconset, col
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/873955817c8240c9.
Report an issue: GitHub.