{"record":{"id":"be1fc62a8c79b850","repo":"iOfficeAI/OfficeCLI","slug":"column-endcol-out-of-range-max-xfd","errorCode":null,"errorMessage":"Column {endCol} out of range (max: XFD)","messagePattern":"Column (.+?) out of range \\(max: XFD\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/PivotTableHelper.Cache.cs","lineNumber":279,"sourceCode":"\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\n        // non-empty data cell per column (skipping the header row) so pivot\n        // value cells can inherit the source column's number format. This\n        // mirrors how Excel's pivot engine picks the column format: it looks\n        // at the data-area formatting, not the header.\n        var rows = new List<string[]>();\n        var columnStyleIds = new uint?[colCount];\n        var sst = sourceSheet.OpenXmlPackage is SpreadsheetDocument doc\n            ? doc.WorkbookPart?.GetPartsOfType<SharedStringTablePart>().FirstOrDefault()\n            : null;\n\n        foreach (var row in sheetData.Elements<Row>())\n        {\n            var rowIdx = (int)(row.RowIndex?.Value ?? 0);\n            if (rowIdx < startRow || rowIdx > endRow) continue;\n","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/PivotTableHelper.Cache.cs#L261-L297","documentation":"ArgumentException thrown in ReadSourceData when the END column of the source range exceeds Excel's hard maximum (XFD = column 16384). Same R6-3 guard as the start-column check, applied to the second corner of the range.","triggerScenarios":"Passing a sourceRef whose second corner uses a column beyond XFD — e.g. 'A1:XFE100', 'A1:XFZ100', or 'A1:ZZZZ'. The end column's ColToIndex exceeds 16384 and the guard fires.","commonSituations":"Hand-typing an oversized end column; programmatic column-letter generation past XFD; a range that 'extends past the sheet'; mistyping the end corner.","solutions":["Keep the end column within A..XFD (1..16384), e.g. sourceRef=\"A1:XFD100\" at most.","Clamp generated end-column letters to the 16384 maximum.","Verify the end corner is not past the real data extent / sheet limit."],"exampleFix":"// before\nsourceRef=\"A1:XFE100\"\n// after\nsourceRef=\"A1:XFD100\"","handlingStrategy":"validation","validationCode":"static int ColToIndex(string col)\n{\n    int idx = 0;\n    foreach (var ch in col.ToUpperInvariant()) { if (ch < 'A' || ch > 'Z') return -1; idx = idx * 26 + (ch - 'A' + 1); }\n    return idx;\n}\nstatic bool EndColumnInRange(string sourceRef)\n{\n    var endCell = sourceRef.Replace(\"$\",\"\").Split(':')[1];\n    var letters = new string(endCell.TakeWhile(char.IsLetter).ToArray());\n    return ColToIndex(letters) <= 16384;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep end columns within A..XFD (1..16384).","Clamp generated end-column letters to the 16384 maximum.","Ensure the end corner is within the real data extent."],"tags":["pivot-table","excel","input-validation","range","column-limit","ooxml","officecli"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}