{"record":{"id":"d2fe9a7a2febc7de","repo":"iOfficeAI/OfficeCLI","slug":"expected-an-integer-cell-count-or-a-unit-qualified","errorCode":null,"errorMessage":"Expected an integer cell count or a unit-qualified size (e.g. '6cm', '2in') for {name}, got '{value}'.","messagePattern":"Expected an integer cell count or a unit-qualified size \\(e\\.g\\. '6cm', '2in'\\) for (.+?), got '(.+?)'\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs","lineNumber":1461,"sourceCode":"        if (int.TryParse(value, out var plainInt))\n        {\n            // R30-1: negative cell-count is meaningless and silently\n            // produced an invalid file. Reject up front. CONSISTENCY with\n            // ParseAnchorDimensionEmu's negative-int guard.\n            if (plainInt <= 0)\n                throw new ArgumentException($\"Picture/shape {name} must be positive (got '{value}').\");\n            return plainInt;\n        }\n\n        // Not a plain integer — treat as EMU-convertible size string.\n        long emu;\n        try\n        {\n            emu = OfficeCli.Core.EmuConverter.ParseEmu(value);\n        }\n        catch\n        {\n            throw new ArgumentException($\"Expected an integer cell count or a unit-qualified size (e.g. '6cm', '2in') for {name}, got '{value}'.\");\n        }\n        // R30-1: unit-qualified negative (\"-2in\") parses to a negative\n        // EMU; reject so the shape branch matches picture behavior.\n        if (emu <= 0)\n            throw new ArgumentException($\"Picture/shape {name} must be positive (got '{value}').\");\n\n        // Rough conversion: 1 default Excel column ≈ 64px ≈ 0.677cm ≈ 609600 EMU.\n        // 1 default Excel row    ≈ 15pt ≈ 0.529cm ≈ 190500 EMU.\n        // For width/height passed as a unit, choose the larger of the two\n        // converters so \"6cm\" yields a sensible ~9 columns result either axis.\n        const long emuPerColApprox = 609600;\n        const long emuPerRowApprox = 190500;\n        if (name == \"height\")\n            return Math.Max(1, (int)(emu / emuPerRowApprox));\n        return Math.Max(1, (int)(emu / emuPerColApprox));\n    }\n\n    // CONSISTENCY(ole-width-units): OLE round-trip preserves sub-cell precision","sourceCodeStart":1443,"sourceCodeEnd":1479,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs#L1443-L1479","documentation":"Thrown by ParseAnchorDimension when the value is neither a plain integer nor a unit-qualified size parseable by EmuConverter.ParseEmu. ParseAnchorDimension accepts an integer cell count ('3','5') or a unit-qualified size ('6cm','2in','72pt') converted to an approximate cell count. Any other syntax is invalid.","triggerScenarios":"Passing width='abc', width='50%', width='3cols', width='B2:D2' (cell ranges belong on anchor=, not width), or width='5em' (unsupported font-relative unit). EmuConverter's inner exception is wrapped and re-thrown with this message.","commonSituations":"Passing a cell-range where a dimension is expected; using percentage or font-relative units; typos in unit suffixes; mixing the anchor= and width/height grammars.","solutions":["Pass a positive integer cell count: width=3.","Or pass a unit-qualified size with a supported unit: width='2in', width='6cm', width='72pt'.","To size by cell range, use anchor='B2:D2' on a twoCell anchor instead of width/height.","Avoid unsupported units (% em ex rem vw vh) and check for suffix typos."],"exampleFix":"// before\nshape width=50%\n// after\nshape width=2in","handlingStrategy":"validation","validationCode":"bool IsValidAnchorDimension(string value)\n    => int.TryParse(value, out _)\n       || OfficeCli.Core.EmuConverter.TryParseEmu(value, out _);","typeGuard":"static bool IsAnchorDimensionValue(string s)\n    => int.TryParse(s, out _) || OfficeCli.Core.EmuConverter.TryParseEmu(s, out _);","tryCatchPattern":"try { ParseAnchorDimension(value, \"width\"); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Expected an integer cell count\"))\n{\n    // not a cell count or unit-qualified size; surface a user error\n}","preventionTips":["Pass either a positive integer cell count or a unit-qualified size (cm/in/pt/px/emu).","Do not pass cell ranges (use anchor=) or percentages.","Avoid unsupported units (% em ex rem vw vh).","Pre-validate with EmuConverter.TryParseEmu when sourcing from user input."],"tags":["excel","drawing","anchor","dimension","emu","units","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}