# Export to Excel in a Tableau Data App

How to build a native Export to Excel into a Tableau Data App: a real, styled `.xlsx` workbook made in the
browser from the data the app already holds, handed over in a way Tableau Cloud's sandbox allows. Read it
top to bottom before you start.

## What to build

An **Export to Excel** feature for this Data App. When the viewer asks for it, the app builds a real, styled `.xlsx`
workbook **in the browser**, from the data it already holds, and hands it over through a dialog. No library, no
server, no network request.

The workbook is designed, not dumped: an **About** tab first that explains the export, then one tab per table the
viewer needs, each with a dark frozen header row, filters, set column widths, real numbers and dates, and the same
sort the app shows.

## Why it has to work this way

A Data App runs inside Tableau's sandboxed frame, and that frame does not allow downloads. We tested this on Tableau
Cloud in Chrome and Safari (November 2026). Every route a page can start was blocked:

- `<a download>` with a `data:` or `blob:` URL, clicked: no file.
- `window.open` of a `data:` or `blob:` URL: a window opens, no file arrives.
- `window.open('', '_blank')` then writing into it: `SecurityError`.
- `showSaveFilePicker`: refused ("Sandboxed documents aren't allowed to show a file picker").
- Clipboard: `navigator.clipboard` is refused, and `execCommand('copy')` reports success but copies nothing.

**What works:** the viewer **right-clicks** a link to the file and chooses **Save link as** (Chrome, Edge) or
**Download Linked File As** (Safari). The browser starts that download, not the page, so the sandbox allows it.

So the design is: build the file, put it behind one big link in a dialog, and tell the viewer to right-click it.
Don't spend time looking for a one-click route on Tableau Cloud; we tried eight.

## Rules

- No libraries (no SheetJS, no JSZip) and no network loads of any kind. Write the file with plain JavaScript.
- Build from data the app has already queried. Don't add queries for the export unless a tab truly needs fields the
  app doesn't have.
- Keep **building** the workbook separate from **handing it over**: one function returns
  `{ bytes, filename, info }`, another shows the dialog. That keeps the builder testable.
- Hide every export button when `tableau.extensions.environment.isExporting` is true (an image export can't use it).
- Match the app's look: the dialog uses the app's own colours, fonts and light or dark theme.

## The experience

1. **The button.** A clear "Export to Excel" button where the viewer will look for it (the header, near the other
   controls). If the app has a detail view (a drawer or slide-over for one item), give it its own export button for
   that item's detail.
2. **The dialog.** On click, build the workbook and open a dialog over the app:
   - a title (for example "Superstore Explorer: dashboard export"),
   - a line with the size: "Excel workbook, 48 KB, made just now",
   - **one big link button** showing the filename, with the action underneath it:
     **"Right-click, then Save link as"** (in Safari: **"Right-click, then Download Linked File As"**),
   - a hint below it: "Tableau blocks downloads from inside the app, so right-click the button and choose Save link
     as.",
   - a short list of the tabs in the file, each with one line on what it holds.
3. **A plain click.** Leave the link clickable (in case Tableau lifts the block one day), but when it's clicked,
   change the hint to "Nothing downloaded? Right-click the button above and choose Save link as." and give the hint
   a brief flash so the viewer notices it.
4. **Safari's wording.** Detect Safari from the user agent (`/Safari\//` and none of
   `Chrome|Chromium|CriOS|FxiOS|Edg|OPR|Firefox`) and use "Download Linked File As" there.
5. **Outside Tableau.** If the same app also runs as a plain web page (for example a static copy framed on Tableau
   Public), a click does save there; word the button "Click to download" in that case. Inside Tableau Cloud, always
   use the right-click wording.
6. **Accessibility.** The dialog has `role="dialog"` and `aria-modal="true"`, a labelled title, a Close button that
   takes focus when it opens, Esc closes it, a click on the shade closes it, and focus returns to the button that
   opened it.
7. **Filename.** App name, scope and the data's end date, cleaned of `\ / : * ? " < > |`, for example
   `Superstore Explorer - last 12 months to 2026-12.xlsx` or `Superstore Explorer - Technology - orders.xlsx`.

## What goes in the workbook

**One workbook per job.** A dashboard export (summary tables, as the dashboard shows them) and an item export (the
detail rows behind one item) are separate files, each with its own About tab.

**Tab 1 is always "About"**, gridlines off, column widths about 28, 70, 16, 16, laid out top to bottom:

1. The report title (large, bold) and a one-line subtitle (muted).
2. A blank row, then section **"About this export"** as label and value pairs: exported from (app name and which
   view), exported at (the viewer's clock, `yyyy-mm-dd hh:mm`), the data source, and the period the data runs
   through.
3. Section **"Filters applied"**: every filter, parameter and setting the viewer had chosen, in words, including
   ones that only changed what the dashboard showed, saying how the export treats each.
4. Section **"At a glance"** (dashboard export) or **"Summary"** (item export): the headline figures.
5. Section **"What is on each tab"**: a small table, Tab and What it holds, one row per data tab.
6. Section **"How to use it"**: short bullets in column B written as `•  text` (not a bullet in column A): the header
   row has filters and stays in view; units and time zones; "this is a snapshot of what you had filtered; export
   again after changing filters"; how to get the other export.

Section headings are bold, slightly larger, with a thin bottom border across four columns. Labels are bold; long
values wrap.

**Data tabs:**

- Row 1 is the header: white bold text on a dark fill (`#1E293B`), wrapped, about 22 to 30 points tall.
- Freeze row 1 and put an auto filter on the whole table.
- Set every column's width so nothing is cut off; landscape; print one page wide.
- **Real values:** numbers as numbers (so they sum and sort), dates as Excel dates with a date format, percentages
  as fractions with a percent format, currency with a currency format. Never write formatted text like "$1.2K".
- Units in the header where they help ("Sales ($)", "Profit ratio").
- Full text, not what fitted on screen: full product names, full error messages, email addresses.
- The same ranking or sort the dashboard showed; a Rank column when the order matters.
- Colour that carries meaning can travel: red for negative profit (through the number format), red bold for a
  "Failing" status, green for "Succeeded".

## Example: Superstore Explorer

The app queries order lines once (order month, order ID, category, sub-category, product, customer, region,
state/province, segment, sales, profit, quantity) and computes everything else in the browser, filtered by the
**Period**, **Category** and **Region** controls, with a selected **metric** (Sales, Profit, Profit ratio, Orders,
Units). Build two exports from that.

**1. Dashboard export** ("Export to Excel" in the header). File:
`Superstore Explorer - <period> to <last month yyyy-mm>.xlsx`.

| Tab | Rows | Columns |
| --- | --- | --- |
| About | as above | Filters applied: Period (with first and last month), Category, Region, and which metric ranks the tabs. At a glance: the five KPIs for the scope, and the change against the prior period when the period isn't All |
| Monthly trend | one per month in the scope, oldest first | Month (a real date, first of the month, format `mmm yyyy`), Sales, Profit, Profit ratio, Orders, Units sold |
| Sub-categories | every sub-category in the scope, ranked by the selected metric | Rank, Category, Sub-Category, Sales, Profit, Profit ratio, Orders, Units sold |
| Top products | top 100 products by the selected metric | Rank, Product, Category, Sub-Category, Sales, Profit, Profit ratio, Orders, Units sold |

**2. Item export** ("Export orders to Excel" in the detail drawer for a category, region, product, customer and so
on). File: `Superstore Explorer - <item> - orders.xlsx`.

| Tab | Rows | Columns |
| --- | --- | --- |
| About | as above | Filters applied: the item and what it is (for example "Technology, a category"), the period, and the dashboard's Category and Region filters. Summary: Sales, Profit, Profit ratio, Orders, Units, Average order |
| Order lines | the order lines behind the item in the scope, biggest sales first | Order ID, Order month, Customer, Segment, Region, State/Province, Category, Sub-Category, Product, Sales, Profit, Quantity |

Orders counts distinct order IDs. Profit ratio is total profit divided by total sales, never an average of row ratios.
Order month is all the app has (it queries the date truncated to the month), so name the column "Order month", not
"Order date".

**Size limit.** The file travels as a `data:` URL, about 1.35 times the file's size, and Chrome caps URLs at about
2 MB. We have never sent a file near that size, so treat the limit as real and stay well under it. A whole category or region can hold several thousand order lines, which would pass that. So cap the
Order lines tab at **1,000 lines** (biggest sales first), and when the cap applies say so twice: in the About tab
("Showing the 1,000 largest of 3,742 order lines") and in the dialog. As a second guard, if the `data:` URL is still
longer than 1,900,000 characters, show a message in the dialog instead of the link.

## Writing the .xlsx

An `.xlsx` file is a zip archive of XML files ("parts"). Write the parts as strings, encode them as UTF-8, and store
them in a zip **without compression**. Every name and attribute below is exact; Excel is strict about them.

**Parts, in this order:**

| Zip path | Holds |
| --- | --- |
| `[Content_Types].xml` | the content type of every part |
| `_rels/.rels` | points at the workbook and the document properties |
| `docProps/core.xml` | title, creator, created time |
| `docProps/app.xml` | the application name |
| `xl/workbook.xml` | the list of sheets, and the filter ranges |
| `xl/_rels/workbook.xml.rels` | points at each sheet and at the styles |
| `xl/styles.xml` | fonts, fills, borders, number formats and the cell styles |
| `xl/worksheets/sheet1.xml` … `sheetN.xml` | one per tab, About first |

Every part starts with `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>`.

**`[Content_Types].xml`** (one `Override` per sheet):

```xml
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
  <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
  <Default Extension="xml" ContentType="application/xml"/>
  <Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>
  <Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>
  <Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>
  <Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
  <Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
</Types>
```

**`_rels/.rels`:**

```xml
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
  <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
  <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
</Relationships>
```

**`docProps/core.xml`** and **`docProps/app.xml`** (created time in UTC, ISO 8601 without milliseconds):

```xml
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
  xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <dc:title>Superstore Explorer export</dc:title><dc:creator>Superstore Explorer</dc:creator>
  <dcterms:created xsi:type="dcterms:W3CDTF">2026-11-26T09:30:00Z</dcterms:created>
</cp:coreProperties>
```

```xml
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
  <Application>Superstore Explorer</Application>
</Properties>
```

**`xl/workbook.xml`** (sheet `n` has `sheetId="n"` and `r:id="rIdn"`; one `definedName` per sheet that has a filter,
with `localSheetId` counting from 0, the sheet name in single quotes with any `'` doubled, and absolute references):

```xml
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
  xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
  <bookViews><workbookView activeTab="0"/></bookViews>
  <sheets>
    <sheet name="About" sheetId="1" r:id="rId1"/>
    <sheet name="Monthly trend" sheetId="2" r:id="rId2"/>
  </sheets>
  <definedNames>
    <definedName name="_xlnm._FilterDatabase" localSheetId="1" hidden="1">'Monthly trend'!$A$1:$F$49</definedName>
  </definedNames>
</workbook>
```

**`xl/_rels/workbook.xml.rels`** (sheets are `rId1` to `rIdN`, styles is `rId(N+1)`):

```xml
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>
  <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet2.xml"/>
  <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
</Relationships>
```

**`xl/styles.xml`.** A cell picks a style with `s="n"`, where `n` is the position of an `<xf>` inside `cellXfs`,
counting from 0. Use this table and keep the indexes in step with the XML:

| `s` | Style | Use |
| --- | --- | --- |
| 0 | plain | default |
| 1 | head | header row: white bold on `#1E293B`, wrapped, vertically centred |
| 2 | title | About title: bold 20 pt |
| 3 | muted | About subtitle: grey `#64748B` |
| 4 | label | About labels: bold, top-aligned |
| 5 | section | About section headings: bold 13 pt, thin bottom border `#E2E8F0` |
| 6 | wrap | long text, wrapped, top-aligned |
| 7 | mutedWrap | grey wrapped text |
| 8 | int | whole numbers `#,##0` |
| 9 | intLeft | whole numbers, left-aligned (About values) |
| 10 | money | `$#,##0.00`, negatives red |
| 11 | pct | `0.0%`, negatives red |
| 12 | date | `yyyy-mm-dd` |
| 13 | month | `mmm yyyy` |
| 14 | good | bold green `#047857` |
| 15 | bad | bold red `#B91C1C` |

```xml
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  <numFmts count="4">
    <numFmt numFmtId="164" formatCode="yyyy-mm-dd"/>
    <numFmt numFmtId="165" formatCode="mmm yyyy"/>
    <numFmt numFmtId="166" formatCode="0.0%;[Red]-0.0%"/>
    <numFmt numFmtId="167" formatCode="$#,##0.00;[Red]-$#,##0.00"/>
  </numFmts>
  <fonts count="8">
    <font><sz val="11"/><color rgb="FF0F172A"/><name val="Calibri"/><family val="2"/></font>
    <font><b/><sz val="11"/><color rgb="FFF1F5F9"/><name val="Calibri"/><family val="2"/></font>
    <font><b/><sz val="20"/><color rgb="FF0F172A"/><name val="Calibri"/><family val="2"/></font>
    <font><sz val="11"/><color rgb="FF64748B"/><name val="Calibri"/><family val="2"/></font>
    <font><b/><sz val="11"/><color rgb="FF0F172A"/><name val="Calibri"/><family val="2"/></font>
    <font><b/><sz val="13"/><color rgb="FF1E293B"/><name val="Calibri"/><family val="2"/></font>
    <font><b/><sz val="11"/><color rgb="FF047857"/><name val="Calibri"/><family val="2"/></font>
    <font><b/><sz val="11"/><color rgb="FFB91C1C"/><name val="Calibri"/><family val="2"/></font>
  </fonts>
  <fills count="3">
    <fill><patternFill patternType="none"/></fill>
    <fill><patternFill patternType="gray125"/></fill>
    <fill><patternFill patternType="solid"><fgColor rgb="FF1E293B"/><bgColor indexed="64"/></patternFill></fill>
  </fills>
  <borders count="2">
    <border><left/><right/><top/><bottom/><diagonal/></border>
    <border><left/><right/><top/><bottom style="thin"><color rgb="FFE2E8F0"/></bottom><diagonal/></border>
  </borders>
  <cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs>
  <cellXfs count="16">
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>
    <xf numFmtId="0" fontId="1" fillId="2" borderId="0" xfId="0" applyFont="1" applyFill="1" applyAlignment="1"><alignment vertical="center" wrapText="1"/></xf>
    <xf numFmtId="0" fontId="2" fillId="0" borderId="0" xfId="0" applyFont="1"/>
    <xf numFmtId="0" fontId="3" fillId="0" borderId="0" xfId="0" applyFont="1"/>
    <xf numFmtId="0" fontId="4" fillId="0" borderId="0" xfId="0" applyFont="1" applyAlignment="1"><alignment vertical="top"/></xf>
    <xf numFmtId="0" fontId="5" fillId="0" borderId="1" xfId="0" applyFont="1" applyBorder="1"/>
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" applyAlignment="1"><alignment vertical="top" wrapText="1"/></xf>
    <xf numFmtId="0" fontId="3" fillId="0" borderId="0" xfId="0" applyFont="1" applyAlignment="1"><alignment vertical="top" wrapText="1"/></xf>
    <xf numFmtId="3" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
    <xf numFmtId="3" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1" applyAlignment="1"><alignment horizontal="left" vertical="top"/></xf>
    <xf numFmtId="167" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
    <xf numFmtId="166" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
    <xf numFmtId="164" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
    <xf numFmtId="165" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
    <xf numFmtId="0" fontId="6" fillId="0" borderId="0" xfId="0" applyFont="1"/>
    <xf numFmtId="0" fontId="7" fillId="0" borderId="0" xfId="0" applyFont="1"/>
  </cellXfs>
  <cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles>
</styleSheet>
```

**A worksheet** (`xl/worksheets/sheetN.xml`). The elements must appear in this order:

```xml
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
  xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
  <sheetPr><pageSetUpPr fitToPage="1"/></sheetPr>
  <sheetViews>
    <sheetView workbookViewId="0" tabSelected="1">
      <pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen"/>
      <selection pane="bottomLeft"/>
    </sheetView>
  </sheetViews>
  <sheetFormatPr defaultRowHeight="15"/>
  <cols>
    <col min="1" max="1" width="12" customWidth="1"/>
    <col min="2" max="2" width="14" customWidth="1"/>
  </cols>
  <sheetData>
    <row r="1" ht="22" customHeight="1">
      <c r="A1" s="1" t="inlineStr"><is><t xml:space="preserve">Month</t></is></c>
      <c r="B1" s="1" t="inlineStr"><is><t xml:space="preserve">Sales ($)</t></is></c>
    </row>
    <row r="2">
      <c r="A2" s="13"><v>44927</v></c>
      <c r="B2" s="10"><v>14236.895</v></c>
    </row>
  </sheetData>
  <autoFilter ref="A1:B49"/>
  <mergeCells count="1"><mergeCell ref="B3:D3"/></mergeCells>
  <pageMargins left="0.5" right="0.5" top="0.6" bottom="0.6" header="0.3" footer="0.3"/>
  <pageSetup orientation="landscape" fitToWidth="1" fitToHeight="0"/>
</worksheet>
```

- `tabSelected="1"` on the first sheet only. On the About sheet, drop the `pane` and `selection`, and add
  `showGridLines="0"` to `sheetView`.
- Leave out `cols`, `autoFilter` and `mergeCells` when a sheet has none. `autoFilter` covers the header row to the
  last row and last column, and must match that sheet's `_xlnm._FilterDatabase` defined name.
- Cell references are column letters plus row number (A, B … Z, AA, AB …), rows counting from 1.
- **Text:** `t="inlineStr"` with `<is><t xml:space="preserve">…</t></is>`. No shared strings table is needed.
- **Numbers:** no `t` attribute, the value in `<v>`. Only finite numbers; write an empty cell for null, NaN or
  Infinity.
- **Empty cells:** leave them out, unless they carry a style (for example the section border), then
  `<c r="C5" s="5"/>`.
- **Escape all text and names:** `&` → `&amp;`, `<` → `&lt;`, `>` → `&gt;`, `"` → `&quot;`, and remove characters
  U+0000 to U+0008, U+000B, U+000C and U+000E to U+001F, which XML forbids (they turn up in real data and make Excel
  call the file corrupt).

**Dates.** An Excel date is a number: days since 1899-12-30. For a date at midnight UTC,
`serial = Date.UTC(year, monthIndex, day) / 86400000 + 25569`. A month is the serial of its first day with the
`month` style. Work in UTC so the viewer's time zone can't shift a date by a day.

**Sheet names.** At most 31 characters, none of `[ ] : * ? / \`, not empty, and unique ignoring case (add " 2",
" 3" to repeats).

**The zip.** Store each part uncompressed. All numbers are little-endian. For each part, in order, write a local file
header, then the part's file name bytes (UTF-8), then its data bytes:

| Offset | Bytes | Local file header field | Value |
| --- | --- | --- | --- |
| 0 | 4 | signature | `0x04034b50` |
| 4 | 2 | version needed | 20 |
| 6 | 2 | flags | `0x0800` (names are UTF-8) |
| 8 | 2 | compression | 0 (stored) |
| 10 | 2 | modified time | DOS time: `hours << 11 \| minutes << 5 \| seconds >> 1` |
| 12 | 2 | modified date | DOS date: `(year - 1980) << 9 \| month << 5 \| day` |
| 14 | 4 | CRC-32 of the data | see below |
| 18 | 4 | compressed size | data length |
| 22 | 4 | uncompressed size | data length |
| 26 | 2 | file name length | |
| 28 | 2 | extra field length | 0 |

Then a central directory: for each part, a 46-byte record followed by its file name bytes:

| Offset | Bytes | Central directory field | Value |
| --- | --- | --- | --- |
| 0 | 4 | signature | `0x02014b50` |
| 4 | 2 | version made by | 20 |
| 6 | 2 | version needed | 20 |
| 8 | 2 | flags | `0x0800` |
| 10 | 2 | compression | 0 |
| 12 | 2 | modified time | as above |
| 14 | 2 | modified date | as above |
| 16 | 4 | CRC-32 | as above |
| 20 | 4 | compressed size | data length |
| 24 | 4 | uncompressed size | data length |
| 28 | 2 | file name length | |
| 30 | 2 | extra field length | 0 |
| 32 | 2 | comment length | 0 |
| 34 | 2 | disk number | 0 |
| 36 | 2 | internal attributes | 0 |
| 38 | 4 | external attributes | 0 |
| 42 | 4 | offset of the local header | where this part's local header starts |

Then the 22-byte end record: signature `0x06054b50` (4 bytes), disk 0 (2), disk with the directory 0 (2), entries on
this disk (2), total entries (2), central directory size in bytes (4), central directory offset (4), comment length 0
(2).

**CRC-32** is the standard zip checksum (reflected polynomial `0xEDB88320`), over the uncompressed data. Build the
256-entry table once; for each byte, `c = table[(c ^ byte) & 0xFF] ^ (c >>> 8)`, starting from `0xFFFFFFFF`, and
finish with `(c ^ 0xFFFFFFFF) >>> 0`.

**Handing it over.** Base64 the bytes (in chunks of 32,768 bytes through `String.fromCharCode.apply`, then
`btoa`, since one huge call can overflow the stack), and make the link:

```html
<a href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,…"
   download="Superstore Explorer - last 12 months to 2026-12.xlsx">…</a>
```

## Pitfalls we hit

- A click on that link inside Tableau Cloud does nothing. That's expected; the right-click is the design.
- In a local preview, a `.click()` from a script is not a real user gesture, so download behaviour there proves
  nothing. Only a real right-click on Tableau Cloud does.
- Text written as numbers ("$1.2K", "12.6%") can't be summed or sorted. Always write the raw number and let the
  style format it.
- A sheet name with `'` in it must be doubled inside the defined name: `'O''Brien orders'!$A$1:$L$20`.
- The filter range must end at the last data row and last column, in both `autoFilter` and the defined name.
- Tableau's build check may warn that the code mentions `http://schemas.openxmlformats.org` and `http://purl.org`.
  Those are XML namespace names, never fetched; the warning is harmless.

## How to test it

1. Publish to Tableau Cloud (the site allows packages; the viewer has API Access on the workbook).
2. Click **Export to Excel**: the dialog opens with the size, the big link and the list of tabs.
3. Left-click the link: nothing saves, and the hint changes and flashes.
4. Right-click, **Save link as** (Chrome) and **Download Linked File As** (Safari): an `.xlsx` with the right name
   saves.
5. Open it in Excel: no repair prompt. About is first with no gridlines; each data tab has a dark frozen header,
   filters, widths that fit, real numbers that sum, months that sort as dates, negative profit in red.
6. Change Period, Category and Region, export again: the About tab and every tab follow the new filters.
7. Open an item's detail and export its orders: a separate file; a big category shows the 1,000-line cap in the
   About tab and in the dialog.
8. Export the dashboard as an image or PDF: no export button appears in it.
