{"record":{"id":"bab72837f6a19237","repo":"iOfficeAI/OfficeCLI","slug":"invalid-width-value-value-column-width-mus","errorCode":null,"errorMessage":"Invalid 'width' value: '{value}'. Column width must be between 0 and 255 character units.","messagePattern":"Invalid 'width' value: '(.+?)'\\. Column width must be between 0 and 255 character units\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.cs","lineNumber":196,"sourceCode":"        }\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();\n        var colIdx = 0;\n        foreach (var ch in col) colIdx = colIdx * 26 + (ch - 'A' + 1);\n        if (colIdx < 1 || colIdx > 16384) return false;\n        if (!long.TryParse(m.Groups[2].Value, out var row) || row < 1 || row > 1048576) return false;\n        return true;\n    }","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.cs#L178-L214","documentation":"Thrown by ParseColWidthChars after a successful parse when the resulting width in character units falls outside Excel's [0, 255] bound. Excel rejects files with out-of-range column widths, so this validates at Set time.","triggerScenarios":"Passing width=300, width=-3, or a unit conversion whose char-unit value exceeds 255 (e.g. width=50cm ≈ 283 char units -> rejected).","commonSituations":"Treating the value as pixels (width=255 thinking 255px ≈ 36 char units, which is fine, but width=2000px ≈ 285 char units is rejected); negative widths from a sign error; very large physical conversions.","solutions":["Clamp the value into [0, 255] character units (Excel's documented maximum column width is 255).","If you intended pixels, note the 7-px-per-char approximation: char_units ≈ pixels / 7.","Re-check the unit; 255 char units is roughly 1785px, 47cm, or 18.7in."],"exampleFix":"// before\nset /Sheet1/col[B] --prop width=300\n\n// after\nset /Sheet1/col[B] --prop width=255","handlingStrategy":"validation","validationCode":"const double ColWidthMax = 255.0;\ndouble chars = ExcelHandler.ParseColWidthChars(value);   // assume parse succeeded\nif (chars < 0 || chars > ColWidthMax)\n    throw new ArgumentException($\"Column width {chars} char-units is out of [0, {ColWidthMax}].\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp column widths to [0, 255] character units before setting.","Approximate char-units from pixels as pixels/7."],"tags":["excel","validation","column-width","bounds","ooxml"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}