Open this example in the interactive library
Source code
// app/billing/page.tsx
export default function InvoiceCSVDownload() {
const invoices = [
{ id: "A", cents: 3200, paid: true, due: "2028-01-10" },
{ id: "B", cents: 7900, paid: false, due: "2028-02-15" },
{ id: "C", cents: 4600, paid: false, due: "2028-03-20" },
];
const csv = [
"id,amount,due",
...invoices.map((i) => [i.id, (i.cents / 100).toFixed(2), i.due].join(",")),
].join("\n");
return (
<a download="invoices.csv" href={"data:text/csv," + encodeURIComponent(csv)}>
Export billing report
</a>
);
}
