{"record":{"id":"9da0e82ed4758995","repo":"iOfficeAI/OfficeCLI","slug":"source-range-has-no-data","errorCode":null,"errorMessage":"Source range has no data","messagePattern":"Source range has no data","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/PivotTableHelper.Readback.cs","lineNumber":416,"sourceCode":"            newRef = newSourceSpec;\n        }\n\n        // Locate the source worksheet via the workbook part.\n        var workbookPart = pivotPart.GetParentParts().OfType<WorksheetPart>().FirstOrDefault()\n            ?.GetParentParts().OfType<WorkbookPart>().FirstOrDefault()\n            ?? throw new InvalidOperationException(\"Workbook part not reachable from pivot table part\");\n        var sheetEntry = workbookPart.Workbook?.Sheets?.Elements<Sheet>()\n            .FirstOrDefault(s => s.Name?.Value == newSheetName)\n            ?? throw new ArgumentException($\"Source sheet not found: {newSheetName}\");\n        if (sheetEntry.Id?.Value is not string srcRelId)\n            throw new InvalidOperationException(\"Source sheet has no relationship id\");\n        var sourceWsPart = workbookPart.GetPartById(srcRelId) as WorksheetPart\n            ?? throw new InvalidOperationException(\"Source sheet relationship does not resolve to a WorksheetPart\");\n\n        // Re-read source data from the new range.\n        var (headers, columnData, _) = ReadSourceData(sourceWsPart, newRef);\n        if (headers.Length == 0)\n            throw new ArgumentException(\"Source range has no data\");\n        if (columnData.Count == 0 || columnData[0].Length == 0)\n            throw new ArgumentException(\"Source range has no data rows\");\n\n        // R15-2: Before mutating any cache/pivot state, validate that existing\n        // row/col/value/filter field references still fit inside the new\n        // (possibly narrower) header list. A silent drop or index clamp here\n        // would leave the DataFields pointing past the rendered columnData,\n        // crashing RenderPivotIntoSheet with ArgumentOutOfRangeException.\n        // Prefer strict error over data loss: user must explicitly restate the\n        // affected axes in the same Set call if they intended to drop them.\n        var newFieldCount = headers.Length;\n        var existingPivotDef = pivotPart.PivotTableDefinition;\n        if (existingPivotDef != null)\n        {\n            // Axes that the same Set call is explicitly overwriting are\n            // excluded from validation — their new values will be parsed\n            // against the fresh headers by RebuildFieldAreas.\n            bool rowsOverwritten = pendingFieldAreaProps?.ContainsKey(\"rows\") == true;","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/PivotTableHelper.Readback.cs#L398-L434","documentation":"Thrown by RefreshPivotCacheFromSource after ReadSourceData(sourceWsPart, newRef) returns an empty headers array. This means the new source range produced no header row at all — the cells at the top of the specified range are entirely empty, or the range reference itself resolves to nothing readable.","triggerScenarios":"Calling Set source=A1:Z50 where every cell in row 1 (the header row) is empty. Or passing a range reference whose syntax is malformed so ReadSourceData interprets it as an empty region.","commonSituations":"Pointing the source at the wrong region of a sheet; the data was moved and the old range is now blank; off-by-one in the range (e.g. header row is actually row 2 but spec says A1); range points below the last used row.","solutions":["Verify the range's first row contains at least one non-empty cell to serve as the header.","Double-check the range coordinates — the top-left cell should be the first header.","If the data moved, update the range to the new location.","Confirm the range reference syntax matches what ReadSourceData expects (e.g. A1:D10)."],"exampleFix":"// before — row 1 is blank, headers are on row 2\nSet pivot source=Sheet1!A1:D50\n// after\nSet pivot source=Sheet1!A2:D50","handlingStrategy":"validation","validationCode":"// Before Set source=, confirm the range has a non-empty header row\nvar (testHeaders, _, _) = ReadSourceData(sourceWsPart, testRange);\nif (testHeaders.Length == 0)\n    throw new ArgumentException($\"Range {testRange} has no header data — check coordinates.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always verify the range's top row has at least one populated cell.","Confirm the top-left cell of the range is the first header.","Check for off-by-one errors in range coordinates (header row position)."],"tags":["pivot","excel","source-range","empty-data","set-property"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}