iOfficeAI/OfficeCLI · error · ArgumentException

Invalid font size: '{szVal}'. Excel font size must be <= 409

Error message

Invalid font size: '{szVal}'. Excel font size must be <= 409pt.

What it means

Thrown when an Excel font size is greater than 409pt. Excel's UI caps font size at 409pt (ECMA-376 §17.4.18); larger values render silently as the default 11pt or open broken. The lower bound (>0) is enforced in the shared ParseFontSize helper, while this Excel-specific upper bound lives in the Excel style manager.

Source

Thrown at src/officecli/Core/ExcelStyleManager.cs:981

        else if (fontProps.TryGetValue("vertalign", out var vaVal))
            vertAlign = vaVal.ToLowerInvariant() is "superscript" or "subscript" ? vaVal.ToLowerInvariant() : null;
        else if (baseVertAlign?.Val?.Value == VerticalAlignmentRunValues.Superscript)
            vertAlign = "superscript";
        else if (baseVertAlign?.Val?.Value == VerticalAlignmentRunValues.Subscript)
            vertAlign = "subscript";
        else
            vertAlign = null;
        double size;
        if (fontProps.TryGetValue("size", out var szVal))
        {
            size = ParseHelpers.ParseFontSize(szVal);
            // R39-4: Excel UI caps font size at 409pt (ECMA-376 §17.4.18).
            // Values above silently render as default 11pt or open broken.
            // The lower bound (>0) is enforced in ParseFontSize; upper
            // bound is Excel-specific so it lives here, not in the shared
            // helper (Word/PPT have far higher limits).
            if (size > 409)
                throw new ArgumentException(
                    $"Invalid font size: '{szVal}'. Excel font size must be <= 409pt.");
        }
        else
        {
            size = baseFont.FontSize?.Val?.Value ?? 11;
        }
        string name = fontProps.GetValueOrDefault("name",
            baseFont.FontName?.Val?.Value ?? OfficeDefaultFonts.MinorLatin);
        // CONSISTENCY(scheme-color): font.color accepts scheme names
        // ("accent1"-"accent6", "lt1"/"dk1", "hlink", etc.) per the project conventions.
        // When matched, store as <color theme="N"/> instead of rgb.
        string? color;
        uint? colorTheme = null;
        if (fontProps.TryGetValue("color", out var cVal))
        {
            var schemeIdx = OfficeCli.Handlers.ExcelHandler.ExcelSchemeColorNameToThemeIndex(cVal);
            if (schemeIdx.HasValue)
            {

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Clamp or correct the font size to the 1..409 range before setting it.
  2. Check the unit: Excel font size is in points, not pixels.
  3. If a larger size is genuinely needed, this is an Excel hard limit — redesign the layout instead.

Example fix

// before
fontProps["size"] = "600"; // > 409pt
// after
fontProps["size"] = Math.Min(requestedSize, 409).ToString();
Defensive patterns

Strategy: validation

Validate before calling

static double ClampFontSize(string szVal)
{
    var sz = ParseHelpers.ParseFontSize(szVal);
    return sz > 409 ? 409 : sz;
}

Try / catch

try { SetFont(size: requested); }
catch (ArgumentException ex) when (ex.Message.Contains("<= 409pt"))
{ SetFont(size: 409); }

Prevention

When it happens

Trigger: Calling an Excel style/font API with font size (size=... or sz) parsed to a double > 409. The value is first parsed by ParseHelpers.ParseFontSize (which rejects <=0), then checked here for the upper bound.

Common situations: Passing size in the wrong unit (e.g. pixels or a scaled value) that overruns 409; a config/default that multiplies a base size; user input not clamped.

Related errors


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