@corbe30/fortune-excel 1.0.8 → 1.2.0

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
@@ -1,23 +1,18 @@
1
- # FortuneExcel
1
+ <p align="center">
2
+ <img align="center" src="fortuneExcelLogo.png" width="150px" height="150px" />
3
+ </p>
4
+ <h1 align="center">FortuneExcel</h1>
5
+ <p align="center">FortuneExcel is an .xlsx import/export plugin for FortuneSheet.</p>
6
+
7
+ <div align="center">
2
8
 
3
9
  <p>
4
10
  <a href="http://npmjs.com/package/@corbe30/fortune-excel" alt="fortuneExcel on npm">
5
- <img src="https://img.shields.io/npm/v/@corbe30/fortune-excel" /></a>
6
-
7
- <a href="http://npmjs.com/package/@corbe30/fortune-excel" alt="fortuneExcel downloads">
11
+ <img src="https://img.shields.io/npm/v/@corbe30/fortune-excel" /></a> <a href="http://npmjs.com/package/@corbe30/fortune-excel" alt="fortuneExcel downloads">
8
12
  <img src="https://img.shields.io/npm/d18m/%40corbe30%2Ffortune-excel" /></a>
9
13
  </p>
10
14
 
11
- FortuneExcel is an import/export library for [FortuneSheet](https://github.com/ruilisi/fortune-sheet/). It only supports .xlsx files (not .xls).
12
-
13
- ## Features
14
-
15
- Supports the following spreadsheet features in import/export:
16
-
17
- - Cell style
18
- - Cell border
19
- - Cell format, such as number format, date, percentage, etc.
20
- - Formula
15
+ </div>
21
16
 
22
17
  ## Usage
23
18
 
@@ -31,7 +26,7 @@ npm i @corbe30/fortune-excel
31
26
  2. Add import/export toolbar item in fortune-sheet
32
27
  > `<ImportHelper />` is a hidden component and only required when using `importToolBarItem()`.
33
28
  ```js
34
- import { importToolBarItem, ImportHelper, exportToolBarItem } from "fortune-excel";
29
+ import { ImportHelper, importToolBarItem, exportToolBarItem } from "fortune-excel";
35
30
 
36
31
  function App() {
37
32
  const workbookRef = useRef();
@@ -42,9 +37,7 @@ function App() {
42
37
  <>
43
38
  <ImportHelper setKey={setKey} setSheets={setSheets} sheetRef={workbookRef} />
44
39
  <Workbook
45
- key={key}
46
- data={sheets}
47
- ref={workbookRef}
40
+ key={key} data={sheets} ref={workbookRef}
48
41
  customToolbarItems={[exportToolBarItem(workbookRef), importToolBarItem()]}
49
42
  />
50
43
  </>
@@ -55,6 +48,8 @@ function App() {
55
48
  ## Authors and acknowledgment
56
49
 
57
50
  - [@Corbe30](https://github.com/Corbe30)
51
+
52
+ Developers of [FortuneSheetExcel](https://github.com/zenmrp/FortuneSheetExcel):
58
53
  - [@wbfsa](https://github.com/wbfsa)
59
54
  - [@wpxp123456](https://github.com/wpxp123456)
60
55
  - [@Dushusir](https://github.com/Dushusir)
@@ -0,0 +1,2 @@
1
+ declare function setHiddenRowCol(table: any, worksheet: any): void;
2
+ export { setHiddenRowCol };
@@ -0,0 +1,10 @@
1
+ function setHiddenRowCol(table, worksheet) {
2
+ var _a, _b;
3
+ for (var row in (_a = table.config) === null || _a === void 0 ? void 0 : _a.rowhidden) {
4
+ worksheet.getRow(parseInt(row) + 1).hidden = true;
5
+ }
6
+ for (var col in (_b = table.config) === null || _b === void 0 ? void 0 : _b.colhidden) {
7
+ worksheet.getColumn(parseInt(col) + 1).hidden = true;
8
+ }
9
+ }
10
+ export { setHiddenRowCol };
@@ -40,6 +40,8 @@ import { setStyleAndValue } from "./ExcelStyle.js";
40
40
  import { setMerge } from "../common/method.js";
41
41
  import { setImages } from "./ExcelImage.js";
42
42
  import { setBorder } from "./ExcelBorder.js";
43
+ import { setDataValidations } from "./ExcelValidation.js";
44
+ import { setHiddenRowCol } from "./ExcelConfig.js";
43
45
  export function exportSheetExcel(luckysheetRef) {
44
46
  return __awaiter(this, void 0, void 0, function () {
45
47
  var luckysheet, workbook, buffer, fileData;
@@ -59,6 +61,8 @@ export function exportSheetExcel(luckysheetRef) {
59
61
  setMerge((_b = table === null || table === void 0 ? void 0 : table.config) === null || _b === void 0 ? void 0 : _b.merge, worksheet);
60
62
  setBorder(table, worksheet);
61
63
  setImages(table, worksheet, workbook);
64
+ setDataValidations(table, worksheet);
65
+ setHiddenRowCol(table, worksheet);
62
66
  return true;
63
67
  });
64
68
  return [4 /*yield*/, workbook.xlsx.writeBuffer()];
@@ -0,0 +1,2 @@
1
+ declare function setDataValidations(table: any, worksheet: any): void;
2
+ export { setDataValidations };
@@ -0,0 +1,64 @@
1
+ import { DATA_VERIFICATION_REV_MAP, OPERATOR_MAP } from "../common/constant";
2
+ function rowColToCell(rowColumn) {
3
+ var _a = rowColumn.split("_").map(Number), row = _a[0], col = _a[1];
4
+ function columnToLetters(colIndex) {
5
+ var letters = "";
6
+ while (colIndex >= 0) {
7
+ letters = String.fromCharCode((colIndex % 26) + 65) + letters;
8
+ colIndex = Math.floor(colIndex / 26) - 1;
9
+ }
10
+ return letters;
11
+ }
12
+ var columnLetters = columnToLetters(col);
13
+ var rowNumber = row + 1;
14
+ return "".concat(columnLetters).concat(rowNumber);
15
+ }
16
+ // TODO: define contants
17
+ function getExcelValidation(cellVerification) {
18
+ var excelValidation = {
19
+ type: DATA_VERIFICATION_REV_MAP[cellVerification.type],
20
+ showInputMessage: !!cellVerification.hintShow,
21
+ showErrorMessage: !!cellVerification.prohibitInput,
22
+ prompt: cellVerification.hintValue,
23
+ };
24
+ switch (cellVerification.type) {
25
+ case "dropdown":
26
+ excelValidation.formulae = ['"' + cellVerification.value1 + '"'];
27
+ break;
28
+ case "number":
29
+ case "number_integer":
30
+ case "number_decimal":
31
+ excelValidation.operator = OPERATOR_MAP[cellVerification.type2];
32
+ excelValidation.formulae = [
33
+ parseFloat(cellVerification.value1),
34
+ parseFloat(cellVerification.value2),
35
+ ];
36
+ break;
37
+ case "text_length":
38
+ excelValidation.operator = OPERATOR_MAP[cellVerification.type2];
39
+ excelValidation.formulae = [
40
+ parseInt(cellVerification.value1),
41
+ parseInt(cellVerification.value2),
42
+ ];
43
+ if (!excelValidation.formulae[1])
44
+ excelValidation.formulae.pop();
45
+ break;
46
+ case "date":
47
+ excelValidation.operator = OPERATOR_MAP[cellVerification.type2];
48
+ excelValidation.formulae = [
49
+ new Date(cellVerification.value1),
50
+ new Date(cellVerification.value2),
51
+ ];
52
+ break;
53
+ default:
54
+ return {};
55
+ }
56
+ return excelValidation;
57
+ }
58
+ function setDataValidations(table, worksheet) {
59
+ for (var key in table.dataVerification) {
60
+ var cell = rowColToCell(key);
61
+ worksheet.getCell(cell).dataValidation = getExcelValidation(table.dataVerification[key]);
62
+ }
63
+ }
64
+ export { setDataValidations };
@@ -20,6 +20,8 @@ export declare const borderTypes: stringToNum;
20
20
  export declare let numFmtDefaultMap: IattributeList;
21
21
  export declare const fontFamilys: IattributeList;
22
22
  export declare const DATA_VERIFICATION_MAP: IDataVerificationMap;
23
+ export declare const DATA_VERIFICATION_REV_MAP: any;
24
+ export declare const OPERATOR_MAP: any;
23
25
  export declare const COMMON_TYPE2: string[];
24
26
  export declare const DATA_VERIFICATION_TYPE2_MAP: IDataVerificationType2Map;
25
27
  export declare const ALIGNMENT_DEFAULT: number;
@@ -237,6 +237,24 @@ export var DATA_VERIFICATION_MAP = {
237
237
  unknown2: "checkbox", // no match yet
238
238
  unknown3: "validity", // no match yet
239
239
  };
240
+ export var DATA_VERIFICATION_REV_MAP = {
241
+ dropdown: "list",
242
+ number: "decimal",
243
+ number_integer: "decimal",
244
+ number_decimal: "decimal",
245
+ text_length: "textLength",
246
+ date: "date"
247
+ };
248
+ export var OPERATOR_MAP = {
249
+ between: "between",
250
+ notBetween: "notBetween",
251
+ equal: "equal",
252
+ notEqualTo: "notEqual",
253
+ moreThanThe: "greaterThan",
254
+ lessThan: "lessThan",
255
+ greaterOrEqualTo: "greaterThanOrEqual",
256
+ lessThanOrEqualTo: "lessThanOrEqual"
257
+ };
240
258
  export var COMMON_TYPE2 = [
241
259
  "number",
242
260
  "number_integer",
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corbe30/fortune-excel",
3
- "version": "1.0.8",
3
+ "version": "1.2.0",
4
4
  "description": "An Excel import/export import library for FortuneSheet",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",