@corbe30/fortune-excel 2.2.4 → 2.2.5
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/README.md
CHANGED
|
@@ -7,29 +7,33 @@
|
|
|
7
7
|
<div align="center">
|
|
8
8
|
|
|
9
9
|
<p>
|
|
10
|
-
<a href="http://npmjs.com/package/@corbe30/fortune-excel" alt="fortuneExcel on npm">
|
|
11
|
-
<img src="https://img.shields.io/npm/v/@corbe30/fortune-excel"
|
|
12
|
-
|
|
10
|
+
<a href="http://npmjs.com/package/@corbe30/fortune-excel" alt="fortuneExcel on npm">
|
|
11
|
+
<img src="https://img.shields.io/npm/v/@corbe30/fortune-excel" />
|
|
12
|
+
</a>
|
|
13
|
+
<a href="http://npmjs.com/package/@corbe30/fortune-excel" alt="fortuneExcel downloads">
|
|
14
|
+
<img src="https://img.shields.io/npm/d18m/%40corbe30%2Ffortune-excel" />
|
|
15
|
+
</a>
|
|
16
|
+
<a href="https://corbe30.github.io/FortuneExcel/" alt="fortuneExcel storybok">
|
|
17
|
+
<img src="https://img.shields.io/badge/storybook-FF4785" />
|
|
18
|
+
</a>
|
|
13
19
|
</p>
|
|
14
20
|
|
|
15
21
|
</div>
|
|
16
22
|
|
|
17
23
|
## Usage
|
|
18
24
|
|
|
19
|
-
You can check the example in [Storybook](https://github.com/Corbe30/FortuneExcel/blob/main/src/stories/Page.tsx).
|
|
20
|
-
|
|
21
25
|
1. Install the package:
|
|
22
26
|
```js
|
|
23
27
|
npm i @corbe30/fortune-excel
|
|
24
28
|
```
|
|
25
29
|
|
|
26
|
-
2.
|
|
27
|
-
> `<FortuneExcelHelper />` is a hidden component.
|
|
30
|
+
2. Import/export toolbar item ([code example](https://github.com/Corbe30/FortuneExcel/tree/main/src/stories/Plugin.tsx))
|
|
31
|
+
> Note: `<FortuneExcelHelper />` is a hidden component.
|
|
28
32
|
```js
|
|
29
33
|
import { FortuneExcelHelper, importToolBarItem, exportToolBarItem } from "@corbe30/fortune-excel";
|
|
30
34
|
|
|
31
35
|
function App() {
|
|
32
|
-
const
|
|
36
|
+
const sheetRef = useRef();
|
|
33
37
|
const [key, setKey] = useState(0);
|
|
34
38
|
const [sheets, setSheets] = useState(data);
|
|
35
39
|
|
|
@@ -39,13 +43,13 @@ You can check the example in [Storybook](https://github.com/Corbe30/FortuneExcel
|
|
|
39
43
|
setKey={setKey}
|
|
40
44
|
setSheets={setSheets}
|
|
41
45
|
sheetRef={sheetRef}
|
|
42
|
-
config={{ //
|
|
46
|
+
config={{ // default = all values are true
|
|
43
47
|
import: { xlsx: true, csv: true },
|
|
44
48
|
export: { xlsx: true, csv: true },
|
|
45
49
|
}}
|
|
46
50
|
/>
|
|
47
51
|
<Workbook
|
|
48
|
-
key={key} data={sheets} ref={
|
|
52
|
+
key={key} data={sheets} ref={sheetRef}
|
|
49
53
|
customToolbarItems={[importToolBarItem(), exportToolBarItem()]}
|
|
50
54
|
/>
|
|
51
55
|
</>
|
|
@@ -53,7 +57,7 @@ You can check the example in [Storybook](https://github.com/Corbe30/FortuneExcel
|
|
|
53
57
|
}
|
|
54
58
|
```
|
|
55
59
|
|
|
56
|
-
3.
|
|
60
|
+
3. Programmatic import/export ([code example](https://github.com/Corbe30/FortuneExcel/tree/main/src/stories/Manual.tsx))
|
|
57
61
|
```js
|
|
58
62
|
import { transformFortuneToExcel } from "@corbe30/fortune-excel";
|
|
59
63
|
|
|
@@ -61,12 +65,24 @@ You can check the example in [Storybook](https://github.com/Corbe30/FortuneExcel
|
|
|
61
65
|
const exportedFile = await transformFortuneToExcel(
|
|
62
66
|
sheetRef.current,
|
|
63
67
|
"xlsx", // or "csv"; default = "xlsx"
|
|
64
|
-
true //
|
|
68
|
+
true // start automatic download; default = true
|
|
65
69
|
);
|
|
66
70
|
console.log("Exported file data:", exportedFile);
|
|
67
71
|
};
|
|
68
72
|
|
|
69
|
-
<button onClick={manualExport}>
|
|
73
|
+
<button onClick={manualExport}>Export</button>
|
|
74
|
+
```
|
|
75
|
+
```js
|
|
76
|
+
import { transformExcelToFortune } from "@corbe30/fortune-excel";
|
|
77
|
+
|
|
78
|
+
const manualImport = async (event) => {
|
|
79
|
+
await transformExcelToFortune(
|
|
80
|
+
event.target.files[0], // file type (csv/xlsx) is automatically identified
|
|
81
|
+
setSheets,
|
|
82
|
+
setKey,
|
|
83
|
+
sheetRef.current
|
|
84
|
+
)
|
|
85
|
+
}
|
|
70
86
|
```
|
|
71
87
|
|
|
72
88
|
## Authors and acknowledgment
|
|
@@ -46,11 +46,12 @@ var ImportHelper = function (props) {
|
|
|
46
46
|
var setSheets = props.setSheets, setKey = props.setKey, sheetRef = props.sheetRef, config = props.config;
|
|
47
47
|
var acceptTypes = "".concat(config.xlsx ? ".xlsx," : "").concat(config.csv ? ".csv" : "");
|
|
48
48
|
return (react_1.default.createElement("input", { type: "file", id: "ImportHelper", accept: acceptTypes, onChange: function (e) { return __awaiter(void 0, void 0, void 0, function () {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
var _a, _b;
|
|
50
|
+
return __generator(this, function (_c) {
|
|
51
|
+
switch (_c.label) {
|
|
52
|
+
case 0: return [4 /*yield*/, (0, Transform_1.transformExcelToFortune)((_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b[0], setSheets, setKey, sheetRef.current)];
|
|
52
53
|
case 1:
|
|
53
|
-
|
|
54
|
+
_c.sent();
|
|
54
55
|
return [2 /*return*/];
|
|
55
56
|
}
|
|
56
57
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IFileType } from "./ICommon";
|
|
2
|
-
export declare const transformExcelToFortune: (
|
|
2
|
+
export declare const transformExcelToFortune: (file: any, setSheets: any, setKey: any, sheetRef: any) => Promise<void>;
|
|
3
3
|
export declare const transformFortuneToExcel: (luckysheetRef: any, fileType?: IFileType, download?: boolean) => Promise<Blob>;
|
package/dist/common/Transform.js
CHANGED
|
@@ -85,12 +85,11 @@ var convertCsvToExcel = function (file) { return __awaiter(void 0, void 0, void
|
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
}); };
|
|
88
|
-
var transformExcelToFortune = function (
|
|
89
|
-
var
|
|
88
|
+
var transformExcelToFortune = function (file, setSheets, setKey, sheetRef) { return __awaiter(void 0, void 0, void 0, function () {
|
|
89
|
+
var excelFile, fileName, files, fortuneFile, lsh;
|
|
90
90
|
return __generator(this, function (_a) {
|
|
91
91
|
switch (_a.label) {
|
|
92
92
|
case 0:
|
|
93
|
-
file = e.target.files[0];
|
|
94
93
|
fileName = file.name;
|
|
95
94
|
if (!(file.type === 'text/csv' || file.name.toLowerCase().endsWith('.csv'))) return [3 /*break*/, 2];
|
|
96
95
|
return [4 /*yield*/, convertCsvToExcel(file)];
|
|
@@ -113,12 +112,11 @@ var transformExcelToFortune = function (e, setSheets, setKey, sheetRef) { return
|
|
|
113
112
|
setSheets(lsh.sheets);
|
|
114
113
|
setKey(function (k) { return k + 1; });
|
|
115
114
|
setTimeout(function () {
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
var sheet = _c[_i];
|
|
115
|
+
for (var _i = 0, _a = lsh.sheets; _i < _a.length; _i++) {
|
|
116
|
+
var sheet = _a[_i];
|
|
119
117
|
var config = sheet.config;
|
|
120
|
-
|
|
121
|
-
|
|
118
|
+
sheetRef.setColumnWidth((config === null || config === void 0 ? void 0 : config.columnlen) || {}, { id: sheet.id });
|
|
119
|
+
sheetRef.setRowHeight((config === null || config === void 0 ? void 0 : config.rowlen) || {}, { id: sheet.id });
|
|
122
120
|
}
|
|
123
121
|
}, 1);
|
|
124
122
|
return [2 /*return*/];
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"workspaces": [
|
|
4
4
|
"src/*"
|
|
5
5
|
],
|
|
6
|
-
"version": "2.2.
|
|
6
|
+
"version": "2.2.5",
|
|
7
7
|
"description": "An Excel import/export import library for FortuneSheet",
|
|
8
8
|
"main": "dist/main.js",
|
|
9
9
|
"types": "dist/main.d.ts",
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
"prepare": "tsc",
|
|
50
50
|
"storybook": "storybook dev -p 6006",
|
|
51
51
|
"build-storybook": "storybook build"
|
|
52
|
-
}
|
|
52
|
+
},
|
|
53
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
53
54
|
}
|