Skip to content

produce an excel file out of a flattened json object

License

Notifications You must be signed in to change notification settings

saviourofdp/jsonexcel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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('jsonexel');
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
            }
        }
    }
]

buffer = toxl(test, "My Example", ".");
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:

About

produce an excel file out of a flattened json object

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%