json-xls-converter
v1.4.4
Published
[](https://www.npmjs.com/package/json-xls-converter) [](https://www.npmjs.com/package/json-xls-converter) [.
This project is based in:
json2xls, by Rikkert Koppes.excel-export, by functionscope.
None of those projects included any kind of license, I'm distributing this new version with the MIT license.
Installation
npm i json-xls-converter
Usage
To save as a file:
import { converter } from 'json-xls-converter';
import fs from 'fs/promises';
const json = {
foo: 'bar',
qux: 'moo',
poo: 123,
stux: new Date()
}
const xls = await converter(json);
await fs.writeFile('data.xlsx', xls, 'binary');Or use as an express middleware. It adds a convenience xls method to the response object to immediately output an excel file as a download.
const jsonArr = [{
foo: 'bar',
qux: 'moo',
poo: 123,
stux: new Date()
},
{
foo: 'bar',
qux: 'moo',
poo: 345,
stux: new Date()
}];
app.use(converter.middleware);
app.get('/', (req, res) => {
res.xls('data.xlsx', jsonArr);
});Migrating from json2xls to json-xls-converter
npm remove json2xls && npm install json-xls-converterChange every import from:
import json2xls from 'json2xls';to:
import { converter } from 'json-xls-converter';Change every invocation from:
const xls = json2xls(data);to:
const xls = await converter(data);If you are using it as an express middleware, change from:
app.use(json2xls.middleware);to:
app.use(converter.middleware);
