iOfficeAI/OfficeCLI · error · ArgumentException
Source range has no data
Error message
Source range has no data
What it means
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.
Source
Thrown at src/officecli/Core/PivotTableHelper.Readback.cs:416
newRef = newSourceSpec;
}
// Locate the source worksheet via the workbook part.
var workbookPart = pivotPart.GetParentParts().OfType<WorksheetPart>().FirstOrDefault()
?.GetParentParts().OfType<WorkbookPart>().FirstOrDefault()
?? throw new InvalidOperationException("Workbook part not reachable from pivot table part");
var sheetEntry = workbookPart.Workbook?.Sheets?.Elements<Sheet>()
.FirstOrDefault(s => s.Name?.Value == newSheetName)
?? throw new ArgumentException($"Source sheet not found: {newSheetName}");
if (sheetEntry.Id?.Value is not string srcRelId)
throw new InvalidOperationException("Source sheet has no relationship id");
var sourceWsPart = workbookPart.GetPartById(srcRelId) as WorksheetPart
?? throw new InvalidOperationException("Source sheet relationship does not resolve to a WorksheetPart");
// Re-read source data from the new range.
var (headers, columnData, _) = ReadSourceData(sourceWsPart, newRef);
if (headers.Length == 0)
throw new ArgumentException("Source range has no data");
if (columnData.Count == 0 || columnData[0].Length == 0)
throw new ArgumentException("Source range has no data rows");
// R15-2: Before mutating any cache/pivot state, validate that existing
// row/col/value/filter field references still fit inside the new
// (possibly narrower) header list. A silent drop or index clamp here
// would leave the DataFields pointing past the rendered columnData,
// crashing RenderPivotIntoSheet with ArgumentOutOfRangeException.
// Prefer strict error over data loss: user must explicitly restate the
// affected axes in the same Set call if they intended to drop them.
var newFieldCount = headers.Length;
var existingPivotDef = pivotPart.PivotTableDefinition;
if (existingPivotDef != null)
{
// Axes that the same Set call is explicitly overwriting are
// excluded from validation — their new values will be parsed
// against the fresh headers by RebuildFieldAreas.
bool rowsOverwritten = pendingFieldAreaProps?.ContainsKey("rows") == true;View on GitHub (pinned to 1ced45e900)
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).
Example fix
// before — row 1 is blank, headers are on row 2 Set pivot source=Sheet1!A1:D50 // after Set pivot source=Sheet1!A2:D50
Defensive patterns
Strategy: validation
Validate before calling
// Before Set source=, confirm the range has a non-empty header row
var (testHeaders, _, _) = ReadSourceData(sourceWsPart, testRange);
if (testHeaders.Length == 0)
throw new ArgumentException($"Range {testRange} has no header data — check coordinates."); Prevention
- 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).
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Source range has no data rows
- Source sheet not found: {newSheetName}
- {axis} field '{fieldRef}' (index {idx}) is out of range afte
- Source range has no data
- Source range has no data rows
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/9da0e82ed4758995.
Report an issue: GitHub.