{"record":{"id":"2c2ef03324727b0f","repo":"iOfficeAI/OfficeCLI","slug":"invalid-width-value-value-expected-a-finit-2c2ef0","errorCode":null,"errorMessage":"Invalid 'width' value: '{value}'. Expected a finite number or unit-qualified value (e.g. 8.43, 20px, 2cm, 1in, 60pt).","messagePattern":"Invalid 'width' value: '(.+?)'\\. Expected a finite number or unit-qualified value \\(e\\.g\\. 8\\.43, 20px, 2cm, 1in, 60pt\\)\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.cs","lineNumber":190,"sourceCode":"                System.Globalization.CultureInfo.InvariantCulture, out var bare)\n            && !char.IsLetter(trimmed[^1]))\n        {\n            if (double.IsNaN(bare) || double.IsInfinity(bare))\n                throw new ArgumentException($\"Invalid 'width' value: '{value}'. Expected a finite number (column width in char units, e.g. 8.43).\");\n            chars = bare;\n        }\n        else\n        {\n            try\n            {\n                var emu = OfficeCli.Core.EmuConverter.ParseEmu(trimmed);\n                // 9525 EMU = 1 px; 7 px ≈ 1 char unit (Calibri 11pt MDW baseline)\n                var px = emu / EmuConverter.EmuPerPxF;\n                chars = px / 7.0;\n            }\n            catch (Exception ex)\n            {\n                throw new ArgumentException($\"Invalid 'width' value: '{value}'. Expected a finite number or unit-qualified value (e.g. 8.43, 20px, 2cm, 1in, 60pt).\", ex);\n            }\n        }\n        // DEFERRED(xlsx/row-height-validation) RC2: Excel column width is bounded\n        // [0, 255] character units. Validate at Set time.\n        if (chars < 0 || chars > 255)\n            throw new ArgumentException($\"Invalid 'width' value: '{value}'. Column width must be between 0 and 255 character units.\");\n        return chars;\n    }\n\n    // Returns true if `s` would parse as a valid cell reference (e.g. A1,\n    // TBL1, XFD1048576). Excel refuses to open files whose table names match\n    // this pattern — the name is ambiguous with a cell address.\n    internal static bool LooksLikeCellReference(string? s)\n    {\n        if (string.IsNullOrEmpty(s)) return false;\n        var m = System.Text.RegularExpressions.Regex.Match(s, @\"^\\$?([A-Za-z]{1,3})\\$?([0-9]+)$\");\n        if (!m.Success) return false;\n        var col = m.Groups[1].Value.ToUpperInvariant();","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.cs#L172-L208","documentation":"Thrown by ParseColWidthChars when the input is unit-qualified (last char is a letter) but EmuConverter.ParseEmu rejected it. The inner exception carries the precise reason (unknown unit, bad numeric prefix, font-context unit like 'em').","triggerScenarios":"Passing width=2em, width=20ft, width=abc px, or any unit-qualified value whose prefix or suffix EmuConverter refuses.","commonSituations":"AI assistants defaulting to 'em'/'rem'; typoed unit suffixes; locale comma decimals in the numeric prefix; passing '%' which is unsupported.","solutions":["Use a supported unit for column width: px, cm, in, pt, mm (e.g. width=20px, width=2cm).","Inspect the inner exception for the precise reason and fix the prefix or unit.","Use a dot decimal separator in the numeric prefix."],"exampleFix":"// before\nset /Sheet1/col[B] --prop width=2em\n\n// after (no font context -> convert em yourself, e.g. 2em at Calibri 11pt ≈ 14pt)\nset /Sheet1/col[B] --prop width=14pt","handlingStrategy":"try-catch","validationCode":"static readonly Regex ColWidthRe = new(@\"^\\s*-?\\d+(\\.\\d+)?\\s*(px|cm|mm|in|pt)?\\s*$\", RegexOptions.IgnoreCase);\nstatic bool IsValidColWidth(string v) => !string.IsNullOrWhiteSpace(v) && ColWidthRe.IsMatch(v);","typeGuard":null,"tryCatchPattern":"try { var chars = ExcelHandler.ParseColWidthChars(value); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"'width'\"))\n{ /* inspect ex.InnerException for the EmuConverter reason */ }","preventionTips":["Restrict column-width units to px/cm/in/pt/mm; 'em'/'rem'/'%' are unsupported.","Use a dot decimal separator in the numeric prefix.","Read the inner exception for the precise cause on failure."],"tags":["excel","validation","column-width","units"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}