iOfficeAI/OfficeCLI · error · ArgumentException

Table name '{name}' looks like a cell reference; Excel refus

Error message

Table name '{name}' looks like a cell reference; Excel refuses to open files with such table names. Choose a name like '{name}_'.

What it means

Thrown by the table-name validator (userProvided=true) when the name looks like an A1 or R1C1 cell reference (e.g. 'A1', 'R2C3'), or equals 'R'/'C' (single-letter reserved column refs). Excel refuses to open files with such table names (0x800A03EC).

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Helpers.TableStyle.cs:64

            if (System.Text.RegularExpressions.Regex.IsMatch(name, @"^[Tt][Bb][Ll]\d+$"))
                throw new ArgumentException(
                    $"Table name '{name}' matches Excel's internal Tbl{{N}} naming pattern and is rejected by Mac Excel. Use 'Table{{N}}' (default) or a descriptive name like 'SalesData'.");
            // Excel enforces defined-name grammar on table names: identifier
            // chars only (no spaces), must not parse as an A1/R1C1 cell
            // reference. Violations pass schema validation but real Excel
            // refuses the whole file (0x800A03EC) — reject up front, same
            // rule set as the namedrange validator.
            // "Letter" is any Unicode letter (\p{L}) — Excel accepts CJK/
            // Cyrillic table names (same identifier grammar as defined
            // names, whose validator was widened the same way).
            if (!System.Text.RegularExpressions.Regex.IsMatch(name, @"^[\p{L}_\\][\p{L}\p{N}._\\]*$"))
                throw new ArgumentException(
                    $"Table name '{name}' is not a valid Excel name: use letters, digits, '.' or '_' only, starting with a letter or '_' (no spaces). Excel refuses to open files with other table names.");
            if (LooksLikeCellReference(name)
                || System.Text.RegularExpressions.Regex.IsMatch(name, @"^[Rr]\d+[Cc]\d+$")
                || name.Equals("R", StringComparison.OrdinalIgnoreCase)
                || name.Equals("C", StringComparison.OrdinalIgnoreCase))
                throw new ArgumentException(
                    $"Table name '{name}' looks like a cell reference; Excel refuses to open files with such table names. Choose a name like '{name}_'.");
            return name;
        }
        var looksLikeRef = LooksLikeCellReference(name)
            || System.Text.RegularExpressions.Regex.IsMatch(name, @"^[0-9]+$");
        return looksLikeRef ? name + "_" : name;
    }

    // T6 — built-in Excel table style names. Unknown names are rejected at
    // Add time rather than silently passed through to Excel.
    private static readonly HashSet<string> _builtInTableStyles = BuildBuiltInTableStyles();
    private static HashSet<string> BuildBuiltInTableStyles()
    {
        var set = new HashSet<string>(StringComparer.Ordinal);
        foreach (var tier in new[] { "Light", "Medium", "Dark" })
            for (int i = 1; i <= 28; i++)
                set.Add($"TableStyle{tier}{i}");
        // Pivot styles — users may apply a pivot style to a plain table.

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Append a non-numeric suffix: 'A1' → 'A1Data' or 'A1_'.
  2. Avoid single-letter 'R' or 'C' as names.
  3. Use the validationCode guard before submitting.

Example fix

// before
string name = "A1"; // looks like cell A1
// after
string name = "A1_Data";
// or pick a descriptive name:
string name = "Region1Table";
Defensive patterns

Strategy: validation

Validate before calling

// Reject names that look like cell references
static bool LooksLikeRef(string name)
    => name.Equals("R", StringComparison.OrdinalIgnoreCase)
       || name.Equals("C", StringComparison.OrdinalIgnoreCase)
       || System.Text.RegularExpressions.Regex.IsMatch(name ?? "", @"^[Rr]\d+[Cc]\d+$")
       /* LooksLikeCellReference handles A1-style internally */;

Type guard

null

Try / catch

try { /* add table */ }
catch (ArgumentException ex) when (ex.Message.Contains("looks like a cell reference"))
{ name = name + "_"; /* the message itself suggests this suffix */ }

Prevention

When it happens

Trigger: Calling an add-table API with name='A1', name='C5', name='R2C3', name='R', or name='C'. LooksLikeCellReference plus the R1C1 pattern and single-letter R/C all trigger.

Common situations: Generating table names from short codes that happen to be cell refs; user input that matches A1 shape; copying Excel's own short identifiers.

Related errors


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