to-spreadsheet 1.1.1 → 1.1.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.
@@ -42,8 +42,11 @@ const generateExcel = (dump, environmentType = EnvironmentType.NODE) => {
42
42
  else if (content instanceof util_1.SkipCell) {
43
43
  return new Array(content.getSkipCell()).fill({ type: index_1.ICellType.skip, value: undefined });
44
44
  }
45
+ else if (content instanceof util_1.Equation) {
46
+ return { type: index_1.ICellType.equation, value: content };
47
+ }
45
48
  else {
46
- return { type: index_1.ICellType.skip, value: undefined };
49
+ return { type: index_1.ICellType.skip };
47
50
  }
48
51
  });
49
52
  return { cells };
package/lib/index.d.ts CHANGED
@@ -1,14 +1,27 @@
1
1
  import { generateExcel, EnvironmentType } from "./generate-excel";
2
- import { SkipCell, skipCell } from "./util";
2
+ import { SkipCell, skipCell, Equation, writeEquation } from "./util";
3
3
  declare enum ICellType {
4
4
  string = "s",
5
5
  number = "n",
6
- skip = "skip"
6
+ skip = "skip",
7
+ equation = "equation"
7
8
  }
8
- interface ICell {
9
- type: ICellType;
10
- value: number | undefined;
9
+ interface ICellString {
10
+ type: ICellType.string;
11
+ value: number;
11
12
  }
13
+ interface ICellNumber {
14
+ type: ICellType.number;
15
+ value: number;
16
+ }
17
+ interface ICellSkip {
18
+ type: ICellType.skip;
19
+ }
20
+ interface ICellEquation {
21
+ type: ICellType.equation;
22
+ value: Equation;
23
+ }
24
+ declare type ICell = ICellString | ICellNumber | ICellSkip | ICellEquation;
12
25
  interface IRows {
13
26
  cells: ICell[];
14
27
  }
@@ -23,12 +36,12 @@ interface IWorkbook {
23
36
  }
24
37
  interface IPage {
25
38
  title: string;
26
- content: (string | number | undefined | SkipCell)[][];
39
+ content: (string | number | undefined | SkipCell | Equation)[][];
27
40
  }
28
41
  export { ICell, ISheet, IWorkbook, IRows, ICellType, IPage };
29
42
  declare const sampleData: ({
30
43
  title: string;
31
- content: (string[] | number[])[];
44
+ content: (string[] | (number | Equation)[])[];
32
45
  } | {
33
46
  title: string;
34
47
  content: (number | SkipCell)[][];
@@ -36,4 +49,4 @@ declare const sampleData: ({
36
49
  title: string;
37
50
  content: (string | undefined)[][];
38
51
  })[];
39
- export { generateExcel, sampleData, EnvironmentType, skipCell };
52
+ export { generateExcel, sampleData, EnvironmentType, skipCell, writeEquation };
package/lib/index.js CHANGED
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.skipCell = exports.EnvironmentType = exports.sampleData = exports.generateExcel = exports.ICellType = void 0;
3
+ exports.writeEquation = exports.skipCell = exports.EnvironmentType = exports.sampleData = exports.generateExcel = exports.ICellType = void 0;
4
4
  const generate_excel_1 = require("./generate-excel");
5
5
  Object.defineProperty(exports, "generateExcel", { enumerable: true, get: function () { return generate_excel_1.generateExcel; } });
6
6
  Object.defineProperty(exports, "EnvironmentType", { enumerable: true, get: function () { return generate_excel_1.EnvironmentType; } });
7
7
  const util_1 = require("./util");
8
8
  Object.defineProperty(exports, "skipCell", { enumerable: true, get: function () { return util_1.skipCell; } });
9
+ Object.defineProperty(exports, "writeEquation", { enumerable: true, get: function () { return util_1.writeEquation; } });
9
10
  var ICellType;
10
11
  (function (ICellType) {
11
12
  ICellType["string"] = "s";
12
13
  ICellType["number"] = "n";
13
14
  ICellType["skip"] = "skip";
15
+ ICellType["equation"] = "equation";
14
16
  })(ICellType || (ICellType = {}));
15
17
  exports.ICellType = ICellType;
16
18
  const sampleData = [
@@ -20,7 +22,7 @@ const sampleData = [
20
22
  ['woof', 'smack'],
21
23
  [1],
22
24
  [1, 2],
23
- [1, 2, 3],
25
+ [1, 2, 3, (0, util_1.writeEquation)('SUM(A5,C5)')],
24
26
  ]
25
27
  },
26
28
  { title: 'Maifee2', content: [[1], [1, (0, util_1.skipCell)(3), 2]] },
package/lib/util.d.ts CHANGED
@@ -10,4 +10,10 @@ declare class SkipCell {
10
10
  constructor(skipCell: number);
11
11
  }
12
12
  declare const skipCell: (skipCell: number) => SkipCell;
13
- export { indexToVbIndex, indexToVbRelationIndex, indexToRowIndex, rowColumnToVbPosition, calculateExtant, SkipCell, skipCell };
13
+ declare class Equation {
14
+ private equation;
15
+ getEquation: () => string;
16
+ constructor(equation: string);
17
+ }
18
+ declare const writeEquation: (equation: string) => Equation;
19
+ export { indexToVbIndex, indexToVbRelationIndex, indexToRowIndex, rowColumnToVbPosition, calculateExtant, SkipCell, skipCell, Equation, writeEquation };
package/lib/util.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.skipCell = exports.SkipCell = exports.calculateExtant = exports.rowColumnToVbPosition = exports.indexToRowIndex = exports.indexToVbRelationIndex = exports.indexToVbIndex = void 0;
3
+ exports.writeEquation = exports.Equation = exports.skipCell = exports.SkipCell = exports.calculateExtant = exports.rowColumnToVbPosition = exports.indexToRowIndex = exports.indexToVbRelationIndex = exports.indexToVbIndex = void 0;
4
4
  const indexToVbIndex = (index) => index + 1;
5
5
  exports.indexToVbIndex = indexToVbIndex;
6
6
  const indexToVbRelationIndex = (index) => indexToVbIndex(index) + 2;
@@ -29,3 +29,12 @@ class SkipCell {
29
29
  exports.SkipCell = SkipCell;
30
30
  const skipCell = (skipCell) => new SkipCell(skipCell);
31
31
  exports.skipCell = skipCell;
32
+ class Equation {
33
+ constructor(equation) {
34
+ this.getEquation = () => this.equation;
35
+ this.equation = equation;
36
+ }
37
+ }
38
+ exports.Equation = Equation;
39
+ const writeEquation = (equation) => new Equation(equation);
40
+ exports.writeEquation = writeEquation;
@@ -20,18 +20,33 @@ const generateSheetXml = (sheet) => {
20
20
  <col max="1025" min="1" style="0" width="11.52"/>
21
21
  </cols>
22
22
  <sheetData>
23
- ${(sheet.rows).map((row, indexCol) => `
24
- <row r="${(0, util_1.indexToVbIndex)(indexCol)}">
25
- ${(row.cells).map((cell, indexRow) => cell.type === __1.ICellType.skip
26
- ? ""
27
- : `
28
- <c r="${(0, util_1.rowColumnToVbPosition)(indexRow, indexCol)}" t="${cell.type}">
29
- <v>${cell.value}</v>
30
- </c>
31
- `).join('\n')}
32
- </row>
33
- `).join('\n')}
34
- </sheetData>
23
+ ${sheet.rows.map((row, rowIndex) => {
24
+ let rowContent = '';
25
+ rowContent += `<row r="${(0, util_1.indexToVbIndex)(rowIndex)}">\n`;
26
+ row.cells.forEach((cell, cellIndex) => {
27
+ const cellType = cell.type;
28
+ if (cellType !== __1.ICellType.skip) {
29
+ const cellPosition = (0, util_1.rowColumnToVbPosition)(cellIndex, rowIndex);
30
+ const cellValue = cell.value || '';
31
+ if (cell.type === __1.ICellType.equation) {
32
+ rowContent += `
33
+ <c r="${cellPosition}" t="n">
34
+ <f aca="false">${cell.value.getEquation()}</f>
35
+ </c>\n`;
36
+ }
37
+ else {
38
+ rowContent += `
39
+ <c r="${cellPosition}" t="${cellType}">
40
+ <v>${cellValue}</v>
41
+ </c>\n`;
42
+ }
43
+ }
44
+ });
45
+ rowContent += '</row>\n';
46
+ return rowContent;
47
+ }).join('')}
48
+ </sheetData>
49
+
35
50
  <pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>
36
51
  </worksheet>
37
52
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "to-spreadsheet",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "npm package to create spreadsheet in node environment",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -1,16 +1,30 @@
1
1
  import { generateExcel, EnvironmentType } from "./generate-excel";
2
- import { SkipCell, skipCell } from "./util";
2
+ import { SkipCell, skipCell, Equation, writeEquation } from "./util";
3
3
 
4
4
  enum ICellType {
5
5
  string = "s",
6
6
  number = "n",
7
7
  skip = "skip",
8
+ equation = "equation",
8
9
  }
9
10
 
10
- interface ICell {
11
- type: ICellType;
12
- value: number | undefined;
11
+ interface ICellString {
12
+ type: ICellType.string;
13
+ value: number;
13
14
  }
15
+ interface ICellNumber {
16
+ type: ICellType.number;
17
+ value: number;
18
+ }
19
+ interface ICellSkip {
20
+ type: ICellType.skip;
21
+ }
22
+ interface ICellEquation {
23
+ type: ICellType.equation;
24
+ value: Equation;
25
+ }
26
+
27
+ type ICell = ICellString | ICellNumber | ICellSkip | ICellEquation;
14
28
 
15
29
  interface IRows {
16
30
  cells: ICell[];
@@ -29,7 +43,7 @@ interface IWorkbook {
29
43
 
30
44
  interface IPage {
31
45
  title: string
32
- content: (string | number | undefined | SkipCell)[][]
46
+ content: (string | number | undefined | SkipCell | Equation)[][]
33
47
  }
34
48
 
35
49
  export { ICell, ISheet, IWorkbook, IRows, ICellType, IPage }
@@ -42,7 +56,7 @@ const sampleData = [
42
56
  ['woof', 'smack'],
43
57
  [1],
44
58
  [1, 2],
45
- [1, 2, 3],
59
+ [1, 2, 3, writeEquation('SUM(A5,C5)')],
46
60
  ]
47
61
  },
48
62
  { title: 'Maifee2', content: [[1], [1, skipCell(3), 2]] },
@@ -51,4 +65,4 @@ const sampleData = [
51
65
 
52
66
  // generateExcel(sampleData) // <- check before releasing with `yarn test:compile`
53
67
 
54
- export { generateExcel, sampleData, EnvironmentType, skipCell };
68
+ export { generateExcel, sampleData, EnvironmentType, skipCell, writeEquation };