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 🙏

© 2024 – Pkg Stats / Ryan Hefner

xlsxtable

v0.3.1

Published

Create nice Excel files from tabular data

Downloads

15,807

Readme

xlsxtable

A small, simple library to create nice .xlsx Excel files from tabular data, which:

  • Emboldens and (optionally) freezes and autofilters the headings
  • Sets column widths based on cell content
  • Converts dates and times to native Excel format (roughly: floating-point days since 0 Jan 1900)
  • Works everywhere, including Node and browsers

Size: under 7KB gzipped. The only runtime dependency is littlezipper (which is by the same author, tiny, and has no runtime dependencies of its own).

This library powers .xlsx download in the Neon SQL Editor.

How do you say xlsxtable?

Pronunciation rhymes with Hextable, or is similar to vegetable. That is: ex-el-ess-EX-tuh-bl.

Types

Types are defined on a per-column basis. The library supports Excel numbers, strings, dates/times, and empty cells.

Excel has no concept of time zones, so the date and time types have local and UTC variants. The local variants produce a date or time that's the same as the one you get from date.toString() (minus the local timezone information, and formatted differently). The UTC variants produce a date or time that's the same as the one shown by date.toISOString() (minus the Z, and formatted differently).

  • For XlsxTypes.String columns, cell values will be coerced to string.
  • For XlsxTypes.Number columns, cell values must be provided as either number or (numeric) string.
  • For XlsxTypes.LocalDate, XlsxTypes.UTCDate, XlsxTypes.LocalTime, XlsxTypes.UTCTime, XlsxTypes.LocalDateTime and XlsxTypes.UTCDateTime columns, cell values should be provided as Date objects, with string as a fallback (e.g. if the date is infinite, or before 1900, or otherwise unsupported by Excel).
  • For all column types, null or undefined cell values result in an empty cell.

Example usage

To write an .xlsx file in Node:

import { createXlsx, XlsxTypes as Xl } from 'xlsxtable';
import { writeFileSync } from 'fs';

const now = new Date();

createXlsx({
  // sheet data
  headings: ['id', 'name', 'dob', 'wake_up', 'lastUpdated'],
  types: [Xl.Number, Xl.String, Xl.LocalDate, Xl.LocalTime, Xl.LocalDateTime],
  data: [
    [1, 'Anna', new Date(1979, 0, 1), new Date(0, 0, 0, 7), now],
    [2, 'Bryn', new Date(1989, 1, 2), new Date(0, 0, 0, 8), now],
    [3, 'Chip', new Date(1999, 2, 3), new Date(0, 0, 0, 9), now],
  ],
  // options
  sheetName: 'Sheet 1',  // shown on the tab at the bottom: limited character range allowed
  freeze: true,          // freeze the top/header row
  autoFilter: true,      // enable autofilter for headers
  wrapText: true,        // wrap long text cells
  // metadata
  creator: 'Diane', 
  title: 'Blughupsnitch data',
  description: 'Data about the blughupsnitch',
  company: 'Dogoodnever Inc.',
})
  .then(xlsx => writeFileSync('/path/to/my.xlsx', xlsx));

This produces my.xlsx:

Screenshot

To provide a download in browsers, something like this works well:

const xlsx = await createXlsx(/* ... */);

const url = URL.createObjectURL(new Blob([xlsx]));
const link = document.createElement('a');
link.style.display = 'none';
document.body.appendChild(link);
link.href = url;
link.download = 'my.xlsx';
link.click();
setTimeout(() => {
  URL.revokeObjectURL(url);
  document.body.removeChild(link);
}, 0);

License

MIT licensed.