Skip to content

Fast & Memory Efficient NodeJs Excel Writer using Rust Binding

License

Notifications You must be signed in to change notification settings

slaveofcode/fastexcel

Repository files navigation

FastExcel

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 (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

// 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();

About

Fast & Memory Efficient NodeJs Excel Writer using Rust Binding

Resources

License

Stars

Watchers

Forks

Packages

No packages published