2.1.2 • Published 3 years ago

json-and-xlsx v2.1.2

Weekly downloads
48
License
MIT
Repository
github
Last release
3 years ago

json-and-xlsx

A package for converting JSON to XLSX and XLSX to JSON

Global Functions

ParamDescription
xlsxToJsonThe function for handling xlsx to json conversion
jsonToXlsxThe function for handling json to xlsx conversion

xlsxToJson

This function is used to handle xlsx to json conversions

readAndGet(xlsxData)

Reads workbook returns a json output

ParamTypeDescription
xlsxDataworkbookThe workbook to get in js

Usage

Xlsx Data in Sheet1

titledescription
Title 1Desc 1
Title 2Desc 2
const {xlsxToJson} = require('json-and-xlsx');

const workbook = require('./workbook'); // Get Workbook

const output = xlsxToJson.readAndGet(workbook);
/*
    returns [
    {
        title: 'Title 1',
        description: 'Desc 1'
    },
    {
        title: 'Title 2',
        description: 'Desc 2'
    }
];
*/

readFromBufferAndGet(buffer)

Reads from a buffer and returns a json output

ParamTypeDescription
bufferBufferThe buffer to get in js object

Usage

const {xlsxToJson} = require('json-and-xlsx');
const buffer = require('./buffer-data.js');

const output = xlsxToJson.readFromBufferAndGet(buffer);
/*
    returns [
    {
        title: 'Title 1',
        description: 'Desc 1'
    },
    {
        title: 'Title 2',
        description: 'Desc 2'
    }
];
*/

readFromFileAndGet(xlsxData)

Reads workbook returns a json output

ParamTypeDescription
xlsxDataworkbookThe workbook to get in js

Usage

Xlsx Data in Sheet1 stored in workbook.xlsx

titledescription
Title 1Desc 1
Title 2Desc 2
const {xlsxToJson} = require('json-and-xlsx');

const output = xlsxToJson.readFromFileAndGet('workbook.xlsx');
/*
    returns [
    {
        title: 'Title 1',
        description: 'Desc 1'
    },
    {
        title: 'Title 2',
        description: 'Desc 2'
    }
];
*/

jsonToXlsx

This function is used to handle json to xlsx conversions

//  json-data.json
[
    {
        "title": "Title 1",
        "description": "Desc 1"
    },
    {
        "title": "Title 2",
        "description": "Desc 2"
    }
]

readAndGet(jsonData)

Reads json returns a workbook

const {jsonToXlsx} = require('json-and-xlsx');

const jsonData = [
    {
        title: "Title 1",
        description: "Desc 1"
    },
    {
        title: "Title 2",
        description: "Desc 2"
    }
]; // Could be a JSON String

const output = jsonToXlsx.readAndGet(jsonData);
/*
    returns Workbook
*/

readAndGetBuffer(jsonData)

Reads json returns a buffer of the workbook

const {jsonToXlsx} = require('json-and-xlsx');

const jsonData = [
    {
        title: "Title 1",
        description: "Desc 1"
    },
    {
        title: "Title 2",
        description: "Desc 2"
    }
]; // Could be a JSON String

const output = jsonToXlsx.readAndGetBuffer(jsonData);
/*
    returns Buffer
*/

readFromFileAndGet(sourceFilePath)

Reads json returns a workbook

const {jsonToXlsx} = require('json-and-xlsx');

const output = jsonToXlsx.readFromFileAndGet('json-data.json');
/*
    returns Workbook
*/

readFromFileAndGetBuffer(sourceFilePath)

Reads json from sourceFile and returns a Buffer

const {jsonToXlsx} = require('json-and-xlsx');

const output = jsonToXlsx.readFromFileAndGetBuffer('json-data.json');
/*
    returns Buffer
*/

readFromFileToFile(sourceFilePath, destFilePath)

Reads json from file and writes the workbook to a file

const {jsonToXlsx} = require('json-and-xlsx');

jsonToXlsx.readFromFileToFile('json-data.json', 'workbook.xlsx');
/*
    writes json to workbook.xlsx
*/
2.1.2

3 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago