iOfficeAI/OfficeCLI · error · ArgumentException
Source range has no data rows
Error message
Source range has no data rows
What it means
Thrown by RefreshPivotCacheFromSource when headers were found but columnData has zero rows (columnData.Count == 0 or columnData[0].Length == 0). The source range is header-only — e.g. A1:D1 has column names but no data rows beneath them. A pivot with zero source records produces an empty cache; this guard rejects it early with the same ArgumentException family as the no-headers case.
Source
Thrown at src/officecli/Core/PivotTableHelper.Readback.cs:418
// 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;
bool colsOverwritten = pendingFieldAreaProps?.ContainsKey("cols") == true;
bool valuesOverwritten = pendingFieldAreaProps?.ContainsKey("values") == true;View on GitHub (pinned to 1ced45e900)
Solutions
- Extend the range to include at least one data row below the header (e.g. A1:D2 minimum).
- Confirm the worksheet actually contains populated data rows in the specified columns.
- If using a dynamic range, verify it resolves to more than one row.
Example fix
// before Set pivot source=Sheet1!A1:D1 // after Set pivot source=Sheet1!A1:D100
Defensive patterns
Strategy: validation
Validate before calling
// Before Set source=, confirm the range has at least one data row
var (testHeaders, testRows, _) = ReadSourceData(sourceWsPart, testRange);
if (testHeaders.Length > 0 && (testRows.Count == 0 || testRows[0].Length == 0))
throw new ArgumentException($"Range {testRange} is header-only — no data rows."); Prevention
- Ensure the range spans at least two rows (header + one data row).
- Verify data exists below the header row in the specified columns.
- Avoid using single-row ranges as pivot sources.
When it happens
Trigger: Calling Set source=A1:D1 (only the header row, no data). Or pointing at a range whose data rows are all blank so ReadSourceData yields zero record rows.
Common situations: The source range's bottom boundary is set too high (e.g. A1:D1 instead of A1:D100); the worksheet has headers but the data was cleared; template worksheet where data hasn't been populated yet.
Related errors
- Source range has no data
- 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/450a0fadfaa07d6a.
Report an issue: GitHub.