-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
173 lines (160 loc) · 3.39 KB
/
index.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { Workbook } from "exceljs";
const workbook = new Workbook();
const worksheet = workbook.addWorksheet("Sheet1");
worksheet.addRow(["Stock Opname Report"]);
worksheet.addRow(["Term : 01-December-2023 - 31-December-2023"]);
worksheet.addRow(["Print Date : 02-January-2024"]);
worksheet.addRow([]);
// Menambahkan header pertama
const headers = [
"no",
"",
"",
"",
"",
"",
"Code",
"Date",
"Warehouse",
"status",
"",
"",
];
const headers2 = [
"",
"",
"",
"",
"",
"Code",
"Item Name",
"Before",
"After",
"Diff",
"%",
"Unit",
];
// Menambahkan data
const data = [
[
"",
"ADJ0257",
"01/12/2023",
"Bar",
"Confirmed",
10305,
"Fresh Lemon",
89,
3,
-1,
-84,
"Kg",
],
[
"",
"ADJ0257",
"01/12/2023",
"Bar",
"Confirmed",
10305,
"Fresh Lemon",
89,
3,
-1,
-84,
"pcs",
],
];
const footter = ["", "", "", "", "", "", "TOTAL", "", "", "", "", ""];
// menambahkan data ke worksheet
const header1Row = worksheet.addRow(headers);
const header2Row = worksheet.addRow(headers2);
data.forEach((row, index) => {
const dataRow = worksheet.addRow(row);
// Memberikan border pada seluruh data row
dataRow.eachCell((cell, cellNumber) => {
cell.border = {
top: { style: index === 0 ? "thin" : "none" }, // Add top border for the first data row
right: { style: cellNumber === dataRow.cellCount ? "thin" : "none" }, // Add right border for the last cell in each row
};
});
});
const footerRow = worksheet.addRow(footter);
// style
header1Row.eachCell((cell) => {
cell.fill = {
type: "pattern",
pattern: "solid",
fgColor: { argb: "B0B0B0" },
};
cell.border = {
top: { style: "thin" },
bottom: { style: "thin" },
};
});
header2Row.eachCell((cell) => {
cell.fill = {
type: "pattern",
pattern: "solid",
fgColor: { argb: "B0B0B0" },
};
cell.border = {
top: { style: "thin" },
bottom: { style: "thin" },
};
});
footerRow.eachCell((cell, cellNumber) => {
cell.fill = {
type: "pattern",
pattern: "solid",
fgColor: { argb: "B0B0B0" },
};
cell.border = {
top: { style: "thin" },
bottom: { style: "thin" },
right: { style: cellNumber === footerRow.cellCount ? "thin" : "none" },
};
});
worksheet.getCell("L5").border = {
right: { style: "thin" },
top: { style: "thin" },
bottom: { style: "thin" },
};
worksheet.getCell("L6").border = {
right: { style: "thin" },
top: { style: "thin" },
bottom: { style: "thin" },
};
worksheet.views = [{ state: "frozen", xSplit: 0, ySplit: 6, activeCell: "A6" }];
worksheet.getColumn(6).width = 6;
worksheet.getColumn(7).width = 30;
worksheet.getColumn(8).width = 8;
worksheet.getColumn(9).width = 8;
worksheet.getColumn(10).width = 8;
worksheet.getColumn(11).width = 6;
worksheet.getColumn(12).width = 6;
worksheet.getColumn(12).alignment = {
vertical: "middle",
horizontal: "right",
};
worksheet.getCell("H6").alignment = {
vertical: "middle",
horizontal: "right",
};
worksheet.getCell("I6").alignment = {
vertical: "middle",
horizontal: "right",
};
worksheet.getCell("J6").alignment = {
vertical: "middle",
horizontal: "right",
};
// Menyimpan Workbook ke File Excel
workbook.xlsx
.writeFile("output.xlsx")
.then(() => {
console.log("File Excel berhasil disimpan.");
})
.catch((error) => {
console.error("Gagal menyimpan file Excel:", error);
});