iOfficeAI/OfficeCLI · error · ArgumentException

Invalid vertical alignment: '{value}'. Valid values: top, ce

Error message

Invalid vertical alignment: '{value}'. Valid values: top, center, bottom.

What it means

Thrown by the Excel vertical-alignment parser when a value does not match a known token. Like the horizontal case, the message lists only 'top, center, bottom' even though the switch also accepts 'justify' and 'distributed'.

Source

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

            "center" => HorizontalAlignmentValues.Center,
            "right" => HorizontalAlignmentValues.Right,
            "justify" => HorizontalAlignmentValues.Justify,
            "general" => HorizontalAlignmentValues.General,
            "fill" => HorizontalAlignmentValues.Fill,
            "centeracrossselection" or "centercontinuous" => HorizontalAlignmentValues.CenterContinuous,
            "distributed" => HorizontalAlignmentValues.Distributed,
            _ => throw new ArgumentException($"Invalid horizontal alignment: '{value}'. Valid values: left, center, right, justify.")
        };

    private static VerticalAlignmentValues ParseVAlign(string value) =>
        value.ToLowerInvariant() switch
        {
            "top" => VerticalAlignmentValues.Top,
            "center" => VerticalAlignmentValues.Center,
            "bottom" => VerticalAlignmentValues.Bottom,
            "justify" => VerticalAlignmentValues.Justify,
            "distributed" => VerticalAlignmentValues.Distributed,
            _ => throw new ArgumentException($"Invalid vertical alignment: '{value}'. Valid values: top, center, bottom.")
        };
}

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use one of the actually-supported values: top, center, bottom, justify, distributed.
  2. Trim and lowercase the input.
  3. Note the message is incomplete — if your value is justify/distributed it works despite not being listed.

Example fix

// before
align["vertical"] = "middel";
// after
align["vertical"] = "middle".ToLowerInvariant() == "middle" ? "center" : align["vertical"]; // map 'middle'->'center'
Defensive patterns

Strategy: type-guard

Validate before calling

static readonly HashSet<string> ValidVAlign = new(StringComparer.OrdinalIgnoreCase)
{ "top","center","bottom","justify","distributed" };
static string NormalizeVAlign(string v) => ValidVAlign.Contains(v?.Trim() ?? "") ? v.Trim().ToLowerInvariant() : throw new ArgumentException("invalid valign");

Type guard

static bool IsValidVAlign(string v) => ValidVAlign.Contains(v?.Trim() ?? "");

Try / catch

try { SetAlign(vertical: value); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Invalid vertical alignment"))
{ /* fallback to 'bottom' */ }

Prevention

When it happens

Trigger: Passing alignment/vertical= with a value outside the switch arms. The default arm throws, but the listed valid options are narrower than what the parser actually accepts (it also accepts justify and distributed).

Common situations: Typo such as 'middel' or 'Center '; whitespace not trimmed; confusion with the horizontal alignment vocabulary.

Related errors


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