https://github.com/slaveofcode/fastexcel
Fast & Memory Efficient NodeJs Excel Writer using Rust Binding
https://github.com/slaveofcode/fastexcel
Last synced: 8 months ago
JSON representation
Fast & Memory Efficient NodeJs Excel Writer using Rust Binding
- Host: GitHub
- URL: https://github.com/slaveofcode/fastexcel
- Owner: slaveofcode
- License: mit
- Created: 2022-12-11T20:09:06.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-15T10:06:20.000Z (almost 3 years ago)
- Last Synced: 2025-02-20T13:03:30.660Z (9 months ago)
- Language: Rust
- Size: 433 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FastExcel
> This project need Rust to be installed, check here for [Rust installation instruction](https://www.rust-lang.org/tools/install)
> This project using [Rust](https://www.rust-lang.org) and [Neon](https://neon-bindings.com) as a binding to Rust to execute fast and efficient memory usage for generating XLSX document from NodeJs.
> This project cannot be executed via NVM based NodeJs, you should deactivate (via `nvm deactivate`) or use a system version installation of NodeJs (via `nvm use system`).
Writing a large amount of data into Excel file is not a trivial task when you have a limited memory (RAM) allocated. Especially when working at a small node on the server. This library is created to solve that problem, using the efficiency of Rust while generating a large datasheet of XLSX from CSV.
### Installation
npm i -D cargo-cp-artifact
npm i fastexcel
### How it works
1. Generate the CSV
2. Convert the CSV to XLSX
The CSV generation is happen on the NodeJs side, and converting XLSX file is on Rust side (via Neon)
### Example Usage
```js
// dummy-excel.js
const path = require('path');
const { CsvFileWriter, Converter } = require("fastexcel");
const main = async () => {
const src = path.join(process.cwd(), 'example/source.csv');
const dst = path.join(process.cwd(), 'example/generated.xlsx');
const cols = [];
const totalCols = 200; // 200 columns
for (let i = 0; i < totalCols; i++) {
cols.push('Col ' + (i+1));
}
const writer = new CsvFileWriter(src, cols);
const totalRows = 3_00_000; // 300k rows
for (let i = 0; i < totalRows; i++) {
let row = [];
for (let i = 0; i < totalCols; i++) {
row.push('Col No ' + (i+1));
}
await writer.write(row);
}
await writer.close();
// Part 2: Convert csv to excel
const res = await Converter.toXLSX(
src,
dst
);
};
main();
```