npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

simple-xlsx-export

v1.0.0

Published

Zero-dependency library for exporting data to XLSX files

Downloads

20

Readme

simple-xlsx-export

npm version License: MIT

A zero-dependency JavaScript/TypeScript library for exporting data to XLSX (Excel) files. No external libraries required - generates valid Excel files easily - for example as export from grids in applications, where no heavy libraries are needed.

Features

Zero Dependencies - No external libraries required
Small Bundle Size - Lightweight implementation
Simple API - Just two functions to export data
Security - Protection against formula injection and common vulnerabilities

Installation

npm install simple-xlsx-export

Quick Start

Recommended: Use exportFull() for Most Cases

For any data with numbers, dates, or when you want column widths, use exportFull(). It auto-detects types and is the easiest option!

import { exportFull, saveToFile } from 'simple-xlsx-export';

const data = [
  [
    { data: 'Name', width: 20 },
    { data: 'Age', width: 10 },
    { data: 'Salary', width: 15 }
  ],
  [
    { data: 'John Doe' },
    { data: 30 },        // Auto-detected as number!
    { data: 75000 }      // Works in Excel formulas!
  ],
  [
    { data: 'Jane Smith' },
    { data: 25 },
    { data: 65000 }
  ]
];

const xlsxData = exportFull(data, 'employees');
await saveToFile(xlsxData, 'employees.xlsx');

Alternative: exportOnlyString() for Text-Only Data

Only use this if you have pure text data with no numbers or dates:

import { exportOnlyString, saveToFile } from 'simple-xlsx-export';

const data = [
  ['Name', 'City', 'Country'],
  ['John Doe', 'New York', 'USA'],
  ['Jane Smith', 'London', 'UK']
];

const xlsxData = exportOnlyString(data, 'addresses');
await saveToFile(xlsxData, 'addresses.xlsx');

// Note: All values become text in Excel, even if they look like numbers

Key Differences

| Feature | exportOnlyString | exportFull | |---------|------------------|------------| | Input | string[][] | CellData[][] | | Type detection | ❌ All text | ✅ Automatic! | | Numbers work in formulas | ❌ No | ✅ Yes | | Column widths | ❌ No | ✅ Yes | | Best for | Pure text | Everything else |

All Supported Data Types Example

import { exportFull, saveToFile } from 'simple-xlsx-export';

const data = [
  [
    { data: 'Name', width: 20 },
    { data: 'Age', width: 10 },
    { data: 'Salary', width: 15 },
    { data: 'Start Date', width: 15 },
    { data: 'Active', width: 10 }
  ],
  [
    { data: 'John Doe' },              // string (auto)
    { data: 30 },                      // number (auto)
    { data: 75000 },                   // number (auto)
    { data: new Date('2020-01-15') },  // date (auto)
    { data: true }                     // boolean (auto)
  ]
];

const xlsxData = exportFull(data, 'employees');
await saveToFile(xlsxData, 'employees.xlsx');

// Explicit types (optional - auto-detection usually works)
const explicitTypes = [[
  { data: '100', type: 'string' },  // Force as text
  { data: '200', type: 'number' }   // Force as number
]];

API Reference

exportOnlyString(data, filename, sheetName?)

Exports a simple 2D array of strings to XLSX format. All values become text in Excel.

Parameters:

  • data: string[][] - Two-dimensional array of strings
  • filename: string - Output filename (without .xlsx extension)
  • sheetName?: string - Optional sheet name (default: 'Sheet1')

Returns: Uint8Array - The XLSX file data

exportFull(data, filename, sheetName?)

Exports a 2D array of CellData objects with auto-type detection and formatting (recommended).

Parameters:

  • data: CellData[][] - Two-dimensional array of CellData objects
  • filename: string - Output filename (without .xlsx extension)
  • sheetName?: string - Optional sheet name (default: 'Sheet1')

Returns: Uint8Array - The XLSX file data

saveToFile(xlsxData, filename)

Saves XLSX data to a file (Node.js only).

Parameters:

  • xlsxData: Uint8Array - The XLSX file data from export functions
  • filename: string - Output filename (will add .xlsx if missing)

Returns: Promise<void>

downloadInBrowser(xlsxData, filename)

Triggers a download in the browser.

Parameters:

  • xlsxData: Uint8Array - The XLSX file data from export functions
  • filename: string - Download filename (will add .xlsx if missing)

CellData Interface

interface CellData {
  data: string | number | boolean | Date;
  type?: 'string' | 'number' | 'boolean' | 'date';  // Auto-detected if omitted
  width?: number;  // Column width in character units (0-255)
}

Supported Data Types

  • string - Text data
  • number - Numeric values
  • boolean - TRUE/FALSE values
  • date - Date objects (formatted as dates in Excel)

Browser Usage

Requires a bundler (Vite, Webpack, Parcel, etc.)

import { exportFull, downloadInBrowser } from 'simple-xlsx-export';

// In your click handler
const xlsx = exportFull(data, 'report');
downloadInBrowser(xlsx, 'report.xlsx');

See QUICKSTART.md for React and other framework examples.

Security

Built-in protection against common vulnerabilities:

  • Formula Injection Prevention - Automatically sanitizes dangerous formulas
  • Input Validation - Enforces Excel's limits (1,048,576 rows, 16,384 columns)
  • XML Escaping - Properly escapes all user data
  • No Dependencies - Zero supply chain attack surface

Why Zero Dependencies?

  • Smaller bundle - No bloat (~17 kB)
  • Better security - No supply chain vulnerabilities
  • Easier maintenance - No dependency updates needed
  • Full control - Complete understanding of the codebase

Compatibility

Node.js: 14+
Browsers: All modern browsers (Chrome, Firefox, Safari, Edge)

License

MIT License - see LICENSE file for details.

Contributing

Contributions welcome! Read CONTRIBUTING.md first.

Core principles: Zero dependencies, extreme simplicity, small package size.

Repository

GitHub: simple-xlsx-export


Simple, focused XLSX export. That's it.