iOfficeAI/OfficeCLI · error · ArgumentException

Invalid 'lineSpacing' value '{raw}'. Line spacing must be gr

Error message

Invalid 'lineSpacing' value '{raw}'. Line spacing must be greater than 0.

What it means

Thrown by the RequirePositive local in ParseWordLineSpacing (BUG-R7-04) when a fixed (Exact) line-spacing value in cm or in units is <= 0. Zero produces degenerate OOXML (w:spacing/@line=0 is undefined in MS-DOC) and Office silently collapses to single-spacing, so it is surfaced. Used for the cm/in fixed paths. ArgumentException.

Source

Thrown at src/officecli/Core/SpacingConverter.cs:148

    /// <summary>
    /// Parse line spacing for Word. Returns (twips, isMultiplier).
    /// "1.5x" or "150%" → (360, true)  — Auto rule, 240 × multiplier
    /// "18pt"           → (360, true=false) — Exact rule, pt × 20
    /// "0.5cm"          → converted to pt, then Exact
    /// bare number      → (number, true) — Auto rule, backward compat (raw twips)
    /// </summary>
    public static (int Twips, bool IsMultiplier) ParseWordLineSpacing(string value)
    {
        var trimmed = value.Trim();

        // BUG-R7-04: lineSpacing must not be zero. Zero produces degenerate
        // OOXML (w:spacing/@line=0 is undefined in MS-DOC) and Office silently
        // collapses to single-spacing — surface the error to the user instead.
        static double RequirePositive(double n, string raw)
        {
            if (n <= 0)
                throw new ArgumentException($"Invalid 'lineSpacing' value '{raw}'. Line spacing must be greater than 0.");
            return n;
        }

        // Auto/multiplier line spacing maps to w:line, which is
        // ST_SignedTwipsMeasure — negatives are schema-legal and real docs
        // carry them (e.g. <w:spacing w:line="-310" w:lineRule="auto"/> in a
        // style). Reject only zero (degenerate per BUG-R7-04); allow negative
        // so such styles round-trip instead of failing the whole add op.
        static double RequireNonZero(double n, string raw)
        {
            if (n == 0)
                throw new ArgumentException($"Invalid 'lineSpacing' value '{raw}'. Line spacing must not be zero.");
            return n;
        }

        // "1.5x" → multiplier (negative permitted under the Auto rule)
        if (trimmed.EndsWith("x", StringComparison.OrdinalIgnoreCase))
        {

View on GitHub (pinned to 1ced45e900)

Solutions

  1. For single spacing use a multiplier: '1x' or '100%', not a zero fixed length.
  2. For a small fixed line height use a positive value like '12pt'.
  3. If you need a zero-exact/atLeast pair, note Word's '0pt' atLeast is allowed only via the pt branch (see error 419 context), not via cm/in.

Example fix

// before
set paragraph lineSpacing=0cm
// after
set paragraph lineSpacing=1x
Defensive patterns

Strategy: validation

Validate before calling

var pts = SpacingConverter.ParsePoints(value);
if (pts <= 0) throw new ArgumentException($"lineSpacing must be > 0 for cm/in fixed: {value}");
// Use '1x'/'100%' for single spacing instead of a zero fixed length.

Try / catch

try { var (tw, mult) = SpacingConverter.ParseWordLineSpacing(value); }
catch (ArgumentException ex) when (ex.Message.Contains("greater than 0"))
{ /* use a positive fixed length or a multiplier like 1x */ }

Prevention

When it happens

Trigger: Passing '0cm', '-1cm', '0in', or '-0.5in' as a Word lineSpacing (the fixed cm/in branches call RequirePositive). The pt branch has its own negative-only check and the multiplier branches use RequireNonZero.

Common situations: A user tries to set zero fixed line spacing to mean 'no spacing', or copies a negative value; a script passes 0 expecting single-line behavior.

Related errors


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