@zenuinebit/report-export
v0.1.0
Published
CSV and XLSX export for tables and GST reports. No dependencies, runs in Node and the browser.
Readme
@zenuinebit/report-export
CSV and Excel (.xlsx) export for tables and for @zenuinebit/gst-report reports. No runtime dependencies besides the report types; works in Node and the browser (you get a string or a Uint8Array and decide how to save it).
import { table, toCSV, toXLSX, gstReportTables, XLSX_MIME } from "@zenuinebit/report-export";
const sales = table("Sales", rows, [
{ header: "Invoice", value: "number" },
{ header: "Date", value: "date", type: "date" }, // "YYYY-MM-DD"
{ header: "Qty", value: "qty", type: "number" },
{ header: "Amount", value: "amount", type: "money" }, // integer minor units
]);
toCSV(sales, { bom: true }); // string; the BOM makes Excel read UTF-8 correctly
const bytes = toXLSX([sales, anotherTable]); // Uint8Array, one sheet per table
// Browser download
const url = URL.createObjectURL(new Blob([bytes], { type: XLSX_MIME }));
// Node
await fs.writeFile("sales.xlsx", bytes);
// A whole GST report: Summary, B2B, B2CL, B2CS, By rate, HSN, Invoices
await fs.writeFile("gst-april.xlsx", toXLSX(gstReportTables(report)));Column types: text (default), number, money (integer minor units, written as 1234.56), date (YYYY-MM-DD).
Good to know
- Money stays a number in Excel.
moneycells are real numeric cells with a#,##0.00format, so sums and filters work. In CSV they are plain decimals. UsecurrencyDigitsfor currencies without 2 decimals. - Spreadsheet formula safety. In CSV, text starting with
=,+,-or@gets a leading'so Excel cannot run it as a formula (turn off withformulaGuard: false). Numbers are never altered. In XLSX all text is stored as plain strings. - CSV follows RFC 4180: fields with commas, quotes or line breaks are quoted, lines end with CRLF.
delimiter: ";"is available for locales that need it. - XLSX sheets have a bold, frozen header row and sized columns. Sheet names are made valid (31 characters, no
[]:*?/\) and unique. - The .xlsx is written without compression (store only), which every spreadsheet program reads. It has been opened with openpyxl and checked with
unzip -t.
Not included: styling beyond the header, formulas, multiple header rows, merged cells, charts, and reading files.
