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
- Use one of the listed valid border style names, spelled exactly.
- Trim whitespace and lowercase the value before passing it.
- 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
- Trim and lowercase border values before passing.
- Restrict the UI/config vocabulary to the supported set.
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
- Property 'sqref' (or 'range'/'ref') is required for validati
- invalid_value
- unsupported_type
- number format is {formatCode.Length} chars; Excel's limit is
- number format has unbalanced square brackets: '{formatCode}'
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/4b88aabd16c6edcb.
Report an issue: GitHub.