|
2 | 2 |
|
3 | 3 | > This project using [Neon](https://neon-bindings.com) as a binding to Rust to execute fast and efficient memory usage for generating XLSX document. |
4 | 4 |
|
| 5 | +> Check here for [Rust installation instruction](https://www.rust-lang.org/tools/install) |
| 6 | +
|
5 | 7 | ### Installation |
6 | 8 |
|
7 | 9 | npm i fastexcel |
8 | 10 |
|
| 11 | + npm i -D cargo-cp-artifact |
| 12 | + |
9 | 13 | ### Example |
10 | 14 |
|
11 | 15 | ``` |
12 | | -const fs = require('fs'); |
| 16 | +// index.js |
| 17 | +const path = require('path'); |
13 | 18 | const { CsvFileWriter, Converter } = require("fastexcel"); |
14 | 19 |
|
15 | | -// Part 1: Put Data to CSV/Text |
16 | | -const writer = new CsvFileWriter("./test/source-lib.csv", [ |
17 | | - "No", |
18 | | - "Name", |
19 | | - "Gender", |
20 | | -]); |
21 | | -
|
22 | | -const rows = [ |
23 | | - [1, "John", "Male"], |
24 | | - [2, "Doe", "Male"], |
25 | | -]; |
26 | | -
|
27 | | -for (const row of rows) { |
28 | | - await writer.write(row); |
29 | | -} |
30 | | -
|
31 | | -await writer.close(); |
32 | | -
|
33 | | -// Part 2: Convert csv to excel |
34 | | -const res = await Converter.toXLSX( |
35 | | - "./test/source-lib.csv", |
36 | | - "./test/result-lib.xlsx", |
37 | | -); |
| 20 | +const main = async () => { |
| 21 | + const src = path.join(process.cwd(), 'example/source.csv'); |
| 22 | + const dst = path.join(process.cwd(), 'example/generated.xlsx'); |
| 23 | +
|
| 24 | + console.log('src', src); |
| 25 | + console.log('dst', dst); |
| 26 | +
|
| 27 | + const cols = []; |
| 28 | + const totalCols = 200; |
| 29 | + for (let i = 0; i < totalCols; i++) { |
| 30 | + cols.push('Col ' + (i+1)); |
| 31 | + } |
| 32 | +
|
| 33 | + const writer = new CsvFileWriter(src, cols); |
| 34 | +
|
| 35 | + const totalRows = 1000000; // 1jt rows |
| 36 | + for (let i = 0; i < totalRows; i++) { |
| 37 | + let row = []; |
| 38 | + |
| 39 | + for (let i = 0; i < totalCols; i++) { |
| 40 | + row.push('Col No ' + (i+1)); |
| 41 | + } |
| 42 | +
|
| 43 | + row.push(row); |
| 44 | + await writer.write(row); |
| 45 | + } |
| 46 | +
|
| 47 | + await writer.close(); |
| 48 | +
|
| 49 | + // Part 2: Convert csv to excel |
| 50 | + const res = await Converter.toXLSX( |
| 51 | + src, |
| 52 | + dst |
| 53 | + ); |
| 54 | +}; |
| 55 | +
|
| 56 | +main(); |
38 | 57 | ``` |
0 commit comments