XLSX

Quick Start

Create your first .xlsx spreadsheet in 5 minutes with @office-open/xlsx

Create a spreadsheet from scratch in three steps: define data, build a workbook, and export.

Step 1 — Install

pnpm add @office-open/xlsx

Step 2 — Create a Workbook

import { generateWorkbook } from "@office-open/xlsx";

const opts = {
  worksheets: [
    {
      name: "Sales",
      rows: [
        {
          cells: [
            { value: "Product", style: { font: { bold: true } } },
            { value: "Q1", style: { font: { bold: true } } },
            { value: "Q2", style: { font: { bold: true } } },
          ],
        },
        { cells: [{ value: "Widget" }, { value: 100 }, { value: 150 }] },
        { cells: [{ value: "Gadget" }, { value: 200 }, { value: 250 }] },
      ],
    },
  ],
};

Or use the JSON API:

{
  "worksheets": [
    {
      "name": "Sales",
      "rows": [
        { "cells": [{ "value": "Product" }, { "value": "Q1" }, { "value": "Q2" }] },
        { "cells": [{ "value": "Widget" }, { "value": 100 }, { "value": 150 }] },
        { "cells": [{ "value": "Gadget" }, { "value": 200 }, { "value": 250 }] }
      ]
    }
  ]
}

Step 3 — Export

// Node.js — write to file
import { writeFileSync } from "node:fs";
import { generateWorkbook } from "@office-open/xlsx";

const buffer = await generateWorkbook({
  worksheets: [
    {
      name: "Sales",
      rows: [
        { cells: [{ value: "Product" }, { value: "Q1" }, { value: "Q2" }] },
        { cells: [{ value: "Widget" }, { value: 100 }, { value: 150 }] },
        { cells: [{ value: "Gadget" }, { value: 200 }, { value: 250 }] },
      ],
    },
  ],
});
writeFileSync("output.xlsx", buffer);
// Browser — download as file
import { generateWorkbook } from "@office-open/xlsx";

const blob = await generateWorkbook(
  {
    worksheets: [
      {
        name: "Sales",
        rows: [
          { cells: [{ value: "Product" }, { value: "Q1" }, { value: "Q2" }] },
          { cells: [{ value: "Widget" }, { value: 100 }, { value: 150 }] },
          { cells: [{ value: "Gadget" }, { value: 200 }, { value: 250 }] },
        ],
      },
    ],
  },
  { type: "blob" },
);
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "output.xlsx";
a.click();

Multiple Worksheets

import { generateWorkbook } from "@office-open/xlsx";

const buffer = await generateWorkbook({
  worksheets: [
    {
      name: "Summary",
      rows: [{ cells: [{ value: "Total" }, { value: 500 }] }],
    },
    {
      name: "Details",
      rows: [
        { cells: [{ value: "Item" }, { value: "Amount" }] },
        { cells: [{ value: "A" }, { value: 200 }] },
        { cells: [{ value: "B" }, { value: 300 }] },
      ],
    },
  ],
});

Output Formats

generateWorkbook supports multiple output formats via the optional second argument. See the page for the full list.

UsageReturnsUse Case
generateWorkbook(opts)BufferNode.js file I/O
generateWorkbook(opts, { type: "blob" })BlobBrowser downloads
generateWorkbook(opts, { type: "base64" })stringData URLs, API payloads
generateWorkbookSync(opts)BufferSynchronous Node.js I/O
Copyright © 2026