2.0.3 • Published 6 years ago

jsonexcel v2.0.3

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

This module lets you create an excel file out of an array of javascript objects. The objects are flattened using flatjson. The resulting excel sheet has one column per key in the flattened objects. Each row in the excel sheet corresponds to the values of each object in the input array.

The array of objects do not necessarily need to have the same set of keys - but the excel sheet will have the union of all keys as the column list.

Example Usage

toxl = require('jsonexcel');
fs = require('fs');

var test = [
    {
        parent1: {
            child1: {
                child11: 10, 
                child12: 11
            }, 
            child2: {
                child21: 20, 
                child22: 21
            }
        }, 
        parent2 : {
            child1: {
                child11: 101, 
                child21: 102
            }
        }
    }, 
    {
        parent1: {
            child2: {
                child21: 20, 
                child22: 21
            }, 
            child3: {
                child31: 30, 
                child32: 31
            }
        }, 
        parent2 : {
            child1: {
                child11: 101, 
                child21: 102
            }
        }
    }
]

var opts = {
    sheetname : "My Example",
    delimiter : "."
}

buffer = toxl(test, opts);
fs.writeFile("example.xlsx", buffer,  "binary",function(err) {
    if(err) {
        console.log(err);
    } else {
        console.log("Saved excel file to example.xlsx");
    }
});

The resulting excel file will look like this:

2.0.3

6 years ago

2.0.2

7 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago