A package for converting JSON to XLSX and XLSX to JSON
Param | Description |
---|---|
xlsxToJson | The function for handling xlsx to json conversion |
jsonToXlsx | The function for handling json to xlsx conversion |
This function is used to handle xlsx to json conversions
Reads workbook returns a json output
Param | Type | Description |
---|---|---|
xlsxData | workbook | The workbook to get in js |
title | description |
---|---|
Title 1 | Desc 1 |
Title 2 | Desc 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'
}
];
*/
Reads from a buffer and returns a json output
Param | Type | Description |
---|---|---|
buffer | Buffer | The buffer to get in js object |
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'
}
];
*/
Reads workbook returns a json output
Param | Type | Description |
---|---|---|
xlsxData | workbook | The workbook to get in js |
title | description |
---|---|
Title 1 | Desc 1 |
Title 2 | Desc 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'
}
];
*/
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"
}
]
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
*/
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
*/
Reads json returns a workbook
const {jsonToXlsx} = require('json-and-xlsx');
const output = jsonToXlsx.readFromFileAndGet('json-data.json');
/*
returns Workbook
*/
Reads json from sourceFile
and returns a Buffer
const {jsonToXlsx} = require('json-and-xlsx');
const output = jsonToXlsx.readFromFileAndGetBuffer('json-data.json');
/*
returns Buffer
*/
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
*/