Skip to content

How to use

Ronni Egeriis Persson edited this page Jan 22, 2019 · 4 revisions

How to use zipcelx

Install

Install using yarn, npm, or download the files, whatever you prefer. lib contains pre-build source.

There are three different builds:

  • main => lib/legacy.js is a CommonJS build
  • module => lib/module.js is an ES Module build for your modern pipeline
  • standalone-build => lib/standalone.js is for drop-in use via <script>

Note: If you are using a modern build pipeline, like Rollup or Webpack 2+, they will import the ES Module, thus you are responsible for transpiling zipcelx for whatever target is relevant for your app.

Usage

zipcelx has one default export:

zipcelx(config: Config): Promise<Blob>

Config type:

type Cell = {
  value: string | number,
  type: 'string' | 'number'
};

type Row = Array<Cell>;

type Sheet = {
  data: Array<Row>
};

type Config = {
  filename: string,
  sheet: Sheet
};

Example

zipcelx takes a simple configuration object and then runs it through the parser and will in the end then create a single .xlsx file with a single sheet where all the rows of data given is parsed to the Excel XML format.

import zipcelx from 'zipcelx';

const config = {
  filename: 'general-ledger-Q1',
  sheet: {
    data: [
      [{
        value: 'Income - Webshop',
        type: 'string'
      }, {
        value: 1000,
        type: 'number'
      }]
    ]
  }
};

zipcelx(config);

Invoking zipcelx will automatically download the generated xlsx file.

Clone this wiki locally