xlsxtable
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

xlsxtable

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

  • Emboldens and (optionally) autofilters and freezes the headings
  • Sets reasonable column widths
  • Converts dates and times to native Excel format (roughly: floating-point days since 1 Jan 1900)

The only runtime dependency is littlezipper (which has no runtime dependencies of its own).

How to say xlsxtable

Pronunciation is as close as possible to 'vegetable' or 'Whitstable'. That is: ex-el-ess-EX-ta-bl.

Types

  • XlsxTypes.String values will be coerced to string.
  • XlsxTypes.Number values must be provided as number or string.
  • XlsxTypes.Date, XlsxTypes.Time and XlsxTypes.DateTime values should be provided as Date objects, with string as a fallback (e.g. if the date is infinite or otherwise unsupported).
  • null or undefined values result in an empty cell for all XlsxTypes.

Example usage

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

const now = new Date();

createXlsx({
  // sheet data
  headings: ['id', 'name', 'dob', 'lastUpdated'],
  types: [XlsxTypes.Number, XlsxTypes.String, XlsxTypes.Date, XlsxTypes.DateTime],
  data: [
    [1, 'Anna', new Date('1979-01-01'), now],
    [2, 'Bryn', new Date('1979-01-02'), now],
    [null, null, null, null],
    [3, 'Chip', new Date('1979-01-03'), 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));

Readme

Keywords

Package Sidebar

Install

npm i xlsxtable

Weekly Downloads

1,319

Version

0.3.0

License

MIT

Unpacked Size

56.7 kB

Total Files

7

Last publish

Collaborators

  • jawj