iOfficeAI/OfficeCLI · error · System.ArgumentException

Unknown dataBar axisPosition '{dbAxisPos}'. Valid: automatic

Error message

Unknown dataBar axisPosition '{dbAxisPos}'. Valid: automatic, middle, none.

What it means

Thrown by AddDataBar when building the x14:dataBar extension (Excel 2010+ bar) for a dataBar conditional format. The 'axisPosition' property controls where the axis line is drawn relative to the bar; it is lowercased and matched against a fixed allowlist. An unrecognized value is rejected rather than silently coerced, because emitting an unknown X14.DataBarAxisPositionValues enum would produce a file real Excel refuses to open.

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Cf.cs:208

        var cf = new ConditionalFormatting(cfRule)
        {
            SequenceOfReferences = new ListValue<StringValue>(
                sqref.Split(' ').Select(s => new StringValue(s)))
        };

        var wsElement = GetSheet(cfWorksheet);
        InsertConditionalFormatting(wsElement, cf);

        // R10-1: Build the x14:dataBar counterpart under worksheet extLst.
        var dbNegColor = ParseHelpers.NormalizeArgbColor(properties.GetValueOrDefault("negativeColor", "FF0000"));
        var dbAxisColor = ParseHelpers.NormalizeArgbColor(properties.GetValueOrDefault("axisColor", "000000"));
        var dbAxisPos = (properties.GetValueOrDefault("axisPosition") ?? "automatic").ToLowerInvariant();
        var dbAxisPosVal = dbAxisPos switch
        {
            "middle" => X14.DataBarAxisPositionValues.Middle,
            "none" => X14.DataBarAxisPositionValues.None,
            "automatic" or "auto" => X14.DataBarAxisPositionValues.Automatic,
            _ => throw new ArgumentException(
                $"Unknown dataBar axisPosition '{dbAxisPos}'. Valid: automatic, middle, none.")
        };

        // CF6 — accept user-supplied bar length bounds (defaults follow Excel's
        // 0/100 percentage convention) and bar direction (leftToRight/rightToLeft).
        var dbMinLength = 0U;
        if (properties.TryGetValue("minLength", out var dbMinLenStr)
            && uint.TryParse(dbMinLenStr, out var dbMinLenParsed))
            dbMinLength = dbMinLenParsed;
        var dbMaxLength = 100U;
        if (properties.TryGetValue("maxLength", out var dbMaxLenStr)
            && uint.TryParse(dbMaxLenStr, out var dbMaxLenParsed))
            dbMaxLength = dbMaxLenParsed;

        var x14DataBar = new X14.DataBar
        {
            MinLength = dbMinLength,
            MaxLength = dbMaxLength,

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Set axisPosition to one of: automatic (default), middle, or none. The alias 'auto' is also accepted.
  2. If you meant to control bar fill direction (left vs right), use the 'direction' property (leftToRight/rightToLeft/context), not axisPosition.
  3. Omit axisPosition entirely to accept the 'automatic' default.

Example fix

// before: axisPosition=center
add /Sheet1/A1:A10 cf type=databar axisPosition=center
// after: axisPosition=middle
add /Sheet1/A1:A10 cf type=databar axisPosition=middle
Defensive patterns

Strategy: validation

Validate before calling

var valid = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "automatic", "auto", "middle", "none" };
var pos = properties.GetValueOrDefault("axisPosition") ?? "automatic";
if (!valid.Contains(pos))
    throw new ArgumentException($"axisPosition '{pos}' invalid; choose from {string.Join(", ", valid)}.");

Type guard

static readonly HashSet<string> DataBarAxisPositions = new(StringComparer.OrdinalIgnoreCase)
{ "automatic", "auto", "middle", "none" };
static bool IsValidAxisPosition(string? s) => s is null || DataBarAxisPositions.Contains(s);

Try / catch

try { return Add(path, "databar", pos, props); }
catch (ArgumentException ex) when (ex.Message.Contains("axisPosition"))
{ props["axisPosition"] = "automatic"; return Add(path, "databar", pos, props); }

Prevention

When it happens

Trigger: Calling Add with type=databar (or the cf alias with type=databar) and passing axisPosition=<value> where value is not one of: 'middle', 'none', 'automatic', 'auto' (case-insensitive). The default when the property is omitted is 'automatic'.

Common situations: Typo such as axisPosition=center (the Excel UI label) instead of 'middle'; passing axisPosition=left/right which are not valid axis positions (those are bar *direction* values); copying the OOXML attribute spelling 'mid' from a raw XML sample.

Related errors


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