iOfficeAI/OfficeCLI · error · ArgumentException

Column width cannot be empty.

Error message

Column width cannot be empty.

What it means

Thrown by ParseColWidthChars when the 'width' value for a column is null, empty, or whitespace. The helper normalizes column-width input (bare character units or unit-qualified) into the char-unit value OOXML stores.

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Helpers.cs:168

                throw new ArgumentException($"Invalid 'height' value: '{value}'. Expected a finite number or unit-qualified value (e.g. 15.75, 40pt, 40px, 1cm, 0.5in).", ex);
            }
        }
        // DEFERRED(xlsx/row-height-validation) RC2: Excel row height is bounded
        // [0, 409.5] points. Values outside this range are rejected by Excel at
        // open time (file silently repaired), so validate at Set time.
        if (pts < 0 || pts > 409.5)
            throw new ArgumentException($"Invalid 'height' value: '{value}'. Row height must be between 0 and 409.5 points.");
        return pts;
    }

    // CONSISTENCY(rc-units): Column width is in "maximum digit width" char
    // units (Calibri 11pt ≈ 7px per char). Accepts bare number (char units,
    // legacy) or unit-qualified px/cm/in/pt — physical sizes converted via
    // the 7-px-per-char approximation Excel uses internally.
    internal static double ParseColWidthChars(string value)
    {
        if (string.IsNullOrWhiteSpace(value))
            throw new ArgumentException("Column width cannot be empty.");
        var trimmed = value.Trim();
        double chars;
        if (double.TryParse(trimmed, System.Globalization.NumberStyles.Float,
                System.Globalization.CultureInfo.InvariantCulture, out var bare)
            && !char.IsLetter(trimmed[^1]))
        {
            if (double.IsNaN(bare) || double.IsInfinity(bare))
                throw new ArgumentException($"Invalid 'width' value: '{value}'. Expected a finite number (column width in char units, e.g. 8.43).");
            chars = bare;
        }
        else
        {
            try
            {
                var emu = OfficeCli.Core.EmuConverter.ParseEmu(trimmed);
                // 9525 EMU = 1 px; 7 px ≈ 1 char unit (Calibri 11pt MDW baseline)
                var px = emu / EmuConverter.EmuPerPxF;
                chars = px / 7.0;

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Provide an explicit width value: a bare number (character units, e.g. 8.43) or unit-qualified (20px, 2cm, 1in, 60pt).
  2. Skip setting width if no value is intended rather than passing an empty string.
  3. Guard with string.IsNullOrWhiteSpace in calling code before invoking the Set path.

Example fix

// before
set /Sheet1/col[B] --prop width=

// after
set /Sheet1/col[B] --prop width=12
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(widthValue))
    throw new ArgumentException("Provide a column width (bare char units or e.g. 20px).");

Prevention

When it happens

Trigger: Invoking set /Sheet/col[X] --prop width= with an empty value, or passing null/"" programmatically to a path that calls ParseColWidthChars.

Common situations: Dynamically built prop strings with a missing source field; templating that interpolates an undefined variable; CI runs with --prop width=$WIDTH and WIDTH unset.

Related errors


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