iOfficeAI/OfficeCLI · error · ArgumentException

Invalid 'axisPos' value: '{value}'. Valid: top, bottom, left

Error message

Invalid 'axisPos' value: '{value}'. Valid: top, bottom, left, right.

What it means

Thrown when 'axisPosition'/'axisPos' does not match any switch arm. OOXML ST_AxisPos is {t, b, l, r}; the setter also accepts long-form top/bottom/left/right. Anything else is rejected. The element is inserted in schema order (after delete) to avoid validator rejection.

Source

Thrown at src/officecli/Core/Chart/ChartHelper.Setter.cs:1888

                    };
                    foreach (var ax in plotArea2.Elements<C.ValueAxis>().Where(a => !IsDeletedAxis(a)))
                    { ax.RemoveAllChildren<C.TickLabelPosition>(); InsertAxisChildInOrder(ax, new C.TickLabelPosition { Val = tlPos }); }
                    foreach (var ax in plotArea2.Elements<C.CategoryAxis>().Where(a => !IsDeletedAxis(a)))
                    { ax.RemoveAllChildren<C.TickLabelPosition>(); InsertAxisChildInOrder(ax, new C.TickLabelPosition { Val = tlPos }); }
                    break;
                }

                case "axisposition" or "axispos":
                {
                    var plotArea2 = chart.GetFirstChild<C.PlotArea>();
                    if (plotArea2 == null) { unsupported.Add(key); break; }
                    var axPos = value.ToLowerInvariant() switch
                    {
                        "top" or "t" => C.AxisPositionValues.Top,
                        "bottom" or "b" => C.AxisPositionValues.Bottom,
                        "left" or "l" => C.AxisPositionValues.Left,
                        "right" or "r" => C.AxisPositionValues.Right,
                        _ => throw new ArgumentException($"Invalid 'axisPos' value: '{value}'. Valid: top, bottom, left, right.")
                    };
                    foreach (var ax in plotArea2.Elements<C.CategoryAxis>())
                    {
                        ax.RemoveAllChildren<C.AxisPosition>();
                        // CONSISTENCY(chart/axis-schema-order): axPos must sit
                        // immediately after delete in the CT_*Ax prefix; an
                        // AppendChild lands it at the tail and PowerPoint silently
                        // honors a stale axPos while OpenXmlValidator rejects the
                        // file with 'unexpected child element majorTickMark'.
                        InsertAxisChildInOrder(ax, new C.AxisPosition { Val = axPos });
                    }
                    break;
                }

                case "crosses":
                {
                    var plotArea2 = chart.GetFirstChild<C.PlotArea>();
                    var valAx = plotArea2?.GetFirstChild<C.ValueAxis>();

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use top (t), bottom (b), left (l), or right (r).
  2. Trim and ToLowerInvariant the value.
  3. Whitelist against the four positions before calling Set.

Example fix

// before
SetChartProperties(part, new() { ["axisPos"] = "center" });
// after
SetChartProperties(part, new() { ["axisPos"] = "bottom" });
Defensive patterns

Strategy: validation

Validate before calling

static readonly HashSet<string> AxisPos =
    new[]{"top","t","bottom","b","left","l","right","r"}, StringComparer.OrdinalIgnoreCase);

static bool IsValidAxisPos(string v) =>
    !string.IsNullOrWhiteSpace(v) && AxisPos.Contains(v.Trim().ToLowerInvariant());

Type guard

static bool IsKnownAxisPos(string v) =>
    (v?.Trim().ToLowerInvariant()) is "top" or "t" or "bottom" or "b" or "left" or "l" or "right" or "r";

Try / catch

try { SetChartProperties(part, props); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Invalid 'axisPos'"))
{ /* default to a chart-appropriate position and retry */ }

Prevention

When it happens

Trigger: SetChartProperties with { ["axisPos"] = "center" }, "middle", or a misspelled token.

Common situations: 'center' from a layout vocabulary that has no axis equivalent; case/whitespace mismatch; cross-mapping from labelPos tokens.

Related errors


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