@corbe30/fortune-excel 2.2.3 → 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 +29 -13
- package/dist/ToFortuneSheet/FortuneBase.d.ts +1 -1
- package/dist/ToFortuneSheet/FortuneCell.js +4 -4
- package/dist/ToFortuneSheet/FortuneFile.js +16 -0
- package/dist/ToFortuneSheet/IFortune.d.ts +1 -1
- package/dist/ToFortuneSheet/ImportHelper.js +5 -4
- package/dist/common/Transform.d.ts +1 -1
- package/dist/common/Transform.js +6 -8
- package/package.json +3 -2
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
|
|
@@ -59,7 +59,7 @@ export declare class FortuneSheetCelldataValue implements IfortuneSheetCelldataV
|
|
|
59
59
|
ht: number | undefined;
|
|
60
60
|
mc: IfortuneSheetCelldataValueMerge | undefined;
|
|
61
61
|
tr: number | undefined;
|
|
62
|
-
tb:
|
|
62
|
+
tb: string | undefined;
|
|
63
63
|
v: string | undefined;
|
|
64
64
|
m: string | undefined;
|
|
65
65
|
f: string | undefined;
|
|
@@ -344,14 +344,14 @@ var FortuneSheetCelldata = /** @class */ (function (_super) {
|
|
|
344
344
|
}
|
|
345
345
|
if (wrapText != undefined) {
|
|
346
346
|
if (wrapText == "1") {
|
|
347
|
-
cellValue.tb = 2;
|
|
347
|
+
cellValue.tb = "2";
|
|
348
348
|
}
|
|
349
349
|
else {
|
|
350
|
-
cellValue.tb = 1;
|
|
350
|
+
cellValue.tb = "1";
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
else {
|
|
354
|
-
cellValue.tb = 1;
|
|
354
|
+
cellValue.tb = "1";
|
|
355
355
|
}
|
|
356
356
|
if (textRotation != undefined) {
|
|
357
357
|
// tr: number | undefined //Text rotation,0: 0、1: 45 、2: -45、3 Vertical text、4: 90 、5: -90, alignment
|
|
@@ -438,7 +438,7 @@ var FortuneSheetCelldata = /** @class */ (function (_super) {
|
|
|
438
438
|
}
|
|
439
439
|
}
|
|
440
440
|
else {
|
|
441
|
-
cellValue.tb = 1;
|
|
441
|
+
cellValue.tb = "1";
|
|
442
442
|
}
|
|
443
443
|
if (v != null) {
|
|
444
444
|
var value = v[0].value;
|
|
@@ -397,6 +397,22 @@ var FortuneFile = /** @class */ (function () {
|
|
|
397
397
|
if (v.mc.r !== r || v.mc.c !== c)
|
|
398
398
|
v = { mc: v.mc };
|
|
399
399
|
}
|
|
400
|
+
else {
|
|
401
|
+
for (var key in sheet.config.merge) {
|
|
402
|
+
if (sheet.config.merge.hasOwnProperty(key)) {
|
|
403
|
+
var range = sheet.config.merge[key];
|
|
404
|
+
if (r >= range.r &&
|
|
405
|
+
r < range.r + range.rs &&
|
|
406
|
+
c >= range.c &&
|
|
407
|
+
c < range.c + range.cs) {
|
|
408
|
+
v.mc = { r: range.r, c: range.c };
|
|
409
|
+
if (v.mc.r !== r || v.mc.c !== c)
|
|
410
|
+
v = { mc: v.mc };
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
400
416
|
}
|
|
401
417
|
sheetout.celldata.push({ r: r, c: c, v: v });
|
|
402
418
|
}
|
|
@@ -134,7 +134,7 @@ export interface IfortuneSheetCelldataValue {
|
|
|
134
134
|
ht: number | undefined;
|
|
135
135
|
mc: IfortuneSheetCelldataValueMerge | undefined;
|
|
136
136
|
tr: number | undefined;
|
|
137
|
-
tb:
|
|
137
|
+
tb: string | undefined;
|
|
138
138
|
v: string | undefined;
|
|
139
139
|
m: string | undefined;
|
|
140
140
|
rt: number | undefined;
|
|
@@ -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
|
}
|