{"record":{"id":"4790537e9bfade18","repo":"iOfficeAI/OfficeCLI","slug":"picture-shape-name-must-be-positive-got-value","errorCode":null,"errorMessage":"Picture/shape {name} must be positive (got '{value}').","messagePattern":"Picture/shape (.+?) must be positive \\(got '(.+?)'\\)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs","lineNumber":1449,"sourceCode":"    }\n\n    /// <summary>\n    /// Parse a width/height anchor value that is either a plain integer\n    /// cell-count (\"3\", \"5\") or a unit-qualified size (\"6cm\", \"2in\", \"72pt\").\n    /// Unit-qualified values are converted to an approximate cell count using\n    /// Excel's default ~64px (~0.66cm) column width and ~15pt row height.\n    /// CONSISTENCY(ole-width-units): Picture/Drawing elsewhere accept ParseEmu;\n    /// anchor.x/y stay as cell coordinates, but width/height tolerate EMU units.\n    /// </summary>\n    private static int ParseAnchorDimension(string value, string name)\n    {\n        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","sourceCodeStart":1431,"sourceCodeEnd":1467,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs#L1431-L1467","documentation":"Thrown by ParseAnchorDimension when a plain-integer width/height parses but is <= 0. Width/height as cell counts must be strictly positive; zero or negative would produce an invalid TO marker (cx=0/cy=0 or negative spans) that Excel rejects on open. The guard is symmetric with ParseAnchorDimensionEmu's negative-int guard (R30-1).","triggerScenarios":"Passing width=0, height=-5, or width=-1 as bare integers. Zero is rejected because a zero-span anchor is meaningless; the unit-qualified zero/negative case is handled separately at line 1466.","commonSituations":"Defaulting an unknown width to 0; sign errors in computed dimensions; expecting width=0 to mean 'auto' (it does not - use a unit-qualified or cell-range anchor instead).","solutions":["Pass a positive integer cell count: width=3.","If you meant 'size to content', use a twoCell anchor with anchor='B2:D2' so the span is implied by the cell range.","Clamp computed values to >= 1 before passing.","Use a unit-qualified positive size: width='2in'."],"exampleFix":"// before\nshape width=0\n// after\nshape width=3","handlingStrategy":"validation","validationCode":"bool IsValidDimensionInt(string value)\n    => int.TryParse(value, out var i) && i > 0;","typeGuard":"static bool IsPositiveCellCount(string s)\n    => int.TryParse(s, out var i) && i > 0;","tryCatchPattern":"try { ParseAnchorDimension(value, \"width\"); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"must be positive\"))\n{\n    // default to a sensible positive cell count, or surface a user error\n}","preventionTips":["Use a positive integer cell count for width/height (>=1).","Use a twoCell cell-range anchor for auto-sizing.","Clamp computed dimensions to >= 1.","Do not pass 0 expecting auto-size behavior."],"tags":["excel","drawing","anchor","dimension","validation","cell-index"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}