iOfficeAI/OfficeCLI · error · ArgumentException

Invalid 'height' value: '{value}'. Row height must be betwee

Error message

Invalid 'height' value: '{value}'. Row height must be between 0 and 409.5 points.

What it means

Thrown by ParseRowHeightPoints after a successful parse when the resulting height in points falls outside Excel's hard limit of [0, 409.5]. Excel silently repairs files whose row height is out of range, so this validates at Set time to prevent producing a corrupt file.

Source

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

        }
        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.");
        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))

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Clamp the value into [0, 409.5] points (Excel's documented maximum row height is 409.5 points ≈ 546 pixels).
  2. If you intended pixels, convert to points first: points = pixels * 72/96 = pixels * 0.75.
  3. Re-check the unit: 409.5pt is about 409.5 points, 546px, 14.46cm, or 5.6in.

Example fix

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

// after
set /Sheet1/row[5] --prop height=409.5
Defensive patterns

Strategy: validation

Validate before calling

const double RowHeightMax = 409.5;
double pts = ExcelHandler.ParseRowHeightPoints(value);   // assume parse succeeded
if (pts < 0 || pts > RowHeightMax)
    throw new ArgumentException($"Row height {pts}pt is out of [0, {RowHeightMax}].");

Prevention

When it happens

Trigger: Passing height=500, height=-5, height=1000pt (≈ 1000 points), or any unit conversion whose point value exceeds 409.5 or drops below 0.

Common situations: Confusing points with pixels/char-units (typing height=200 thinking 200 pixels, which is 150pt and fine, but typing height=500 expecting pixels yields 500pt and is rejected); negative values from a sign error; very large unit conversions (5in = 360pt is fine, 7in = 504pt is rejected).

Related errors


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