Skip to content

PPTX export: a workbook for edited and new charts, updated in place when the data changes - #241

Open
pierrevbc wants to merge 3 commits into
storytold:mainfrom
pierrevbc:chart-workbook
Open

pierrevbc wants to merge 3 commits into
storytold:mainfrom
pierrevbc:chart-workbook

Conversation

@pierrevbc

@pierrevbc pierrevbc commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Since #355, an unchanged chart keeps the embedded workbook it was read with (and the other parts
its relationships reach, in Chart.kept) when the presentation is saved as PPTX. What is still
lost:

  • Any edit drops the workbook. Every chart command (chart.type, chart.data,
    chart.options) clears Chart.raw, so after a title change, a new legend or one changed value
    the chart is no longer "unchanged" and is saved without c:externalData or a workbook. Edit Data
    in other presentation apps has nothing to open, and the workbook's other sheets, formulas and
    formatting are gone.
  • Charts made in DeckCraft have no workbook at all.

Reproduce on main with a public file, not for committing:

  1. features/steps/test_files/cht-charts.pptx from scanny/python-pptx (commit 278b47b), or
    test-data/slideshow/aascu.org_hbcu_leadershipsummit_cooper_.pptx from apache/poi (slides 6
    and 7, one chart each).
  2. deckcraft-cli run --in cht-charts.pptx --cmd 'chart.options={"title":"New"}' --export out.pptx
    (any chart command), or insert a chart and export.
  3. unzip -l out.pptx | grep embeddings prints nothing for that chart; its chartN.xml has no
    c:externalData.

Design

The workbook stays where #355 put it: in Chart.kept, the package parts an imported chart points
at. No new media item, no new field for it in the model. ChartKept::workbook() finds the kept
workbook part (the internal package or oleObject target of the chart's relationships).

On export, Exp::chart_rel:

  1. Unchanged chart (its kept part still describes the model): Charts: keep the embedded workbook when a chart is saved unchanged (#335) #355's path, untouched. The
    original part goes back with every kept part under fresh keptN names.
  2. Edited chart whose data still fits its original ranges (Chart.source, commit 2): the
    chart part is written from the model with its original formulas, and the kept workbook is
    written next to it: byte for byte when only the presentation changed (title, type, legend…),
    with only the changed cells rewritten when the data changed.
  3. Anything else (a chart made in DeckCraft, series or points added or removed…): a workbook is
    generated from the chart data, laid out where the generated chart part's formulas point, with
    its c:externalData.

An Office 2016 chart's plain-chart fallback gets no workbook, as with #355: it belongs to the
chartEx part.

What changes

Two commits, then a separate one adding my entry to contributors/people.toml
([people.pierrevbc], display name only).

1. pptx: write a workbook for edited and new charts

  • Model. ChartKept::workbook().
  • Export. Cases 1 and 3 above: an edited or new chart gets a minimal generated workbook (one
    sheet, Sheet1, inline strings; categories in column A, one column per series, series names on
    row 1) under ppt/embeddings/workbook{n}.xlsx, a package relationship and
    c:externalData.
  • Layout fix. Scatter series with different X values, and bubble charts with several series,
    get columns of their own. Before, every scatter series pointed at column A for its X values and
    bubble sizes used col(i + 2), which overlapped the next series' values.
  • Charts: keep the embedded workbook when a chart is saved unchanged (#335) #355's tests in chart_embed.rs: the fixtures strip the workbook the writer now generates
    for a new chart (to stand for a file from an app that writes none);
    an_edited_chart_does_not_write_a_stale_workbook now checks that the stale bytes are not
    written and that the chart gets one workbook of its own data.

2. pptx: update chart workbooks in place instead of rebuilding them

  • Model. Chart.source: Option<ChartSource>: for each series of an imported chart, the
    formulas of its name, categories (or X values), values and bubble sizes (c:f), and the data the
    chart part cached for them. Commands leave it alone, unlike raw. Skipped when absent, so
    existing .deckcraft files serialize as before.
  • Export, data unchanged. When the data still fits the original ranges (same series and point
    counts, same category or XY family, formulas present), the chart part is written with its
    original formulas and the kept workbook is written back byte for byte.
  • Export, data changed. Only the cells whose data differs from what was read are rewritten in
    the kept workbook (crates/pptx/src/write/xlsx.rs, quick-xml and zip, no new dependency, no
    file or network I/O). Every other zip entry is copied with its compressed bytes. In the
    workbook:
    • a cell keeps its style; text is written as an inline string;
    • a new header in a table renames the table column, which Excel requires;
    • a value typed over a formula replaces it, and calcChain.xml (with its relationship and
      content type) is dropped so Excel does not repair the file; Excel rebuilds it;
    • fullCalcOnLoad="1" is set on calcPr when the workbook holds formulas, so formulas
      elsewhere follow the new values.
  • Fallback to a generated workbook (case 3, with a warning in the log) when: series or points
    were added or removed; a category chart became a scatter or bubble chart (or back); the chart
    part held literal data; a formula is not one row or column of one sheet (unions, names, other
    workbooks); a target cell holds a shared or array formula; a new table column name is empty,
    clashes with another column, or appears in a structured reference; a linked workbook's data
    changed; the workbook is an older OLE embedding.

How it was tested

cargo xtask ci passes on this branch, on main at 9859da3 (all 7 steps: fmt, pdf-deps, clippy
-D warnings, 1,687 tests passed and 6 ignored, assets, layers, wasm32 check). On Windows the
deckcraft-ui-egui lib tests sometimes crash with an access violation when run in parallel, on
main as well; the run above used RUST_TEST_THREADS=1.

New and changed tests, all on decks and workbooks built in code:

  • write::chart unit tests: for 11 chart variants (column, stacked bar, line, pie, radar, combo,
    scatter with shared and with separate X values, single-series bubble, multi-series bubble with
    shared and with separate X values), every cached value in the chart part equals the workbook
    cell its formula points to; an unchanged chart keeps its part; edited data leaves that path.
  • write::xlsx unit tests: formula parsing (quoted sheet names, one row or one column only),
    cells replaced and inserted in order (including new rows and an empty sheetData), shared
    formulas and implicit positions refused, calcPr set or inserted at its schema position, table
    columns renamed.
  • tests/chart_workbook.rs, on a workbook built by the test (a Chart data sheet with a table, a
    total in F2, a formula in D5, a Notes sheet with a formula into the first one, shared strings,
    a calculation chain): title, legend and type changed keep the workbook byte for byte; one value
    changed rewrites only that cell and sets fullCalcOnLoad; a renamed series renames the table
    column; a value over a formula drops the formula and the calculation chain; added series or
    points and a clashing series name rebuild the workbook; a scatter chart updates in place; a chart
    made in DeckCraft gets a generated workbook, updated in place after a re-import.
  • tests/roundtrip.rs and tests/chart_embed.rs (Charts: keep the embedded workbook when a chart is saved unchanged (#335) #355): workbook bytes across round trips,
    unchanged charts still keep their parts under keptN names, the chartEx fallback has none.

Checked by hand earlier on the same logic (0.5.0, public decks above, not committed): changing the
title and legend keeps every workbook byte for byte; changing one value changes one cell of one
sheet, every other workbook entry (thumbnail included) staying identical; openpyxl and LibreOffice
read the updated workbooks.

Not verified: PowerPoint's Edit Data and Excel's recalculation on the updated workbooks. That needs
a black-box check on a machine with PowerPoint (AGENTS.md §2).

Known limits

  • The workbook lives in Chart.kept, which a .deckcraft save doesn't store (Charts: keep the embedded workbook when a chart is saved unchanged (#335) #355): a deck saved
    as .deckcraft and reopened has no kept workbook, so an export writes a generated one.
  • The fallback cases above still lose the original workbook's extra sheets, formulas and
    formatting, and an edited chart drops the other kept parts (styles, drawings), as with Charts: keep the embedded workbook when a chart is saved unchanged (#335) #355.
  • An edited chart part is rebuilt from the model: options the model doesn't hold are lost, as
    before. Only the workbook is kept.
  • A changed category is written as text, even over a number or date cell.
  • Structured references are found by their text ([Name], [@Name]); escaped names in formulas
    may be missed. dimension and row spans hints are not updated.

Related PRs

Main keeps an unchanged chart's embedded workbook (storytold#355), but a chart made
in DeckCraft, or one whose data or options changed, was written with no
workbook: no part under ppt/embeddings/, no package relationship, no
c:externalData. PowerPoint's Edit Data had nothing to open.

- Export: an unchanged chart still goes back with its kept parts; an
  edited or new chart gets a workbook generated from its data, laid out
  where the chart part's formulas point (Sheet1, categories in A, one
  column per series), with its c:externalData.
- Scatter series with different X values and multi-series bubble charts
  get their own columns instead of overlapping ranges.
- ChartKept::workbook finds the kept workbook part.
- The plain-chart fallback of an Office 2016 chart gets none: the
  workbook belongs to the chartEx part.
Every chart command clears the original chart part, so any edit (a new
title, another chart type, a legend) made the export drop the chart's
workbook for a generated one: extra sheets, formulas and formatting were
lost even when the data had not changed.

- Model: Chart.source, the series formulas of the imported chart part
  (name, categories or X values, values, bubble sizes) with the data as
  read. Commands keep it.
- Export: when the data still fits the original ranges, the chart part
  is written with its original formulas. Unchanged data keeps the kept
  workbook byte for byte; changed data rewrites only the changed cells
  in it. Every other zip entry is copied as is.
- Cells keep their style; a new name in a table header renames the
  table column; a value typed over a formula replaces it and drops the
  calculation chain; fullCalcOnLoad is set when the workbook holds
  formulas.
- Series or points added or removed, a category chart turned into a
  scatter chart (or back), literal data, shared or array formulas, a
  table column name that would clash or is used by a structured
  reference: the workbook is generated from the chart data, as before.
@pierrevbc pierrevbc changed the title PPTX export: keep chart workbooks, and update them in place when the data changes PPTX export: a workbook for edited and new charts, updated in place when the data changes Oct 15, 2026
anishguduru pushed a commit to anishguduru/deckcraft that referenced this pull request Oct 16, 2026
…om (storytold#241)

- The wheel turns pages in single-page view: one per notch, one per swipe.
- The rail's Page display menu offers Acrobat's view choices.
- Preferences: default page display and default zoom.
- Fit page and Fit height no longer jump across mixed page sizes.
@Harrison-Booth

Copy link
Copy Markdown
Contributor

An embedded workbook would let users edit chart data in PowerPoint, closing the high-priority chart interoperability gap. If you would rather not, I can open a PR that credits you, keeps your commits and shows a git range-diff against this one, so you'll still get credit and have visible work.

@FredApps FredApps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReviewerA — source-read COMMENT (not an approval)

I read the head of the diff: PPTX export writes a workbook for edited and new charts and updates it in place when the data changes. The chart model gains a field for where the data sits in the chart's workbook, and the data as read from there, kept through edits so that an export compares the chart data with it and either keeps the workbook or updates only the cells that changed. PowerPoint's "Edit Data" opens the embedded workbook, so a chart without one is not editable in PowerPoint; writing a correct embedded .xlsx is the real work. contributors/people.toml gains an entry whose display name differs from the account name and sets sync_github_name = false, a contributor choice. A round trip of a chart through PowerPoint (or at least through the importer) is the proof. I have not run it, and no exact-head CI result exists for this head. Nothing was run.

I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.

Status: waiting_author.

@aiongg aiongg added the bugfix Fixes something that is broken: wrong result, crash, data loss label Nov 4, 2026

@aiongg aiongg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated review (Opus). Not a maintainer decision.

Changes needed (not certain):

Edited and new charts now get a workbook in the exported PPTX. The imported workbook is kept as is or has only its changed cells rewritten while the data fits its original ranges, and otherwise a workbook is generated where the chart formulas point.

  • crates/pptx/src/write/mod.rs:223-245: the unchanged-chart path is the same as before. Edited charts take the original formulas when chart::source fits, and otherwise generated ones. The chartEx fallback gets no workbook (crates/pptx/src/write/shapes.rs:408).
  • crates/pptx/src/write/mod.rs:209-210: an edited chart stored as a chartEx part (the newer chart types) still loses its workbook on export, so this change covers plain c:chartSpace charts only.
  • crates/pptx/src/write/chart.rs:181: a changed category is always written as inline text. If the category range held numbers or dates, those cells change type.
  • crates/pptx/src/write/xlsx.rs:556: the in-place patcher refuses shared and array formulas, unparseable ranges and table headers it cannot rename, and then falls back to a generated workbook. That keeps failures safe, but the module is large to review.
  • The default branch has a test asserting that an edited chart exports without its kept workbook (crates/engine/tests/it/chart_native.rs:117-129). This change reverses that, so the test needs updating along with the rebase onto the restructured writer (crates/pptx/src/write.rs).
  • docs/gaps.md:182-183 still says editing a chart drops its workbook. It should be updated with this change.

Claims checked:

  • verified: Every chart command clears Chart.raw, so any edit made the chart export without a workbook before this change. (crates/engine/src/cmd/insert.rs:1711, 1759, 1796, 1800, 1803 and 1820 set c.raw = None. The old export only warned about the dropped workbook (crates/pptx/src/write/mod.rs:209, still used…
  • verified: An unchanged chart keeps the earlier path: its original part plus every kept part under fresh names. (crates/pptx/src/write/mod.rs:223-225 calls chart::kept_chart_xml and then chart::write_kept. crates/pptx/src/write/chart.rs:714-737 keeps the earlier raw-comparison logic.)
  • verified: An edited chart whose data still fits its original ranges is written with its original formulas, and its workbook is kept byte for byte when only the presentation changed. (crates/pptx/src/write/chart.rs:138-184 (source) returns the original refs and only data edits. crates/pptx/src/write/mod.rs:26…
  • verified: When the data changed, only the cells that changed are rewritten in the kept workbook, and its other sheets, formulas and formatting stay. (crates/pptx/src/write/xlsx.rs:556-620 (patch) patches only the edited sheets and copies other zip entries raw. It also sets fullCalcOnLoad, drops calcChain whe…
  • verified: Otherwise (new chart, series or points added or removed), the chart part and a generated workbook laid out where its formulas point are both written from the model. (crates/pptx/src/write/mod.rs:234-238 falls back to new_workbook (mod.rs:247). The formulas come from generated_refs (crates/pptx/src/…
  • verified: Charts made in DeckCraft now get a workbook. (crates/pptx/src/write/shapes.rs:408 passes workbook=true for every plain chart, and crates/pptx/src/write/mod.rs:247-250 writes workbook_xlsx when the chart has series. Charts with no series and chartEx charts get none.)

Recommendation: update the pull request; it will be reviewed again.

Reviewed at a01e062.

@cloutier

cloutier commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

I am refreshing this existing implementation against the current writer layout and checking the stale-workbook engine regression and gap documentation noted in review. Native Mac preservation evidence is recorded separately in #1983. PR #1629 overlaps supported fixed-range in-place workbook edits, so I am checking that coverage before making changes; new-chart/fallback workbook generation remains distinct. I will preserve the original commits and publish a reviewable handoff if branch permissions prevent a direct update.

@cloutier

cloutier commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Publishing correction: The fork-targeted helper linked below is closed. That publishing approach has been withdrawn; local commits and the reported validation are preserved. Any further contribution will stay on this official PR, without a duplicate implementation.

A ready review-correction helper is available at pierrevbc#1, targeting this existing chart-workbook branch. It retains all three original commits and merges current main for the writer restructure. The focused implementation comparison against main is linked in its description. Refreshed code also fixes reproduced numeric-category cell-type loss, title-only workbook loss with literal chart data, and unchanged old-native models missing the new source snapshot. All 14 workbook regressions and 2,467 native tests/doctests pass (six ignored); the separate official-toolchain wasm check passes all 23 relevant crates. Fresh Office acceptance is explicitly pending because the reference Mac session is locked; package linkage/data preflight passed and immutable fixtures remain ready for that follow-up. Existing native observations on a01e062 remain in #1983.

@cloutier

Copy link
Copy Markdown
Contributor

Reproduced a workbook-selection issue at exact head a01e062ac086fcf29fb03c93d279e88df9fc6382 (v0.7.0), at ChartKept::workbook, chart.rs:472 and original_workbook, write/mod.rs:256.

Original synthetic chart relationships, in order: rA -> BookA.xlsx, rB -> BookB.xlsx; c:externalData points to rB. A has B2/B3 = 111/112 and a distinct sentinel; B has 222/223, matching the chart cache.

  • On import the externalData link resolves B, but workbook() returns A. Two unchanged save/reopen cycles retain both workbook payloads byte-identically and still link B.
  • After a model title-only edit with raw cleared, export keeps A byte-for-byte, drops B and links A while the chart cache remains 222/223.
  • After changing the first model value to 999 and clearing raw, export patches A to 999/112 while the chart cache is 999/223. Both mismatches persist through another save/reopen.
  • Reordering the relationships to B,A with the same externalData=rB, selecting first A, and a single-B control all select coherently.

Please preserve the actual externalData relationship ID across raw-invalidating edits and resolve that target instead of taking the first package relationship.

Scope: model/PPTX/XLSX roundtrips, four original well-formed ZIP/XML fixtures, identical input bytes. Fresh main 2127bd1b (v0.18.1) preserves unchanged links/payloads and has the already-known edited-chart workbook loss; it has no selector API. No native PowerPoint/Excel, GUI/engine-command execution, full CI, current-main integration, OLE or external-link acceptance claimed. No implementation or duplicate PR proposed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes something that is broken: wrong result, crash, data loss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants