@nkhang1902/strapi-plugin-export-import-clsx 1.6.1 → 1.6.3
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.
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useState
|
|
1
|
+
import { useState } from "react";
|
|
2
2
|
import {
|
|
3
3
|
Button,
|
|
4
4
|
} from "@strapi/design-system";
|
|
5
|
-
import { Download
|
|
5
|
+
import { Download } from "@strapi/icons";
|
|
6
6
|
import { useNotification } from "@strapi/strapi/admin";
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const ExportParticipantListButton = (props) => {
|
|
9
9
|
const [isExporting, setIsExporting] = useState(false);
|
|
10
10
|
const { toggleNotification } = useNotification();
|
|
11
11
|
const allowedContentTypes = [
|
|
@@ -136,4 +136,4 @@ const ExportButtonsEditView = (props) => {
|
|
|
136
136
|
);
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
-
export default
|
|
139
|
+
export default ExportParticipantListButton;
|
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.3",
|
|
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.21"
|
|
45
46
|
},
|
|
46
47
|
"files": [
|
|
47
48
|
"admin/",
|
|
@@ -1,4 +1,69 @@
|
|
|
1
|
-
const XLSX = require("xlsx");
|
|
1
|
+
const XLSX = require("xlsx-style");
|
|
2
|
+
|
|
3
|
+
function styleWorksheetUniform(worksheet, data, options = {}) {
|
|
4
|
+
const {
|
|
5
|
+
colWidth = 25, // fixed width for all columns
|
|
6
|
+
baseRowHeight = 18, // height for 1 line
|
|
7
|
+
lineHeight = 15, // height per extra line
|
|
8
|
+
} = options;
|
|
9
|
+
|
|
10
|
+
if (!data?.length) return worksheet;
|
|
11
|
+
|
|
12
|
+
const headers = Object.keys(data[0]);
|
|
13
|
+
const range = XLSX.utils.decode_range(worksheet['!ref']);
|
|
14
|
+
|
|
15
|
+
/* ---------------- Column widths ---------------- */
|
|
16
|
+
worksheet['!cols'] = headers.map(() => ({ wch: colWidth }));
|
|
17
|
+
|
|
18
|
+
/* ---------------- Find max line count ---------------- */
|
|
19
|
+
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;
|
|
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];
|
|
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
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return worksheet;
|
|
66
|
+
}
|
|
2
67
|
|
|
3
68
|
module.exports = ({ strapi }) => ({
|
|
4
69
|
async exportData(format = "json", contentType = null, rawFilters = {}, mode = '') {
|
|
@@ -391,6 +456,9 @@ module.exports = ({ strapi }) => ({
|
|
|
391
456
|
flattenForXLSX(entry)
|
|
392
457
|
);
|
|
393
458
|
const worksheet = XLSX.utils.json_to_sheet(cleanedFlat);
|
|
459
|
+
styleWorksheetUniform(worksheet, cleanedFlat, {
|
|
460
|
+
colWidth: 30,
|
|
461
|
+
});
|
|
394
462
|
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
395
463
|
} else {
|
|
396
464
|
// Create empty sheet with headers if no data
|
|
@@ -440,6 +508,9 @@ module.exports = ({ strapi }) => ({
|
|
|
440
508
|
}));
|
|
441
509
|
|
|
442
510
|
const worksheet = XLSX.utils.json_to_sheet(data);
|
|
511
|
+
styleWorksheetUniform(worksheet, data, {
|
|
512
|
+
colWidth: 30,
|
|
513
|
+
});
|
|
443
514
|
XLSX.utils.book_append_sheet(
|
|
444
515
|
workbook,
|
|
445
516
|
worksheet,
|