@corbe30/fortune-excel 2.1.1 → 2.2.2
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/.github/workflows/publish.yml +0 -1
- package/README.md +16 -0
- package/dist/ToExcel/ExcelFile.d.ts +1 -1
- package/dist/ToExcel/ExcelFile.js +5 -3
- package/dist/ToExcel/ExportHelper.d.ts +9 -2
- package/dist/ToExcel/ExportHelper.js +34 -5
- package/dist/common/Transform.d.ts +1 -1
- package/dist/common/Transform.js +15 -9
- package/dist/main.d.ts +1 -0
- package/dist/main.js +1 -0
- package/package.json +1 -6
- package/dist/ToExcel/style.css +0 -33
package/README.md
CHANGED
|
@@ -53,6 +53,22 @@ You can check the example in [Storybook](https://github.com/Corbe30/FortuneExcel
|
|
|
53
53
|
}
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
3. You can programmatically import/export as well:
|
|
57
|
+
```js
|
|
58
|
+
import { transformFortuneToExcel } from "@corbe30/fortune-excel";
|
|
59
|
+
|
|
60
|
+
const manualExport = async () => {
|
|
61
|
+
const exportedFile = await transformFortuneToExcel(
|
|
62
|
+
sheetRef.current,
|
|
63
|
+
"xlsx", // or "csv"; default = "xlsx"
|
|
64
|
+
true // if you want to start automatic download; default = true
|
|
65
|
+
);
|
|
66
|
+
console.log("Exported file data:", exportedFile);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
<button onClick={manualExport}>Try Manual Export!</button>
|
|
70
|
+
```
|
|
71
|
+
|
|
56
72
|
## Authors and acknowledgment
|
|
57
73
|
|
|
58
74
|
- [@Corbe30](https://github.com/Corbe30)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IFileType } from "../common/ICommon";
|
|
2
|
-
export declare function exportSheetExcel(luckysheetRef: any, fileType: IFileType): Promise<
|
|
2
|
+
export declare function exportSheetExcel(luckysheetRef: any, fileType: IFileType, download?: boolean): Promise<Blob>;
|
|
@@ -72,7 +72,8 @@ var ExcelBorder_1 = require("./ExcelBorder");
|
|
|
72
72
|
var ExcelValidation_1 = require("./ExcelValidation");
|
|
73
73
|
var ExcelConfig_1 = require("./ExcelConfig");
|
|
74
74
|
var ICommon_1 = require("../common/ICommon");
|
|
75
|
-
function exportSheetExcel(luckysheetRef, fileType) {
|
|
75
|
+
function exportSheetExcel(luckysheetRef, fileType, download) {
|
|
76
|
+
if (download === void 0) { download = true; }
|
|
76
77
|
return __awaiter(this, void 0, void 0, function () {
|
|
77
78
|
var luckysheet, workbook, fileData, buffer, buffer;
|
|
78
79
|
return __generator(this, function (_a) {
|
|
@@ -105,8 +106,9 @@ function exportSheetExcel(luckysheetRef, fileType) {
|
|
|
105
106
|
fileData = new Blob([buffer]);
|
|
106
107
|
_a.label = 4;
|
|
107
108
|
case 4:
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
if (download)
|
|
110
|
+
fileSaver.saveAs(fileData, "".concat(luckysheetRef.getSheet().name, ".").concat(fileType));
|
|
111
|
+
return [2 /*return*/, fileData];
|
|
110
112
|
}
|
|
111
113
|
});
|
|
112
114
|
});
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
interface ExportHelperProps {
|
|
3
|
+
sheetRef: React.RefObject<any>;
|
|
4
|
+
config: {
|
|
5
|
+
xlsx?: boolean;
|
|
6
|
+
csv?: boolean;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare const ExportHelper: React.FC<ExportHelperProps>;
|
|
10
|
+
export {};
|
|
@@ -5,11 +5,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ExportHelper = void 0;
|
|
7
7
|
var react_1 = __importDefault(require("react"));
|
|
8
|
-
require("./style.css");
|
|
9
8
|
var Transform_1 = require("../common/Transform");
|
|
10
9
|
var ICommon_1 = require("../common/ICommon");
|
|
10
|
+
var exportHelperStyle = {
|
|
11
|
+
display: "flex",
|
|
12
|
+
flexDirection: "column",
|
|
13
|
+
visibility: "hidden",
|
|
14
|
+
backgroundColor: "#fff",
|
|
15
|
+
color: "#000",
|
|
16
|
+
textAlign: "start",
|
|
17
|
+
borderRadius: "4px",
|
|
18
|
+
fontSize: "12px",
|
|
19
|
+
position: "absolute",
|
|
20
|
+
zIndex: 26,
|
|
21
|
+
top: "40px",
|
|
22
|
+
whiteSpace: "nowrap",
|
|
23
|
+
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.35)",
|
|
24
|
+
left: "50px",
|
|
25
|
+
};
|
|
26
|
+
var unstyledButtonStyle = {
|
|
27
|
+
width: "100%",
|
|
28
|
+
background: "none",
|
|
29
|
+
border: "none",
|
|
30
|
+
margin: 0,
|
|
31
|
+
font: "inherit",
|
|
32
|
+
color: "inherit",
|
|
33
|
+
cursor: "pointer",
|
|
34
|
+
padding: "6px 12px",
|
|
35
|
+
outline: "none",
|
|
36
|
+
fontFamily: "Arial, Helvetica, sans-serif",
|
|
37
|
+
textAlign: "left",
|
|
38
|
+
};
|
|
11
39
|
var getExportButton = function (fileType, onClick) {
|
|
12
|
-
return (react_1.default.createElement("button", {
|
|
40
|
+
return (react_1.default.createElement("button", { style: unstyledButtonStyle, onMouseEnter: function (e) { return (e.currentTarget.style.backgroundColor = "#ededed"); }, onMouseLeave: function (e) { return (e.currentTarget.style.backgroundColor = "#fff"); }, onClick: function () { return onClick(fileType); } },
|
|
13
41
|
"Export as .",
|
|
14
42
|
fileType.toLowerCase()));
|
|
15
43
|
};
|
|
@@ -17,13 +45,14 @@ var ExportHelper = function (props) {
|
|
|
17
45
|
var sheetRef = props.sheetRef, config = props.config;
|
|
18
46
|
var onMouseLeave = function () {
|
|
19
47
|
var exportHelper = document.querySelector(".export-helper");
|
|
20
|
-
exportHelper
|
|
48
|
+
if (exportHelper)
|
|
49
|
+
exportHelper.style.visibility = "hidden";
|
|
21
50
|
};
|
|
22
51
|
var onClick = function (fileType) {
|
|
23
|
-
(0, Transform_1.transformFortuneToExcel)(sheetRef.current, fileType);
|
|
52
|
+
(0, Transform_1.transformFortuneToExcel)(sheetRef.current, fileType, true);
|
|
24
53
|
onMouseLeave();
|
|
25
54
|
};
|
|
26
|
-
return (react_1.default.createElement("div", { className: "export-helper", onMouseLeave: onMouseLeave },
|
|
55
|
+
return (react_1.default.createElement("div", { className: "export-helper", style: exportHelperStyle, onMouseLeave: onMouseLeave },
|
|
27
56
|
config.xlsx ? getExportButton(ICommon_1.IFileType.XLSX, onClick) : null,
|
|
28
57
|
config.csv ? getExportButton(ICommon_1.IFileType.CSV, onClick) : null));
|
|
29
58
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IFileType } from "./ICommon";
|
|
2
2
|
export declare const transformExcelToFortune: (e: any, setSheets: any, setKey: any, sheetRef: any) => Promise<void>;
|
|
3
|
-
export declare const transformFortuneToExcel: (luckysheetRef: any, fileType
|
|
3
|
+
export declare const transformFortuneToExcel: (luckysheetRef: any, fileType?: IFileType, download?: boolean) => Promise<Blob>;
|
package/dist/common/Transform.js
CHANGED
|
@@ -63,6 +63,7 @@ exports.transformFortuneToExcel = exports.transformExcelToFortune = void 0;
|
|
|
63
63
|
var FortuneFile_1 = require("../ToFortuneSheet/FortuneFile");
|
|
64
64
|
var HandleZip_1 = require("../ToFortuneSheet/HandleZip");
|
|
65
65
|
var ExcelFile_1 = require("../ToExcel/ExcelFile");
|
|
66
|
+
var ICommon_1 = require("./ICommon");
|
|
66
67
|
var ExcelJS = __importStar(require("exceljs"));
|
|
67
68
|
var convertCsvToExcel = function (file) { return __awaiter(void 0, void 0, void 0, function () {
|
|
68
69
|
var csvText, rows, workbook, worksheet, buffer;
|
|
@@ -125,14 +126,19 @@ var transformExcelToFortune = function (e, setSheets, setKey, sheetRef) { return
|
|
|
125
126
|
});
|
|
126
127
|
}); };
|
|
127
128
|
exports.transformExcelToFortune = transformExcelToFortune;
|
|
128
|
-
var transformFortuneToExcel = function (luckysheetRef, fileType
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
129
|
+
var transformFortuneToExcel = function (luckysheetRef, fileType, download) {
|
|
130
|
+
if (fileType === void 0) { fileType = ICommon_1.IFileType.XLSX; }
|
|
131
|
+
if (download === void 0) { download = true; }
|
|
132
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
133
|
+
var result;
|
|
134
|
+
return __generator(this, function (_a) {
|
|
135
|
+
switch (_a.label) {
|
|
136
|
+
case 0: return [4 /*yield*/, (0, ExcelFile_1.exportSheetExcel)(luckysheetRef, fileType, download)];
|
|
137
|
+
case 1:
|
|
138
|
+
result = _a.sent();
|
|
139
|
+
return [2 /*return*/, result];
|
|
140
|
+
}
|
|
141
|
+
});
|
|
136
142
|
});
|
|
137
|
-
}
|
|
143
|
+
};
|
|
138
144
|
exports.transformFortuneToExcel = transformFortuneToExcel;
|
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./common/ToolbarItem"), exports);
|
|
18
18
|
__exportStar(require("./common/FortuneExcelHelper"), exports);
|
|
19
|
+
__exportStar(require("./common/Transform"), exports);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"workspaces": [
|
|
4
4
|
"src/*"
|
|
5
5
|
],
|
|
6
|
-
"version": "2.
|
|
6
|
+
"version": "2.2.2",
|
|
7
7
|
"description": "An Excel import/export import library for FortuneSheet",
|
|
8
8
|
"main": "dist/main.js",
|
|
9
9
|
"types": "dist/main.d.ts",
|
|
@@ -32,10 +32,8 @@
|
|
|
32
32
|
"@storybook/react-webpack5": "^7.3.2",
|
|
33
33
|
"@storybook/test": "^7.6.12",
|
|
34
34
|
"@types/node": "^20.11.16",
|
|
35
|
-
"copyfiles": "^2.4.1",
|
|
36
35
|
"react": "^18.2.0",
|
|
37
36
|
"react-dom": "^18.2.0",
|
|
38
|
-
"rimraf": "^6.1.0",
|
|
39
37
|
"storybook": "^7.6.16",
|
|
40
38
|
"tsconfig-paths-webpack-plugin": "^4.0.0",
|
|
41
39
|
"typescript": "^5.3.3"
|
|
@@ -49,9 +47,6 @@
|
|
|
49
47
|
},
|
|
50
48
|
"scripts": {
|
|
51
49
|
"prepare": "tsc",
|
|
52
|
-
"clean": "rimraf dist/",
|
|
53
|
-
"copy-files": "copyfiles -u 1 src/**/*.html src/**/*.css dist/",
|
|
54
|
-
"build": "npm run clean && tsc && npm run copy-files",
|
|
55
50
|
"storybook": "storybook dev -p 6006",
|
|
56
51
|
"build-storybook": "storybook build"
|
|
57
52
|
}
|
package/dist/ToExcel/style.css
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
.export-helper {
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-direction: column;
|
|
4
|
-
visibility: hidden;
|
|
5
|
-
background-color: #fff;
|
|
6
|
-
color: #000;
|
|
7
|
-
text-align: start;
|
|
8
|
-
border-radius: 4px;
|
|
9
|
-
font-size: 12px;
|
|
10
|
-
position: absolute;
|
|
11
|
-
z-index: 26;
|
|
12
|
-
top: 40px;
|
|
13
|
-
white-space: nowrap;
|
|
14
|
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
|
|
15
|
-
left: 50px;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.unstyled-button {
|
|
19
|
-
width: 100%;
|
|
20
|
-
background: none;
|
|
21
|
-
border: none;
|
|
22
|
-
margin: 0;
|
|
23
|
-
font: inherit;
|
|
24
|
-
color: inherit;
|
|
25
|
-
cursor: pointer;
|
|
26
|
-
padding: 6px 12px 6px 12px;
|
|
27
|
-
outline: none;
|
|
28
|
-
font-family: Arial, Helvetica, sans-serif;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.unstyled-button:hover {
|
|
32
|
-
background-color: #ededed;
|
|
33
|
-
}
|