@nkhang1902/strapi-plugin-export-import-clsx 1.6.5 → 1.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nkhang1902/strapi-plugin-export-import-clsx",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.7",
|
|
4
4
|
"description": "A powerful Strapi plugin for exporting and importing data with Excel support and advanced filtering",
|
|
5
5
|
"main": "./strapi-server.js",
|
|
6
6
|
"scripts": {
|
|
@@ -41,8 +41,7 @@
|
|
|
41
41
|
"@strapi/strapi": "^4.0.0 || ^5.0.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"
|
|
45
|
-
"xlsx-style": "^0.8.13"
|
|
44
|
+
"exceljs": "^4.4.0"
|
|
46
45
|
},
|
|
47
46
|
"files": [
|
|
48
47
|
"admin/",
|
|
@@ -1,70 +1,62 @@
|
|
|
1
|
-
const
|
|
1
|
+
const ExcelJS = require('exceljs');
|
|
2
2
|
|
|
3
|
-
function
|
|
3
|
+
function styleWorksheetUniformExcelJS(worksheet, data, options = {}) {
|
|
4
4
|
const {
|
|
5
|
-
colWidth =
|
|
6
|
-
baseRowHeight =
|
|
7
|
-
lineHeight = 15,
|
|
5
|
+
colWidth = 30,
|
|
6
|
+
baseRowHeight = 20,
|
|
7
|
+
lineHeight = 15,
|
|
8
8
|
} = options;
|
|
9
9
|
|
|
10
|
-
if (!data?.length) return
|
|
10
|
+
if (!data?.length) return;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
// Set columns
|
|
13
|
+
worksheet.columns = Object.keys(data[0]).map(key => ({
|
|
14
|
+
header: key,
|
|
15
|
+
key,
|
|
16
|
+
width: colWidth,
|
|
17
|
+
}));
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
worksheet['!cols'] = headers.map(() => ({ wch: colWidth }));
|
|
19
|
+
worksheet.addRows(data);
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
// Calculate max manual line count
|
|
19
22
|
let maxLines = 1;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
if (!cell || cell.v == null) continue;
|
|
25
|
-
|
|
26
|
-
const lines = String(cell.v).split('\n').length;
|
|
23
|
+
worksheet.eachRow((row) => {
|
|
24
|
+
row.eachCell(cell => {
|
|
25
|
+
if (!cell.value) return;
|
|
26
|
+
const lines = String(cell.value).split('\n').length;
|
|
27
27
|
maxLines = Math.max(maxLines, lines);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
30
|
|
|
31
|
-
/* ---------------- Uniform row height ---------------- */
|
|
32
31
|
const uniformHeight =
|
|
33
32
|
baseRowHeight + (maxLines - 1) * lineHeight;
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
// Apply styles
|
|
35
|
+
worksheet.eachRow((row, rowNumber) => {
|
|
36
|
+
row.height = uniformHeight;
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
wrapText: true,
|
|
52
|
-
vertical: 'center',
|
|
53
|
-
horizontal: 'left',
|
|
54
|
-
},
|
|
55
|
-
border: {
|
|
56
|
-
top: { style: 'thin' },
|
|
57
|
-
bottom: { style: 'thin' },
|
|
58
|
-
left: { style: 'thin' },
|
|
59
|
-
right: { style: 'thin' },
|
|
60
|
-
},
|
|
38
|
+
row.eachCell(cell => {
|
|
39
|
+
cell.alignment = {
|
|
40
|
+
wrapText: true,
|
|
41
|
+
vertical: 'middle',
|
|
42
|
+
horizontal: 'left',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
cell.border = {
|
|
46
|
+
top: { style: 'thin' },
|
|
47
|
+
left: { style: 'thin' },
|
|
48
|
+
bottom: { style: 'thin' },
|
|
49
|
+
right: { style: 'thin' },
|
|
61
50
|
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
51
|
|
|
65
|
-
|
|
52
|
+
if (rowNumber === 1) {
|
|
53
|
+
cell.font = { bold: true };
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
66
57
|
}
|
|
67
58
|
|
|
59
|
+
|
|
68
60
|
module.exports = ({ strapi }) => ({
|
|
69
61
|
async exportData(format = "json", contentType = null, rawFilters = {}, mode = '') {
|
|
70
62
|
// Normalize content type - handle both content-manager and event-manager formats
|
|
@@ -300,7 +292,7 @@ module.exports = ({ strapi }) => ({
|
|
|
300
292
|
},
|
|
301
293
|
|
|
302
294
|
convertToExcel(data) {
|
|
303
|
-
const workbook =
|
|
295
|
+
const workbook = new ExcelJS.Workbook();
|
|
304
296
|
let hasData = false;
|
|
305
297
|
|
|
306
298
|
const SYSTEM_KEYS = [
|
|
@@ -455,43 +447,40 @@ module.exports = ({ strapi }) => ({
|
|
|
455
447
|
const cleanedFlat = cleanedEntries.map((entry) =>
|
|
456
448
|
flattenForXLSX(entry)
|
|
457
449
|
);
|
|
458
|
-
const worksheet =
|
|
450
|
+
const worksheet = workbook.addWorksheet(sheetName);
|
|
459
451
|
styleWorksheetUniform(worksheet, cleanedFlat, {
|
|
460
452
|
colWidth: 30,
|
|
461
453
|
});
|
|
462
|
-
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
463
454
|
} else {
|
|
464
455
|
// Create empty sheet with headers if no data
|
|
465
|
-
const worksheet =
|
|
466
|
-
|
|
467
|
-
]);
|
|
468
|
-
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
456
|
+
const worksheet = workbook.addWorksheet(sheetName);
|
|
457
|
+
worksheet.addRow(['No data found']);
|
|
469
458
|
hasData = true; // Prevent empty workbook error
|
|
470
459
|
}
|
|
471
460
|
}
|
|
472
461
|
|
|
473
462
|
// If still no data, create a default sheet
|
|
474
463
|
if (!hasData) {
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
]);
|
|
478
|
-
XLSX.utils.book_append_sheet(workbook, worksheet, "NoData");
|
|
464
|
+
const ws = workbook.addWorksheet('NoData');
|
|
465
|
+
ws.addRow(['No data to export']);
|
|
479
466
|
}
|
|
480
467
|
|
|
481
|
-
return
|
|
468
|
+
return workbook.xlsx.writeBuffer();
|
|
482
469
|
},
|
|
483
470
|
|
|
484
|
-
convertExperienceParticipantsToExcel(experienceData) {
|
|
485
|
-
const workbook =
|
|
486
|
-
|
|
471
|
+
async convertExperienceParticipantsToExcel(experienceData) {
|
|
472
|
+
const workbook = new ExcelJS.Workbook();
|
|
473
|
+
const worksheet = workbook.addWorksheet('Participants List');
|
|
474
|
+
|
|
487
475
|
const tag = (list, type) =>
|
|
488
476
|
(list ?? []).map(item => ({ ...item, type }));
|
|
477
|
+
|
|
489
478
|
const participants = [
|
|
490
479
|
...tag(experienceData?.corporates, 'corporate'),
|
|
491
480
|
...tag(experienceData?.investors, 'investor'),
|
|
492
481
|
...tag(experienceData?.vipGuests, 'vipGuest'),
|
|
493
482
|
];
|
|
494
|
-
|
|
483
|
+
|
|
495
484
|
const data = participants.map((p) => ({
|
|
496
485
|
type: p.type,
|
|
497
486
|
corporateName: p.corporateName ?? '',
|
|
@@ -506,22 +495,13 @@ module.exports = ({ strapi }) => ({
|
|
|
506
495
|
companyName: p.companyInformation?.companyName ?? '',
|
|
507
496
|
mobile: p.mobile ?? '',
|
|
508
497
|
}));
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
styleWorksheetUniform(worksheet, data, {
|
|
498
|
+
|
|
499
|
+
styleWorksheetUniformExcelJS(worksheet, data, {
|
|
512
500
|
colWidth: 30,
|
|
513
501
|
});
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
'Participants List'
|
|
518
|
-
);
|
|
519
|
-
|
|
520
|
-
return XLSX.write(workbook, {
|
|
521
|
-
type: 'buffer',
|
|
522
|
-
bookType: 'xlsx',
|
|
523
|
-
});
|
|
524
|
-
},
|
|
502
|
+
|
|
503
|
+
return workbook.xlsx.writeBuffer();
|
|
504
|
+
},
|
|
525
505
|
|
|
526
506
|
async exportSingleEntry(contentType, entryId) {
|
|
527
507
|
try {
|