-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexcel-creator.js
97 lines (90 loc) · 2.2 KB
/
excel-creator.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
import ExcelJS from "exceljs";
const createExcel = async (sales, author) => {
function dateToSlug(date) {
// Función para convertir una fecha en un formato de slug
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
const hours = String(date.getHours()).padStart(2, "0");
const minutes = String(date.getMinutes()).padStart(2, "0");
const seconds = String(date.getSeconds()).padStart(2, "0");
const slug = `${year}_${month}_${day}_${hours}_${minutes}_${seconds}`;
return slug.toLowerCase();
}
const dateHour = dateToSlug(new Date());
const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet("liquidación");
// Configurar las columnas del archivo de Excel
worksheet.columns = [
{
header: "Id de factura",
key: "id",
width: 12,
},
{
header: "Fecha",
key: "date",
width: 10,
},
{
header: "ISBN",
key: "isbn",
width: 15,
style: {
numFmt: "0",
},
},
{
header: "Libro",
key: "book",
width: 30,
},
{
header: "PVP",
key: "PVP",
width: 10,
style: {
numFmt: '"$"#,##0.00',
},
},
{
header: "Ejemplares vendidos",
key: "ammount",
width: 19,
},
{
header: "Total facturado",
key: "billed",
width: 14,
style: {
numFmt: '"$"#,##0.00',
},
},
{
header: "Porcentaje de regalías",
key: "royalties",
width: 20,
style: {
numFmt: "0%",
},
},
{
header: "Regalías generadas",
key: "payedRoyalties",
width: 18,
style: {
numFmt: '"$"#,##0.00',
},
},
];
// Agregar filas al archivo de Excel con los datos de ventas
sales.forEach((item) => {
worksheet.addRows(item);
worksheet.addRow(" ");
});
// Guardar el archivo de Excel
await workbook.xlsx.writeFile(
`./excel-files/${author}-royalties-${dateHour}.xlsx`
);
};
export default createExcel;