Paper Office
paper-xlsxAPI referencepreserve.drawings

openpyxl.preserve.drawings

paper-xlsx 0.2.1 API reference

Charts and images added in-session become NEW drawing/chart/media parts through the lifecycle engine — the stock writer's own serialization, never a re-render of preserved bytes.

Three shapes, in increasing contact with original bytes:

  • ADDED sheet: the stock worksheet writer already emitted <drawing r:id>; this module supplies the parts and fills the rel.
  • LOADED sheet, no drawing machinery: a fresh drawing part plus ONE <drawing r:id> element spliced into the sheet at its schema position.
  • LOADED sheet, existing drawing: new anchors appended INTO the original drawing part — only when that part is anchor-only; anything else refuses.

Preserved drawing parts are never re-serialized: appends are byte insertions before the closing tag, with namespaces declared on the inserted anchors themselves.

CHART_CT

attributeCHART_CT
= 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml'

CHART_REL_TYPE

attributeCHART_REL_TYPE
= REL_NS + '/chart'

DRAWING_CT

attributeDRAWING_CT
= 'application/vnd.openxmlformats-officedocument.drawing+xml'

DRAWING_REL_TYPE

attributeDRAWING_REL_TYPE
= REL_NS + '/drawing'

IMAGE_REL_TYPE

attributeIMAGE_REL_TYPE
= REL_NS + '/image'

REL_NS

attributeREL_NS
= 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'

SHEET_DRAWING_NS

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

plan_added_sheet_drawing

funcplan_added_sheet_drawing(workbook, ws, part_plan, names, rel_entries)

Charts/images on an ADDED sheet: the stock writer emitted <drawing r:id> into the fresh sheet payload with an empty rel Target; supply the drawing/chart/media parts and fill the target. Returns the updated sheet rel entries.

paramworkbook
paramws
parampart_plan
paramnames
paramrel_entries

plan_drawing_append

funcplan_drawing_append(workbook, ws, part_plan, names, drawing_part, original, existing_rels, charts, images)

Charts/images on a LOADED sheet whose drawing already exists: new anchors appended INTO the original drawing bytes (original may already carry this save's shift patches) — only when that drawing is anchor-only. Returns the new drawing payload.

paramworkbook
paramws
parampart_plan
paramnames
paramdrawing_part
paramoriginal
paramexisting_rels
paramcharts
paramimages

plan_fresh_drawing

funcplan_fresh_drawing(workbook, ws, part_plan, names, sheet_part, original_sheet_rels, charts, images)

Charts/images on a LOADED sheet with no drawing machinery: a fresh drawing part via the engine plus ONE spliced element. Returns the <drawing r:id> bytes for the region splice.

paramworkbook
paramws
parampart_plan
paramnames
paramsheet_part
paramoriginal_sheet_rels
paramcharts
paramimages

On this page