1.0.2 • Published 5 years ago

graylab-excel v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

Graylab Excel

This is an excel.js adapter It will take JSON input and generate a generic excel in tabular format based on the input.

The module will handle formatting on its own, such as bold on headers and borders on the table.

To generate multiple files, simply pass a bigger JSON with each file's path being the key of the root level and its sub sheets being the value.

The orientation of the sheet could either be set to vertical or horizontal based on preference, it defaults to vertical.

Views can be provided if required, i.e frozen, split etc. similar to view object in excel.js

In data, each column would be considered as one object, with the keys being the title and values being the values of the cell. If the value is an object then a merged column would be created, where the main title would be the key of the object and its sub column would be the keys inside the said object.

The following example will demonstrate the flow.

###Example:

let generateExcel = require('graylab-excel');
let  data = { 
"sheetData": {
//- Name of the sheet
"./excelExport.xlsx": [
    //- Sub Sheets
    {
        //- Name of the sub sheet
        "title": "sheet one",
        //- Sub sheet orientation
        "horizontal":true,
        "views": [
            {
                "state": "frozen",
                "xSplit": 4,
                "ySplit": 0
            }
        ],
        //- Data format
        "data":[{
            "Field One":10,
            "Field Two":3,
            "Field Three":5,
            "Field Four":{
                "Sub Field One":{
                    "Sub Sub Field One":10,
                    "Sub Sub Field Two":{
                        "Third Level":10
                    }
                },
                "Sub Field Two":10
            }
        },{
            "Field One":13,
            "Field Two":4,
            "Field Three":6,
            "Field Four":{
                "Sub Field One":{
                    "Sub Sub Field One":10,
                    "Sub Sub Field Two":{
                        "Third Level":10
                    }
                },
                "Sub Field Two":10
            }
        },{
            "Field One":19,
            "Field Two":6,
            "Field Three":8,
            "Field Four":{
                "Sub Field One":{
                    "Sub Sub Field One":10,
                    "Sub Sub Field Two":{
                        "Third Level":10
                    }
                },
                "Sub Field Two":10
            }
        }]				
    },
    {
        ...subSheet two
    },
    {
        ...subSheet three
    }
]}};

await generateExcel(data);
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago