josenanodev-react-components-library 0.1.2 → 0.1.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/dist/cjs/components/ExportToExcelButton/ExportToExcelButtonOwnFunctions.js +14 -14
- package/dist/cjs/components/ExportToExcelButton/types.d.ts +2 -2
- package/dist/esm/components/ExportToExcelButton/ExportToExcelButtonOwnFunctions.js +14 -14
- package/dist/esm/components/ExportToExcelButton/types.d.ts +2 -2
- package/package.json +1 -1
|
@@ -27,45 +27,45 @@ exports.downloadExcel = void 0;
|
|
|
27
27
|
//Librerias de terceros
|
|
28
28
|
const XLSX = __importStar(require("xlsx-js-style"));
|
|
29
29
|
function styleObjectParser(styleObject) {
|
|
30
|
-
let
|
|
30
|
+
let restultantStyleObject = {
|
|
31
31
|
v: styleObject.value,
|
|
32
32
|
s: {},
|
|
33
33
|
};
|
|
34
34
|
if (styleObject.allign)
|
|
35
|
-
|
|
35
|
+
restultantStyleObject.s.alignment = Object.assign({}, styleObject.allign);
|
|
36
36
|
if (styleObject.fontSize)
|
|
37
|
-
|
|
37
|
+
restultantStyleObject.s.font = Object.assign(Object.assign({}, restultantStyleObject.s.font), { sz: styleObject.fontSize });
|
|
38
38
|
if (styleObject.fontColor)
|
|
39
|
-
|
|
39
|
+
restultantStyleObject.s.font = Object.assign(Object.assign({}, restultantStyleObject.s.font), { color: { rgb: styleObject.fontColor } });
|
|
40
40
|
if (styleObject.bold)
|
|
41
|
-
|
|
41
|
+
restultantStyleObject.s.font = Object.assign(Object.assign({}, restultantStyleObject.s.font), { bold: styleObject.bold });
|
|
42
42
|
if (styleObject.backgroundColor)
|
|
43
|
-
|
|
43
|
+
restultantStyleObject.s.fill = Object.assign(Object.assign({}, restultantStyleObject.s.fill), { fgColor: { rgb: styleObject.backgroundColor } });
|
|
44
44
|
if (styleObject.borders)
|
|
45
|
-
|
|
45
|
+
restultantStyleObject.s.border = {
|
|
46
46
|
bgColor: styleObject.borders,
|
|
47
47
|
};
|
|
48
|
-
return
|
|
48
|
+
return restultantStyleObject;
|
|
49
49
|
}
|
|
50
50
|
function downloadExcel(fileName, data, headers) {
|
|
51
51
|
if (data !== undefined) {
|
|
52
52
|
const wb = XLSX.utils.book_new();
|
|
53
|
-
for (const
|
|
54
|
-
if (Object.prototype.hasOwnProperty.call(data,
|
|
53
|
+
for (const sheetName in data) {
|
|
54
|
+
if (Object.prototype.hasOwnProperty.call(data, sheetName)) {
|
|
55
55
|
let dataXlsxJs = [];
|
|
56
56
|
if (headers !== undefined) {
|
|
57
57
|
dataXlsxJs = [
|
|
58
|
-
headers[
|
|
59
|
-
...data[
|
|
58
|
+
headers[sheetName].map((header) => styleObjectParser(header)),
|
|
59
|
+
...data[sheetName].map((row) => row.map((cell) => styleObjectParser(cell))),
|
|
60
60
|
];
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
63
|
dataXlsxJs = [
|
|
64
|
-
...data[
|
|
64
|
+
...data[sheetName].map((row) => row.map((cell) => styleObjectParser(cell))),
|
|
65
65
|
];
|
|
66
66
|
}
|
|
67
67
|
const ws = XLSX.utils.aoa_to_sheet(dataXlsxJs);
|
|
68
|
-
XLSX.utils.book_append_sheet(wb, ws,
|
|
68
|
+
XLSX.utils.book_append_sheet(wb, ws, sheetName);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
XLSX.writeFile(wb, `${fileName}.xlsx`);
|
|
@@ -2,8 +2,8 @@ export interface ExportToExcelButtonPropsType {
|
|
|
2
2
|
customButtonText?: string;
|
|
3
3
|
customClass?: string;
|
|
4
4
|
fileName?: string;
|
|
5
|
-
headers?: { [key: string]:
|
|
6
|
-
data?: { [key: string]:
|
|
5
|
+
headers?: { [key: string]: DataObjectXlsxType[] };
|
|
6
|
+
data?: { [key: string]: DataObjectXlsxType[][] };
|
|
7
7
|
onAfterExport?: Function;
|
|
8
8
|
disabled?: boolean;
|
|
9
9
|
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
//Librerias de terceros
|
|
2
2
|
import * as XLSX from "xlsx-js-style";
|
|
3
3
|
function styleObjectParser(styleObject) {
|
|
4
|
-
let
|
|
4
|
+
let restultantStyleObject = {
|
|
5
5
|
v: styleObject.value,
|
|
6
6
|
s: {},
|
|
7
7
|
};
|
|
8
8
|
if (styleObject.allign)
|
|
9
|
-
|
|
9
|
+
restultantStyleObject.s.alignment = Object.assign({}, styleObject.allign);
|
|
10
10
|
if (styleObject.fontSize)
|
|
11
|
-
|
|
11
|
+
restultantStyleObject.s.font = Object.assign(Object.assign({}, restultantStyleObject.s.font), { sz: styleObject.fontSize });
|
|
12
12
|
if (styleObject.fontColor)
|
|
13
|
-
|
|
13
|
+
restultantStyleObject.s.font = Object.assign(Object.assign({}, restultantStyleObject.s.font), { color: { rgb: styleObject.fontColor } });
|
|
14
14
|
if (styleObject.bold)
|
|
15
|
-
|
|
15
|
+
restultantStyleObject.s.font = Object.assign(Object.assign({}, restultantStyleObject.s.font), { bold: styleObject.bold });
|
|
16
16
|
if (styleObject.backgroundColor)
|
|
17
|
-
|
|
17
|
+
restultantStyleObject.s.fill = Object.assign(Object.assign({}, restultantStyleObject.s.fill), { fgColor: { rgb: styleObject.backgroundColor } });
|
|
18
18
|
if (styleObject.borders)
|
|
19
|
-
|
|
19
|
+
restultantStyleObject.s.border = {
|
|
20
20
|
bgColor: styleObject.borders,
|
|
21
21
|
};
|
|
22
|
-
return
|
|
22
|
+
return restultantStyleObject;
|
|
23
23
|
}
|
|
24
24
|
export function downloadExcel(fileName, data, headers) {
|
|
25
25
|
if (data !== undefined) {
|
|
26
26
|
const wb = XLSX.utils.book_new();
|
|
27
|
-
for (const
|
|
28
|
-
if (Object.prototype.hasOwnProperty.call(data,
|
|
27
|
+
for (const sheetName in data) {
|
|
28
|
+
if (Object.prototype.hasOwnProperty.call(data, sheetName)) {
|
|
29
29
|
let dataXlsxJs = [];
|
|
30
30
|
if (headers !== undefined) {
|
|
31
31
|
dataXlsxJs = [
|
|
32
|
-
headers[
|
|
33
|
-
...data[
|
|
32
|
+
headers[sheetName].map((header) => styleObjectParser(header)),
|
|
33
|
+
...data[sheetName].map((row) => row.map((cell) => styleObjectParser(cell))),
|
|
34
34
|
];
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
37
|
dataXlsxJs = [
|
|
38
|
-
...data[
|
|
38
|
+
...data[sheetName].map((row) => row.map((cell) => styleObjectParser(cell))),
|
|
39
39
|
];
|
|
40
40
|
}
|
|
41
41
|
const ws = XLSX.utils.aoa_to_sheet(dataXlsxJs);
|
|
42
|
-
XLSX.utils.book_append_sheet(wb, ws,
|
|
42
|
+
XLSX.utils.book_append_sheet(wb, ws, sheetName);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
XLSX.writeFile(wb, `${fileName}.xlsx`);
|
|
@@ -2,8 +2,8 @@ export interface ExportToExcelButtonPropsType {
|
|
|
2
2
|
customButtonText?: string;
|
|
3
3
|
customClass?: string;
|
|
4
4
|
fileName?: string;
|
|
5
|
-
headers?: { [key: string]:
|
|
6
|
-
data?: { [key: string]:
|
|
5
|
+
headers?: { [key: string]: DataObjectXlsxType[] };
|
|
6
|
+
data?: { [key: string]: DataObjectXlsxType[][] };
|
|
7
7
|
onAfterExport?: Function;
|
|
8
8
|
disabled?: boolean;
|
|
9
9
|
}
|