This project need Rust to be installed, check here for Rust installation instruction
This project using Rust and Neon 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 (vianvm 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.
npm i -D cargo-cp-artifact
npm i fastexcel
- Generate the CSV
- Convert the CSV to XLSX
The CSV generation is happen on the NodeJs side, and converting XLSX file is on Rust side (via Neon)
// 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();