iOfficeAI/OfficeCLI · error · ArgumentException

Invalid 'height' value: '{value}'. Expected a finite number

Error message

Invalid 'height' value: '{value}'. Expected a finite number or unit-qualified value (e.g. 15.75, 40pt, 40px, 1cm, 0.5in).

What it means

Thrown by ParseRowHeightPoints when the input is unit-qualified (the last char is a letter) but EmuConverter.ParseEmu rejected it. The inner exception is preserved, so the true cause (unknown unit, non-numeric magnitude, or a font-context unit like 'em') is in ex.InnerException.

Source

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

        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 'height' value: '{value}'. Expected a finite number (row height in points, e.g. 15.75).");
            pts = bare;
        }
        else
        {
            // Unit-qualified: convert via EMU then back to points.
            try
            {
                var emu = OfficeCli.Core.EmuConverter.ParseEmu(trimmed);
                pts = emu / EmuConverter.EmuPerPointF;
            }
            catch (Exception ex)
            {
                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.");

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use a supported unit for row height: pt, px, cm, in, mm (e.g. height=20pt, height=40px, height=1cm).
  2. Inspect the inner exception message for the precise reason and correct the unit or numeric prefix accordingly.
  3. Use a dot decimal separator in the numeric prefix.

Example fix

// before
set /Sheet1/row[5] --prop height=2em

// after (row height has no font context -> convert em to pt yourself, e.g. 2em at 11pt ≈ 22pt)
set /Sheet1/row[5] --prop height=22pt
Defensive patterns

Strategy: try-catch

Validate before calling

static readonly Regex RowHeightRe = new(@"^\s*-?\d+(\.\d+)?\s*(pt|px|cm|mm|in)?\s*$", RegexOptions.IgnoreCase);
static bool IsValidRowHeight(string v) => !string.IsNullOrWhiteSpace(v) && RowHeightRe.IsMatch(v);

Try / catch

try { var pts = ExcelHandler.ParseRowHeightPoints(value); }
catch (ArgumentException ex) when (ex.Message.Contains("'height'"))
{ /* inspect ex.InnerException for the EmuConverter reason */ }

Prevention

When it happens

Trigger: Passing height=40ft, height=2em, height=10mn (typo of mm), height=abc pt, or a unit-qualified string whose numeric prefix fails to parse.

Common situations: AI assistants reach for CSS units ('em','rem','vh'); typoed suffixes; locale comma decimals in the numeric prefix ('1,5cm'); mixing the helper's accepted set (pt/px/cm/in/mm) with units EmuConverter does not support.

Related errors


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