Code Monkey home page Code Monkey logo

xlr's Introduction

XLR

Code Climate FOSSA Status

https://nodei.co/npm/xlr.png?downloads=true&downloadRank=true&stars=true

A simple node module for exporting a data set to an Excel xlsx file.

Heavily inspired by Node-Excel-Export

Using XLR

Example of a config object to generate a Excel worksheet

{
  name: 'name.xlsx',
  columns: [
    {
      type: 'string',
      width: 10,
    }
  ],
  rows: [],
  merge: []
  stylesXmlFile: 'styles.xml'
}
  • name: Specify worksheet name
  • columns: Array of column definitions
    • type: string / date / bool / number
    • width: (optional) total characters in cell
  • rows: Array of data to be exported. Data needs to be a 2D-Array and should be the same length as the columns array.
  • merge: Array of merge cell objects.
    • row: row index (starting at 1)
    • fromColumn: start the merge from column index (starting at 1)
    • toColumn: end the merge at column index (starting at 1)
  • stylesXmlFile: Absolute path to Excel styles.xml file. An easy way to get a styles.xml file is to unzip an existing xlsx file which has the desired styles and copy the styles.xml file.

Example usage with Express

const express = require('express');
const xlr = require('xlr');
const app = express();

app.get('/', function (req, res) {
  const conf = {
    stylesXmlFile: __dirname + '/styles.xml',
    name: 'report-is-a-thing',
    cols: [
      {
        type: 'string',
        width: 15
      },
      {
        type: 'string',
        width: 25
      },
      {
        type: 'string',
        width: 30
      }
    ],
    rows: [
      [{ value: 'First Name', style: 1 }, { value: 'Last Name', style: 1 }, { value: 'Email', style: 1 }],
      ['Bruce', 'Wayne', '[email protected]'],
      ['Clark', 'Kent', '[email protected]'],
      ['This cell is going to be merged', '', '[email protected]'],
      ['Peter', 'Parker', '[email protected]']
    ],
     merge: [
      { row: 4, fromColumn: 1, toColumn: 2 } 
    ]
  };

  const result = xlr(conf);
  res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  res.setHeader('Content-Disposition', 'attachment; filename=Report.xlsx');
  res.send(new Buffer(result, 'binary'));
});

app.listen(3001, function () {
  console.log('listening on port 3001');
});

License

XLR is © 2017 MADE Code PTY Ltd. It is free software, and may be redistributed under the terms specified in the LICENSE file.

Maintained by

madeagency

XLR was created and is maintained MADE Agency PTY Ltd. The names and logos for MADE Code are trademarks of MADE Code PTY Ltd.

We love open source software. See our Github Profile for more.

We're always looking for talented people who love programming. Get in touch with us.

License

FOSSA Status

xlr's People

Watchers

James Cloos avatar Mathieu M. avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.