From a6127b6f467326754375f1de64b14a65d403b0fd Mon Sep 17 00:00:00 2001 From: Aditya Kresna Date: Mon, 12 Dec 2022 11:08:50 +0700 Subject: [PATCH] update example --- README.md | 63 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 5d1b602..25a2927 100644 --- a/README.md +++ b/README.md @@ -9,30 +9,45 @@ ### Example ``` -const fs = require('fs'); +// index.js +const path = require('path'); const { CsvFileWriter, Converter } = require("fastexcel"); -// Part 1: Put Data to CSV/Text -const writer = new CsvFileWriter("./test/source-lib.csv", [ - "No", - "Name", - "Gender", -]); - -const rows = [ - [1, "John", "Male"], - [2, "Doe", "Male"], -]; - -for (const row of rows) { - await writer.write(row); -} - -await writer.close(); - -// Part 2: Convert csv to excel -const res = await Converter.toXLSX( - "./test/source-lib.csv", - "./test/result-lib.xlsx", -); +const main = async () => { + const src = path.join(process.cwd(), 'example/source.csv'); + const dst = path.join(process.cwd(), 'example/generated.xlsx'); + + console.log('src', src); + console.log('dst', dst); + + const cols = []; + const totalCols = 200; + for (let i = 0; i < totalCols; i++) { + cols.push('Col ' + (i+1)); + } + + const writer = new CsvFileWriter(src, cols); + + const totalRows = 1000000; // 1jt rows + for (let i = 0; i < totalRows; i++) { + let row = []; + + for (let i = 0; i < totalCols; i++) { + row.push('Col No ' + (i+1)); + } + + row.push(row); + await writer.write(row); + } + + await writer.close(); + + // Part 2: Convert csv to excel + const res = await Converter.toXLSX( + src, + dst + ); +}; + +main(); ```