Repository navigation
feat(core): make table Excel exports look like the table (ExcelJS → hucre) - #3358
nickfanion wants to merge 5 commits into
Conversation
…hucre) Table downloads now produce a sheet laid out like the rendered table while staying a working spreadsheet: multi-level headers (Center Across Selection with a Single Accounting underline), totals and subtotals, row lines and shading, Excel 2010 data bars, static color-scale fills, colored deltas, red negatives, links, native sparklines, frozen columns and header, collapsible groups as outline groups, Calibri 11, and autofit columns. Numbers and dates stay native with the report's number formats. The page-level Download Data and Generate Excel Report exports use the same styled sheets for tables; other components get a plain styled data sheet. ExcelJS is replaced by hucre (zero dependencies, ~48 KB gzipped, loaded on first export), patched to write Excel 2010 data-bar options and two sparkline options. Exports are about twice as fast for 20k+ row tables. Display rules the table template used inline are now shared helpers used by both the template and the export. Download filenames are made valid on every OS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S5uhmnLon3oEE2M1VKKZ4L
One table per group of table options that change how a table looks, for checking table Excel exports by hand against the rendered page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S5uhmnLon3oEE2M1VKKZ4L
Excel for Windows re-measures a row that has content but no height of its own, ignoring the sheet's default row height, so a long table's rows shrank from 18pt to the font's natural height partway down. Header and body rows now carry an explicit height, as wrapped rows already did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S5uhmnLon3oEE2M1VKKZ4L
|
@nickfanion is attempting to deploy a commit to the Evidence Team on Vercel. A member of the Team first needs to authorize it. |
Drops an unused type import from the table export and moves the `downloadBlob` doc comment, which had ended up above `sanitizeFilename`, back onto its function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Header titles only wrapped past 200px, so a wide table with short data under longer titles (a pivot over 40 retailer names, say) exported every title on one line, with columns two to three times their width on the page. Columns are now laid out the way the browser lays out the report's table. Each one ranges from its data or its title's longest word to its data or its whole title on one line. A table that fits in about the width a default page gives it keeps its titles on one line, as before; a wider one narrows its columns toward their data and wraps the titles, and the header row grows to the tallest title. Bottom-row titles are bottom-aligned, so shorter titles sit on the rule as they do on screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Update: exported headers now wrap the way the page wraps them I tested the export on a second real report: a distribution grid pivoted over 40 retailer and market names. Its headers didn't wrap. Titles under 200px always stayed on one line, so each column widened to fit its name, and the geography columns came out about 4,600px wide against about 2,600px on the page. fea07c3 lays the columns out the way the browser lays out the report's table. A table that fits on a default-width page keeps its titles on one line, as before. A wider one narrows its columns toward their data and wraps the titles. Bottom-row titles are now bottom-aligned too, so shorter titles sit on the rule as they do on screen.
a4808a1 also removes an unused import and moves a doc comment back onto its function. |
|
/upstream |
|
Imported for internal review, this PR will be updated when it merges. |
|
Thanks for the contribution, @nickfanion! Merged upstream, and synced back in 5e44dad |










Downloading a table to Excel now gives a sheet that looks like the table on the page, so nobody has to reformat it, fit columns, or rebuild totals by hand, and it still behaves like a real spreadsheet: numbers and dates stay native values, nothing is merged, and formats are Excel number formats rather than text.
It also replaces ExcelJS with hucre.
What a table export looks like now
wrap_titlesandformat_titlesare honoredrow_lines,row_shadingrepeat_values(table or dimension) repeats themcollapsible/collapsedviz="bar"scale_mode="shared"across pivot columns), red negative bars from a zero axis, plusbar_color,bar_color_negative,fit_to_data,hide_labels, andviz_include_subtotalsviz="color",color_scale,color_stops,midpoint,conditional_colors,row_conditional_colorsviz="delta"down_is_good,neutral_range). Negative values keep their minus signred_negativesviz="sparkline"fmt,fmt_column, comparisonpct_fmt/abs_fmt, auto formats (usd,num,pct)$1.2M). Zero drops the unit, as on screen. Dates are real Excel datesfreeze_columnsalign,wraplinkhtmlhide, rowlinkcolumnAcross the workbook:
The page-level Excel exports use the same sheets. Both Download Data and Generate Excel Report now write each table the way it renders (pivoted, with totals and formatting) instead of its unpivoted query results. Other components (charts etc.) get a plain data sheet with the same base styling. The single-component downloads for charts and the
downloadcomponent get that base styling too.Deliberate differences from the screen
Some on-screen behavior has no faithful Excel equivalent, or copying it would make the file worse to work with:
color_stops,midpoint, scale columns, per-row conditional colors, background-anchored single colors) don't map onto Excel's 2- and 3-color scales. Static fills match the screen exactly.neutral_range, and Excel's icon sets can't recolor fordown_is_good. Negative values show a minus sign.page_width: fullpage in a wide window, a medium-width table can wrap titles in Excel that fit on one line on screen.infoand comparison tooltips) and the row-link chevron column are left out. Tooltips aren't formatting, so they're outside this change, and the chevron column has no Excel equivalent.Why hucre instead of ExcelJS
archiver,jszip,unzipper,tmp,saxes, andfast-csv. Two of them already needed security overrides in the rootpackage.json(unzipper,uuid);unzipperwas only there for ExcelJS.import()on the first export.In fairness, ExcelJS already writes Excel 2010 data bars (solid fill, negative bars); hucre 1.3.0 only writes the 2007 kind (gradient, 10–90% length, no zero axis). This PR closes that gap with a small patch (below), which I plan to upstream.
Performance
Exporting is about twice as fast as before for tables of 20,000 rows or more.
How this was measured:
main's export pipeline:buildTableExcelExportColumns,getCellStyle,addDataToWorksheet, thenwriteBuffer. "After" isbuildTableExcelSheetpluswriteWorkbook.Where the time goes:
To keep the build fast:
The first export also downloads hucre's writer once: about 48 KB gzipped, previously part of the page bundle.
How formatting is applied
An .xlsx file has no range-level formatting. Each distinct combination of font, fill, border, alignment and number format is stored once in the workbook's style table, and each cell points at one entry. That is also how Excel saves a range you format by hand.
The QA tables use 8–22 distinct formats each; a 200,000-cell table with a color scale uses about 460, almost all of them its gradient's colors. Formatting is applied at the broadest level Excel allows without spilling past the table:
Borders and fills can't move up to columns or rows. A column's default format applies to every row of the sheet, and a row's to every column, so a border or fill set there would run past the table's edges.
Why Calibri
ExcelFont), so the export font can be made configurable later without touching the layout code.The hucre patch (
patches/hucre@1.3.0.patch)The patch is applied through pnpm
patchedDependencies, like the existing ssf/echarts/zrender patches, and is listed inpatches/THIRD-PARTY-NOTICES.md. It touches only the worksheet writer and its types, with every change marked[MODIFIED]:gradient,minLength/maxLength,border,negativeFillColor,axisPosition,axisColor,direction) plusshowValue. Setting any of them writes the rule'sx14extension, the same structure Excel writes. Readers that don't understand it fall back to the 2007 bar.displayHidden(plot data in hidden columns) andmanualMin(pin the axis minimum, so sparklines include zero like the report's).Other changes
DeltaDisplayuses too.formatValue's format-code resolution (auto units, zero handling) is extracted asresolveFormatCode, so Excel number formats follow the same rules.resolveTableColorsis exported from the theme CSS helper, so the export reads the same table colors the CSS variables get.ExcelFont(name, size, line height, glyph metrics). Each export picks its font once (getExcelExportFont()) and passes it to every sheet builder and to the writer, so widths are always measured in the font the workbook declares. Supporting another font later means adding its metrics.features/page-settings.mdxnow describes what table sheets contain.Testing
waterfall_chart.test.ts's date-range snapshot, fails onmaintoo: it depends on the machine's timezone and passes withTZ=UTC.cli/test-environment/pages/excel-export.md, one table per feature group), then checked three ways:svelte-checkfor core passes with no errors, and the changed files are prettier-clean. The CLI check's only error is the generated docs bundle, which needs a bun build.Not verified:
Follow-ups
unzipperoverride no longer applies to anything and could be removed.🤖 Generated with Claude Code
https://claude.ai/code/session_01S5uhmnLon3oEE2M1VKKZ4L