-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
94 lines (85 loc) · 2.31 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const createWorkbook = require("./createWorkbook.js");
const fs = require("fs");
const crypto = require("crypto");
const args = process.argv.slice(2);
const params = [
{
"sheets": [{
"name": "Sheet1",
"headers": [{"value":"Column1"}, {"value": "Column2"}, {"value":"Column3", "blank": true}],
"data" : [
["A", "B", "C"],
{"Column1": "A", "Column2": {"value": "B", "style": "rightAlign"}, "Column3": "C"},
{"Column2": "A", "Column1": "B", "Column3": "C"},
["A", {"value": 1, "style": "percent0dp"}, "C"]
],
"options": "{}"
}],
"styles": {
"percent0dp": {
"numberFormat": "0%"
},
"rightAlign": {
"alignment": {
"horizontal": "right"
}
}
},
"filename": "header_and_formatting.xlsx"
},
{
"sheets": [{
"name": "Sheet1",
"data" : [
["A", "B", "C"],
["A", {"value": "B", "style": "rightAlign"}, "C"],
{"Column2": "A", "Column1": "B", "Column3": "C"},
["A", {"value": 1, "style": "percent0dp"}, "C"]
]
}],
"filename": "no_header_missing_styles.xlsx"
},
{
"sheets": [{
"name": "Sheet1",
"data" : [
["A", "B", "C"],
["D", "E", "F"],
["1", 1, 2],
[{"value": 1}, "A", 1]
]
}],
"filename": "no_header_no_formatting.xlsx"
},
{
"sheets": [{
"name": "Sheet1",
"headers": [{"value":"Long column name"}, {"value": "Column2"}, {"value":"Column3", "blank": true}],
"data" : [
["A", "B", "C"],
{"Long column name": "A", "Column2": {"value": "B", "style": "rightAlign"}, "Column3": "C"},
{"Column2": "A", "Long column name": "B", "Column3": "C"},
["A", {"value": 1, "style": "percent0dp"}, "C"]
],
"columnWidths": [{"column": 1, "width": "autofit", "adjust": 0}],
"options": "{}"
}],
"styles": {
"percent0dp": {
"numberFormat": "0%"
},
"rightAlign": {
"alignment": {
"horizontal": "right"
}
}
},
"filename": "autosize.xlsx"
}
];
(async () => {
params.forEach(async ({sheets, styles, filename}) => {
const base64 = await createWorkbook({sheets, styles});
fs.writeFileSync(`test_output/${filename}`, base64, {encoding: "base64"});
});
})();