Skip to content

File formats: CSV/TSV export writes displayed values; templates and .xlsm saved with their own content types - #422

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
neilcawse:fix/csv-display
Oct 11, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
neilcawse:fix/csv-display

Conversation

@neilcawse

Copy link
Copy Markdown
Contributor

What changed

  • Save As CSV/TSV now writes each cell as it is displayed: number formats applied (dates, currency, percent, fractions, thousands separators, @ text), formula results, errors and booleans as shown. It never writes column-width ##### and never applies the grid's General narrowing, so the field holds the whole value. This follows Microsoft's description of Save As CSV/Text ("the text and values as they are displayed in cells", all characters kept). Before this change the export wrote raw values (46023 instead of 2026-01-01).
    • engine::display::value_text is split out of cell_text: it formats the value without the show-formulas branch. A sheet with Show Formulas on still exports values.
    • gridcraft_xlsx::write_csv(sheet, delimiter, cell_text) takes a closure that supplies each field's text. Quoting, CRLF line ends and UTF-8 without BOM stay in the xlsx crate, and formatting stays in the engine (layering). The old raw field_text helper is removed.
  • .xltx, .xltm and .xlsm are saved with their own xl/workbook.xml content type (template, macro-enabled template, macro-enabled workbook). Before, every one of them got the .xlsx workbook type, which Excel rejects for a template. The new XlsxKind::from_path picks the kind from the extension (case-insensitive; unknown or missing extensions give .xlsx). write_xlsx_as(wb, kind) writes it.
  • The VBA project kept by VBA Macros support #6 now follows the kind: the writer adds xl/vbaProject.bin only for .xlsm and .xltm (XlsxKind::is_macro_enabled), so save_bytes no longer clones the workbook to strip it, and a macro-enabled template keeps its macros. write_xlsx(wb) behaves as before: .xlsm when the workbook holds a VBA project, .xlsx otherwise. The CT_WORKBOOK_MAIN/CT_WORKBOOK_MAIN_MACRO constants are replaced by XlsxKind::main_content_type.

Tests

  • engine io::tests::csv_writes_displayed_text: date, currency, percent, fraction, text-format 007, #N/A, TRUE, formula result, a too-narrow column (no #####), General negative, thousands. Show Formulas is on. Checks the exact CSV bytes, including quoting of "$1,234.50", and the TSV prefix.
  • engine io::tests::template_extension_saves_template_content_type: save_bytes(.., "Budget.xltx") writes the template content type.
  • engine io::tests::macros_are_saved_only_into_xlsm also checks that .xltm keeps the VBA project and .xltx drops it.
  • xlsx tests::roundtrip::package_kind_sets_workbook_content_type: for each of the four kinds, from_path maps the extension (including upper case and a dotted directory), the [Content_Types].xml override for /xl/workbook.xml is correct, and the file reads back with no warnings.
  • xlsx tests::csv_tests::writing is updated for the new write_csv signature (raw-value closure), with the same expected output.

Commands run:

cargo fmt --all -- --check
cargo clippy -p gridcraft-xlsx -p gridcraft-engine --all-targets -- -D warnings
cargo test -p gridcraft-xlsx -p gridcraft-engine
cargo xtask parity --check

All pass.

Docs

  • docs/file-format-parity.md: header Change line, the .xlsm and .xltx/.xltm rows (content type fixed, tests named; the .xlsm row also stops saying macros are dropped, which has been wrong since VBA Macros support #6 landed), the .csv and .txt rows ("displayed values"), the Work table (CSV/text row drops "displayed-value export", 5–8 h → 4–7 h), and a new history row.
  • The header and history rows in this file will conflict with other open file-format PRs, so a rebase will be needed. docs/parity-checklist.md is unchanged (cargo xtask parity --check reports it up to date).

Not done

Unverified: needs confirmation in Excel

  • That Excel opens the saved .xltx/.xltm/.xlsm packages without a repair prompt. Only our reader and the content-type strings from ECMA-376 were checked.
  • Exact displayed text for less common formats in CSV, such as locale-dependent date or currency formats and [h]:mm. These use the same formatter as the grid, which has not been compared against Excel's CSV output.

…xlsm saved with their own content types

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@echelon

echelon commented Oct 11, 2026

Copy link
Copy Markdown
Member

Merged — thank you for the contribution! If you haven't already, please join our Discord: https://discord.gg/artcraft

neilcawse added a commit to neilcawse/gridcraft that referenced this pull request Oct 12, 2026
…/footer labels

CSV/TSV export ran General numbers through the 11-character cell display, so a
barcode like 124412140710 was saved as 1.24412E+11. display::value_text now
writes a General number as & converts it (number_to_text), as its doc already
said; cell_text keeps the cell display. Fixes the two storytold#426 tests that broke when
storytold#422 merged.

Adds the French "Different First Page" / "Different Odd & Even Pages" labels
missing after storytold#413, which failed the i18n completeness test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@neilcawse
neilcawse deleted the fix/csv-display branch November 14, 2026 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants