Skip to content

Commit 48ad46f

Browse files
committed
new node demo
1 parent d7711c2 commit 48ad46f

File tree

3 files changed

+350
-0
lines changed

3 files changed

+350
-0
lines changed

demos/node/demo.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* NAME: demo.js
3+
* AUTH: Brent Ely (https://github.com/gitbrent/)
4+
* DATE: 20220404
5+
* DESC: xlsx-js-style feature demos for Node.js
6+
* REQS: npm 14.x + `npm install pptxgenjs`
7+
* USAGE: `node demo.js` (runs local tests with callbacks etc)
8+
*/
9+
10+
import XLSX from "xlsx-js-style";
11+
12+
console.log(`\n\n--------------------==~==~==~==[ STARTING DEMO... ]==~==~==~==--------------------\n`);
13+
console.log("`XLSX.version` ......... = " + XLSX.version);
14+
console.log("`XLSX.style_version` ... = " + XLSX.style_version);
15+
16+
// STEP 1: Create a new Workbook
17+
const wb = XLSX.utils.book_new();
18+
19+
// STEP 2: Create data rows
20+
let row1 = ["a", "b", "c"];
21+
let row2 = [1, 2, 3];
22+
let row3 = [
23+
{ v: "Courier: 24", t: "s", s: { font: { name: "Courier", sz: 24 } } },
24+
{ v: "bold & color", t: "s", s: { font: { bold: true, color: { rgb: "FF0000" } } } },
25+
{ v: "fill: color", t: "s", s: { fill: { fgColor: { rgb: "E9E9E9" } } } },
26+
{ v: "line\nbreak!", t: "s", s: { alignment: { wrapText: true } } },
27+
];
28+
29+
// STEP 3: Create Worksheet, add data, set cols widths
30+
const ws = XLSX.utils.aoa_to_sheet([row1, row2, row3]);
31+
ws["!cols"] = [{ width: 30 }, { width: 20 }, { width: 20 }];
32+
XLSX.utils.book_append_sheet(wb, ws, "browser-demo");
33+
34+
// STEP 4: Write Excel file to browser
35+
XLSX.writeFile(wb, "xlsx-js-style-demo.xlsx");
36+
37+
console.log(`\n--------------------==~==~==~==[ ...DEMO COMPLETE ]==~==~==~==--------------------\n\n`);

demos/node/package-lock.json

+291
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demos/node/package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "xlsx-js-style-demos-node",
3+
"version": "1.2.0",
4+
"author": {
5+
"name": "Brent Ely",
6+
"url": "https://github.com/gitbrent/"
7+
},
8+
"type": "module",
9+
"description": "Create Excel spreadsheets with basic styling options using JavaScript",
10+
"homepage": "https://gitbrent.github.io/xlsx-js-style/",
11+
"scripts": {
12+
"demo": "node demo.js"
13+
},
14+
"repository": {
15+
"type": "git",
16+
"url": "git+https://github.com/gitbrent/xlsx-js-style.git"
17+
},
18+
"license": "MIT",
19+
"dependencies": {
20+
"xlsx-js-style": "^1.2.0"
21+
}
22+
}

0 commit comments

Comments
 (0)