{"record":{"id":"bded65ca74ee46bd","repo":"iOfficeAI/OfficeCLI","slug":"invalid-source-range-sourceref","errorCode":null,"errorMessage":"Invalid source range: {sourceRef}","messagePattern":"Invalid source range: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/PivotTableHelper.Cache.cs","lineNumber":264,"sourceCode":"            9  => \"Sep\", 10 => \"Oct\", 11 => \"Nov\", 12 => \"Dec\",\n            _  => month.ToString(System.Globalization.CultureInfo.InvariantCulture),\n        };\n\n    private static string CapitalizeFirst(string s)\n        => string.IsNullOrEmpty(s) ? s : char.ToUpperInvariant(s[0]) + s.Substring(1);\n\n    // ==================== Source Data Reader ====================\n\n    private static (string[] headers, List<string[]> columnData, uint?[] columnStyleIds) ReadSourceData(\n        WorksheetPart sourceSheet, string sourceRef)\n    {\n        var ws = sourceSheet.Worksheet ?? throw new InvalidOperationException(\"Worksheet missing\");\n        var sheetData = ws.GetFirstChild<SheetData>();\n        if (sheetData == null) return (Array.Empty<string>(), new List<string[]>(), Array.Empty<uint?>());\n\n        // Parse range \"A1:D100\"\n        var parts = sourceRef.Replace(\"$\", \"\").Split(':');\n        if (parts.Length != 2) throw new ArgumentException($\"Invalid source range: {sourceRef}\");\n\n        var (startCol, startRow) = ParseCellRef(parts[0]);\n        var (endCol, endRow) = ParseCellRef(parts[1]);\n\n        var startColIdx = ColToIndex(startCol);\n        var endColIdx = ColToIndex(endCol);\n        // R6-3: reject columns beyond Excel's hard max (XFD = 16384). Previously\n        // XFE / XFZ / ZZZZ silently parsed into oversized indices, produced a\n        // giant colCount, and either crashed deep in the renderer or wrote an\n        // invalid source range into the cache.\n        const int ExcelMaxColumn = 16384; // XFD\n        if (startColIdx > ExcelMaxColumn)\n            throw new ArgumentException($\"Column {startCol} out of range (max: XFD)\");\n        if (endColIdx > ExcelMaxColumn)\n            throw new ArgumentException($\"Column {endCol} out of range (max: XFD)\");\n        var colCount = endColIdx - startColIdx + 1;\n\n        // Read all rows in range. We also capture the StyleIndex of the first","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/PivotTableHelper.Cache.cs#L246-L282","documentation":"ArgumentException thrown in ReadSourceData when the sourceRef does not parse as exactly two colon-separated cell refs (after stripping '$'). The reader expects an Excel range like 'A1:D100'. Anything without exactly one ':' — a single cell, three parts, or no colon — is rejected.","triggerScenarios":"Passing a pivot table sourceRef / source range that is a single cell ('A1'), a whole-column form the reader does not accept, has multiple colons ('A1:B2:C3'), or is empty/garbage. sourceRef.Replace(\"$\",\"\").Split(':') must yield exactly 2 parts.","commonSituations":"Using a single-cell reference where a full range is required; passing a named range instead of an A1-style range; malformed range from user input or a broken dump/round-trip.","solutions":["Supply a two-corner A1 range including both endpoints, e.g. sourceRef=\"A1:D100\".","Remove any extra colons; whole-sheet references must be spelled with the full corner range (e.g. 'A1:Z1000'), not a single cell.","Ensure the value is an A1 range, not a defined name."],"exampleFix":"// before\nsourceRef=\"A1\"\n// after\nsourceRef=\"A1:D100\"","handlingStrategy":"validation","validationCode":"// Require exactly two colon-separated corners after stripping $:\nstatic bool IsValidSourceRange(string sourceRef)\n    => sourceRef.Replace(\"$\", \"\").Split(':').Length == 2;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a full two-corner A1 range (e.g. A1:D100) for pivot sources.","Do not pass single cells, named ranges, or multi-colon expressions.","Validate the range shape before building the pivot cache."],"tags":["pivot-table","excel","input-validation","range","ooxml","officecli"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}