iOfficeAI/OfficeCLI · error · ArgumentException

Invalid border style: '{value}'. Valid values: thin, medium,

Error message

Invalid border style: '{value}'. Valid values: thin, medium, thick, double, dashed, dotted, dashdot, dashdotdot, hair, mediumdashed, mediumdashdot, mediumdashdotdot, slantdashdot, none.

What it means

Thrown by the Excel border-style parser when a border style string does not match any of the recognized ECMA-376 border style tokens. The switch maps lowercase names to BorderStylesValues; the default arm rejects unknown values with the full list of valid options.

Source

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

    private static BorderStyleValues ParseBorderStyle(string value) =>
        value.ToLowerInvariant() switch
        {
            "thin" => BorderStyleValues.Thin,
            "medium" => BorderStyleValues.Medium,
            "thick" => BorderStyleValues.Thick,
            "double" => BorderStyleValues.Double,
            "dashed" => BorderStyleValues.Dashed,
            "dotted" => BorderStyleValues.Dotted,
            "dashdot" => BorderStyleValues.DashDot,
            "dashdotdot" => BorderStyleValues.DashDotDot,
            "hair" => BorderStyleValues.Hair,
            "mediumdashed" => BorderStyleValues.MediumDashed,
            "mediumdashdot" => BorderStyleValues.MediumDashDot,
            "mediumdashdotdot" => BorderStyleValues.MediumDashDotDot,
            "slantdashdot" => BorderStyleValues.SlantDashDot,
            "none" => BorderStyleValues.None,
            _ => throw new ArgumentException($"Invalid border style: '{value}'. Valid values: thin, medium, thick, double, dashed, dotted, dashdot, dashdotdot, hair, mediumdashed, mediumdashdot, mediumdashdotdot, slantdashdot, none."),
        };

    // ==================== CellFormat ====================

    private static uint FindOrCreateCellFormat(CellFormats cellFormats,
        uint numFmtId, uint fontId, uint fillId, uint borderId, Alignment? alignment, Protection? protection,
        bool applyNumFmt, bool applyFont, bool applyFill, bool applyBorder, bool applyAlignment, bool applyProtection,
        bool? quotePrefix = null)
    {
        // Search for existing match
        int idx = 0;
        foreach (var xf in cellFormats.Elements<CellFormat>())
        {
            if ((xf.NumberFormatId?.Value ?? 0) == numFmtId &&
                (xf.FontId?.Value ?? 0) == fontId &&
                (xf.FillId?.Value ?? 0) == fillId &&
                (xf.BorderId?.Value ?? 0) == borderId &&
                AlignmentMatches(xf.Alignment, alignment) &&

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use one of the listed valid border style names, spelled exactly.
  2. Trim whitespace and lowercase the value before passing it.
  3. Map your app's border vocabulary to the supported Excel set.

Example fix

// before
border["bottom"] = "meduim"; // typo
// after
border["bottom"] = "medium";
Defensive patterns

Strategy: type-guard

Validate before calling

static readonly HashSet<string> ValidBorders = new(StringComparer.OrdinalIgnoreCase)
{ "thin","medium","thick","double","dashed","dotted","dashdot","dashdotdot","hair","mediumdashed","mediumdashdot","mediumdashdotdot","slantdashdot","none" };
static string NormalizeBorder(string v) => ValidBorders.Contains(v?.Trim() ?? "") ? v.Trim().ToLowerInvariant() : throw new ArgumentException("invalid border");

Type guard

static bool IsValidBorderStyle(string v) => ValidBorders.Contains(v?.Trim() ?? "");

Try / catch

try { SetBorder(value); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Invalid border style"))
{ /* default to 'none' or prompt */ }

Prevention

When it happens

Trigger: Passing a border= or borderSide= property with a value not in {thin, medium, thick, double, dashed, dotted, dashdot, dashdotdot, hair, mediumdashed, mediumdashdot, mediumdashdotdot, slantdashdot, none}. Matching is case-insensitive (the input is lowercased).

Common situations: Typo like 'doted' or 'meduim'; using a CSS name like 'ridge'/'groove' not supported in Excel; trailing whitespace not trimmed.

Related errors


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