https://github.com/neverbot/json-xls-converter
Node utility to convert json to an Excel file.
https://github.com/neverbot/json-xls-converter
excel javascript json node
Last synced: 2 months ago
JSON representation
Node utility to convert json to an Excel file.
- Host: GitHub
- URL: https://github.com/neverbot/json-xls-converter
- Owner: neverbot
- License: mit
- Created: 2023-06-22T12:26:18.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-29T13:14:13.000Z (over 2 years ago)
- Last Synced: 2025-10-28T05:35:14.511Z (8 months ago)
- Topics: excel, javascript, json, node
- Language: JavaScript
- Homepage:
- Size: 241 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# json-xls-converter
[](https://www.npmjs.com/package/json-xls-converter)
[](https://www.npmjs.com/package/json-xls-converter)
[](https://github.com/neverbot/json-xls-converter/blob/master/LICENSE)
[](https://www.npmjs.com/package/json-xls-converter)
**Utility to convert json to an Excel file.**
This is an updated version of [json2xls](https://github.com/rikkertkoppes/json2xls) which seems to be abandoned, and have some important vulnerabilities in its dependencies (some of them abandoned too).
This project is based in:
- [`json2xls`](https://github.com/rikkertkoppes/json2xls), by [Rikkert Koppes](https://github.com/rikkertkoppes).
- [`excel-export`](https://github.com/functionscope/Node-Excel-Export), by [functionscope](https://github.com/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:
```javascript
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.
```javascript
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
1. `npm remove json2xls && npm install json-xls-converter`
2. Change every import from:
`import json2xls from 'json2xls';`
to:
`import { converter } from 'json-xls-converter';`
3. Change every invocation from:
`const xls = json2xls(data);`
to:
`const xls = await converter(data);`
4. If you are using it as an express middleware, change from:
`app.use(json2xls.middleware);`
to:
`app.use(converter.middleware);`