@nkhang1902/strapi-plugin-export-import-clsx 1.6.6 → 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.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
- "xlsx": "^0.18.5",
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 XLSX = require('xlsx-style');
1
+ const ExcelJS = require('exceljs');
2
2
 
3
- function styleWorksheetUniform(worksheet, data, options = {}) {
3
+ function styleWorksheetUniformExcelJS(worksheet, data, options = {}) {
4
4
  const {
5
- colWidth = 25, // fixed width for all columns
6
- baseRowHeight = 18, // height for 1 line
7
- lineHeight = 15, // height per extra line
5
+ colWidth = 30,
6
+ baseRowHeight = 20,
7
+ lineHeight = 15,
8
8
  } = options;
9
9
 
10
- if (!data?.length) return worksheet;
10
+ if (!data?.length) return;
11
11
 
12
- const headers = Object.keys(data[0]);
13
- const range = XLSX.utils.decode_range(worksheet['!ref']);
12
+ // Set columns
13
+ worksheet.columns = Object.keys(data[0]).map(key => ({
14
+ header: key,
15
+ key,
16
+ width: colWidth,
17
+ }));
14
18
 
15
- /* ---------------- Column widths ---------------- */
16
- worksheet['!cols'] = headers.map(() => ({ wch: colWidth }));
19
+ worksheet.addRows(data);
17
20
 
18
- /* ---------------- Find max line count ---------------- */
21
+ // Calculate max manual line count
19
22
  let maxLines = 1;
20
-
21
- for (let r = range.s.r; r <= range.e.r; r++) {
22
- for (let c = range.s.c; c <= range.e.c; c++) {
23
- const cell = worksheet[XLSX.utils.encode_cell({ r, c })];
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
- baseRowHeight + lineHeight;
32
+ baseRowHeight + (maxLines - 1) * lineHeight;
34
33
 
35
- worksheet['!rows'] = Array(range.e.r + 1).fill({
36
- hpt: uniformHeight,
37
- });
34
+ // Apply styles
35
+ worksheet.eachRow((row, rowNumber) => {
36
+ row.height = uniformHeight;
38
37
 
39
- /* ---------------- Apply styles ---------------- */
40
- for (let r = range.s.r; r <= range.e.r; r++) {
41
- for (let c = range.s.c; c <= range.e.c; c++) {
42
- const addr = XLSX.utils.encode_cell({ r, c });
43
- const cell = worksheet[addr];
44
- if (!cell) continue;
45
-
46
- const isHeader = r === 0;
47
-
48
- cell.s = {
49
- font: isHeader ? { bold: true } : {},
50
- alignment: {
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
- return worksheet;
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 = XLSX.utils.book_new();
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 = XLSX.utils.json_to_sheet(cleanedFlat);
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 = XLSX.utils.json_to_sheet([
466
- { message: "No data found" },
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 worksheet = XLSX.utils.json_to_sheet([
476
- { message: "No data to export" },
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 XLSX.write(workbook, { type: "buffer", bookType: "xlsx" });
468
+ return workbook.xlsx.writeBuffer();
482
469
  },
483
470
 
484
- convertExperienceParticipantsToExcel(experienceData) {
485
- const workbook = XLSX.utils.book_new();
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
- const worksheet = XLSX.utils.json_to_sheet(data);
511
- styleWorksheetUniform(worksheet, data, {
498
+
499
+ styleWorksheetUniformExcelJS(worksheet, data, {
512
500
  colWidth: 30,
513
501
  });
514
- XLSX.utils.book_append_sheet(
515
- workbook,
516
- worksheet,
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 {