Paper Office
paper-xlsxAPI referencepreserve.chartpatch

openpyxl.preserve.chartpatch

paper-xlsx 0.2.1 API reference

Targeted patches of series references inside PRESERVED chart parts, and of anchor positions inside preserved drawing parts, so row/column shifts can proceed on chart-referenced sheets.

Scope is honest — "if it slips, the refusal stands — never the silent third option": only <c:f> reference texts and <xdr:from>/<xdr:to> anchor markers are rewritten, located namespace-aware (openpyxl writes both families with DEFAULT namespaces; Excel and LibreOffice write c:/xdr: prefixes — both forms are handled by resolving names, never by matching prefixes). Charts carrying modern extension machinery (c15 filtered series, extLst, AlternateContent) refuse; a shift that would delete charted data refuses rather than write #REF! into a chart.

CHART_NS

attributeCHART_NS
= b'http://schemas.openxmlformats.org/drawingml/2006/chart'

DRAWING_MAIN_NS

attributeDRAWING_MAIN_NS
= b'http://schemas.openxmlformats.org/drawingml/2006/main'

XDR_NS

attributeXDR_NS
= b'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing'

parse_series_range

funcparse_series_range(text)

(sheet_title, range_part) for a sheet-qualified single-area range; raises ValueError on anything else (external refs, multi-area, array literals, unqualified ranges).

paramtext

patch_chart

funcpatch_chart(payload, sheet_title, operation, index, amount)

(new_payload, changed, blockers): rewrite every chart formula text referencing sheet_title per the shift.

parampayload
paramsheet_title
paramoperation
paramindex
paramamount

patch_chart_rename

funcpatch_chart_rename(payload, old_title, new_title)

Rewrite every chart formula text (<c:f>) referencing old_title to new_title. Returns the patched payload, or None when nothing referenced the old title. Refuses when the chart carries machinery whose references the patch cannot see (the same blocker set as shift patching).

parampayload
paramold_title
paramnew_title

patch_chart_renames

funcpatch_chart_renames(payload, mapping)

Rewrite chart formula texts through a SIMULTANEOUS title mapping (title swaps must never merge reference classes). Returns the patched payload or None when nothing matched.

parampayload
parammapping

patch_drawing_anchors

funcpatch_drawing_anchors(payload, operation, index, amount)

(new_payload, changed): move drawing anchor markers with the cells (from/to row and col elements in the spreadsheetDrawing namespace).

parampayload
paramoperation
paramindex
paramamount

plan_chart_updates

funcplan_chart_updates(wb, sheet_title, operation, index, amount, overrides=None)

Plan every chart/drawing part patch for a shift on sheet_title.

Returns ({part_name: new_payload}, blockers). Used twice: as a dry run when the edit is attempted (blockers refuse before any mutation) and for real at save time. overrides supplies already-planned payloads so a part touched by an earlier shift is patched incrementally.

paramwb
paramsheet_title
paramoperation
paramindex
paramamount
paramoverrides
= None

plan_property_edits

funcplan_property_edits(wb, ws, key, armed, current, original, allow_composed_formula_baseline=False)

A loaded chart's model drifted since arm: express the drift as byte patches on the ORIGINAL part bytes, or refuse naming the first property chartpatch cannot express. Expressible: series/axis formula texts (<c:f>) and text runs (<a:t> — titles, axis titles). Cached series values are left as-is: Excel re-reads series from cells when it renders the chart.

paramwb
paramws
paramkey
paramarmed
paramcurrent
paramoriginal
paramallow_composed_formula_baseline
= False

On this page