@corbe30/fortune-excel 1.0.9 → 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.
@@ -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",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corbe30/fortune-excel",
3
- "version": "1.0.9",
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",