iOfficeAI/OfficeCLI · error · ArgumentException

Pivot output range overlaps existing pivot '{existingPivot.N

Error message

Pivot output range overlaps existing pivot '{existingPivot.Name?.Value}' at {existingLoc}; choose a different anchor (--prop position=...).

What it means

Thrown by AddPivotTable's output-overlap guard when the conservative output rectangle of the new pivot intersects the <location> reference of an existing pivot on the same host sheet. Two overlapping pivots make Excel surface a 'found a problem' repair dialog because the output cells fight for ownership; this mirrors the table-table overlap check. Cross-sheet pivots are not compared.

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs:1773

                        $"pivot at {ptPosition} does not fit: computed end col={minEndColIdx} row={minEndRow} exceeds sheet dimensions (max XFD1048576)");
                }

                // CONSISTENCY(pivot-output-overlap): two pivot tables whose
                // <x:location> rectangles overlap on the same sheet make
                // Excel surface a "found a problem" repair dialog because
                // the output cells fight for ownership. Mirror the T4
                // table-table overlap check using the conservative output
                // bounds computed above. Cross-sheet pivots are fine.
                var newPivotRange = $"{IndexToColumnName(anchorColIdx)}{anchorRow}:" +
                                    $"{IndexToColumnName(minEndColIdx)}{minEndRow}";
                foreach (var existingPivot in ptWorksheet.PivotTableParts
                    .Select(ptp => ptp.PivotTableDefinition)
                    .Where(d => d != null))
                {
                    var existingLoc = existingPivot!.Location?.Reference?.Value;
                    if (string.IsNullOrEmpty(existingLoc)) continue;
                    if (RangesOverlap(newPivotRange.ToUpperInvariant(), existingLoc.ToUpperInvariant()))
                        throw new ArgumentException(
                            $"Pivot output range overlaps existing pivot " +
                            $"'{existingPivot.Name?.Value}' at {existingLoc}; " +
                            $"choose a different anchor (--prop position=...).");
                }
            }
        }

        // CONSISTENCY(tracking-rebind): CreatePivotTable internally rebinds
        // `properties` to a fresh non-tracking dictionary via
        // NormalizePivotProperties, so all subsequent TryGetValue calls
        // would never reach our TrackingPropertyDictionary comparer. Mark
        // every input key whose normalized form is a known pivot property
        // as consumed up-front, so they don't surface as false
        // unsupported_property warnings. Keys the helper genuinely doesn't
        // know about are still flagged via WarnUnknownPivotProperties +
        // CollectUnknownPivotKeys (R12-1).
        if (properties is OfficeCli.Core.TrackingPropertyDictionary ptTracking)
        {

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Choose a different anchor with --prop position=... that does not overlap the existing pivot.
  2. Remove or relocate the existing pivot first.
  3. Put the new pivot on a different sheet (cross-sheet overlap is allowed).

Example fix

// before (existing pivot at A1:F20)
add /Report/pivottable --prop source=Data!A1:D100 --prop position=C5
// after
add /Report/pivottable --prop source=Data!A1:D100 --prop position=H1
Defensive patterns

Strategy: validation

Validate before calling

// Check the candidate pivot output range against existing pivots on the host sheet before Add.
static bool OverlapsExistingPivot(ExcelHandler h, string sheet, string newRange)
{
    foreach (var loc in h.ListPivotLocations(sheet)) // pseudo
        if (RangesOverlap(newRange.ToUpperInvariant(), loc.ToUpperInvariant()))
            return true;
    return false;
}

Try / catch

try { handler.Add(parentPath, "pivottable", null, props); }
catch (ArgumentException ex) when (ex.Message.Contains("overlaps existing pivot"))
{ /* choose a different position or remove the existing pivot, then retry */ }

Prevention

When it happens

Trigger: Adding a second pivot whose anchor (position) produces an output range overlapping an existing pivot's location on the same sheet, even partially.

Common situations: Re-adding a pivot without removing the old one, auto-positioning landing on an existing pivot, or stacking pivots at the same anchor.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/9e2df3a08aac8f78. Report an issue: GitHub.