@nkhang1902/strapi-plugin-export-import-clsx 1.6.2 → 1.6.4

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.2",
3
+ "version": "1.6.4",
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,7 +41,8 @@
41
41
  "@strapi/strapi": "^4.0.0 || ^5.0.0"
42
42
  },
43
43
  "dependencies": {
44
- "xlsx": "^0.18.5"
44
+ "xlsx": "^0.18.5",
45
+ "xlsx-style": "^0.8.13"
45
46
  },
46
47
  "files": [
47
48
  "admin/",
@@ -1,12 +1,10 @@
1
- const XLSX = require("xlsx");
1
+ const XLSX = require("xlsx-style");
2
2
 
3
- function styleWorksheet(worksheet, data, options = {}) {
3
+ function styleWorksheetUniform(worksheet, data, options = {}) {
4
4
  const {
5
- headerHeight = 24,
6
- rowHeight = 18,
7
- minColWidth = 15,
8
- headerColWidthPadding = 2,
9
- headerAlign = 'center',
5
+ colWidth = 25, // fixed width for all columns
6
+ baseRowHeight = 18, // height for 1 line
7
+ lineHeight = 15, // height per extra line
10
8
  } = options;
11
9
 
12
10
  if (!data?.length) return worksheet;
@@ -14,31 +12,45 @@ function styleWorksheet(worksheet, data, options = {}) {
14
12
  const headers = Object.keys(data[0]);
15
13
  const range = XLSX.utils.decode_range(worksheet['!ref']);
16
14
 
17
- // column widths
18
- worksheet['!cols'] = headers.map((h) => ({
19
- wch: Math.max(h.length + headerColWidthPadding, minColWidth),
20
- }));
15
+ /* ---------------- Column widths ---------------- */
16
+ worksheet['!cols'] = headers.map(() => ({ wch: colWidth }));
21
17
 
22
- // row heights
23
- worksheet['!rows'] = [
24
- { hpt: headerHeight },
25
- ...Array(range.e.r).fill({ hpt: rowHeight }),
26
- ];
18
+ /* ---------------- Find max line count ---------------- */
19
+ let maxLines = 1;
27
20
 
28
- // styles (header + borders)
29
21
  for (let r = range.s.r; r <= range.e.r; r++) {
30
22
  for (let c = range.s.c; c <= range.e.c; c++) {
31
- const cellAddress = XLSX.utils.encode_cell({ r, c });
32
- const cell = worksheet[cellAddress];
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;
27
+ maxLines = Math.max(maxLines, lines);
28
+ }
29
+ }
30
+
31
+ /* ---------------- Uniform row height ---------------- */
32
+ const uniformHeight =
33
+ baseRowHeight + (maxLines - 1) * lineHeight;
34
+
35
+ worksheet['!rows'] = Array(range.e.r + 1).fill({
36
+ hpt: uniformHeight,
37
+ });
38
+
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];
33
44
  if (!cell) continue;
34
45
 
35
46
  const isHeader = r === 0;
36
47
 
37
48
  cell.s = {
38
- font: isHeader ? { bold: true } : undefined,
49
+ font: isHeader ? { bold: true } : {},
39
50
  alignment: {
51
+ wrapText: true,
40
52
  vertical: 'center',
41
- horizontal: isHeader ? headerAlign : 'left',
53
+ horizontal: 'left',
42
54
  },
43
55
  border: {
44
56
  top: { style: 'thin' },
@@ -444,7 +456,9 @@ module.exports = ({ strapi }) => ({
444
456
  flattenForXLSX(entry)
445
457
  );
446
458
  const worksheet = XLSX.utils.json_to_sheet(cleanedFlat);
447
- styleWorksheet(worksheet, cleanedFlat);
459
+ styleWorksheetUniform(worksheet, cleanedFlat, {
460
+ colWidth: 30,
461
+ });
448
462
  XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
449
463
  } else {
450
464
  // Create empty sheet with headers if no data
@@ -494,7 +508,9 @@ module.exports = ({ strapi }) => ({
494
508
  }));
495
509
 
496
510
  const worksheet = XLSX.utils.json_to_sheet(data);
497
- styleWorksheet(worksheet, data);
511
+ styleWorksheetUniform(worksheet, data, {
512
+ colWidth: 30,
513
+ });
498
514
  XLSX.utils.book_append_sheet(
499
515
  workbook,
500
516
  worksheet,