Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
slaveofcode committed Dec 12, 2022
1 parent c8529d7 commit a6127b6
Showing 1 changed file with 39 additions and 24 deletions.
63 changes: 39 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
```

0 comments on commit a6127b6

Please sign in to comment.