read-excel-file 5.2.7 → 5.2.11

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.
Files changed (91) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +4 -0
  3. package/bundle/read-excel-file.min.js +2 -2
  4. package/bundle/read-excel-file.min.js.map +1 -1
  5. package/commonjs/read/coordinates.js +56 -0
  6. package/commonjs/read/coordinates.js.map +1 -0
  7. package/commonjs/read/dropEmptyColumns.js +52 -0
  8. package/commonjs/read/dropEmptyColumns.js.map +1 -0
  9. package/commonjs/read/dropEmptyColumns.test.js.map +1 -0
  10. package/commonjs/read/dropEmptyRows.js +55 -0
  11. package/commonjs/read/dropEmptyRows.js.map +1 -0
  12. package/commonjs/read/dropEmptyRows.test.js.map +1 -0
  13. package/commonjs/read/getData.js +99 -0
  14. package/commonjs/read/getData.js.map +1 -0
  15. package/commonjs/read/parseCell.js +71 -0
  16. package/commonjs/read/parseCell.js.map +1 -0
  17. package/commonjs/read/parseCellValue.js +204 -0
  18. package/commonjs/read/parseCellValue.js.map +1 -0
  19. package/commonjs/read/parseCells.js +30 -0
  20. package/commonjs/read/parseCells.js.map +1 -0
  21. package/commonjs/read/parseDimensions.js +47 -0
  22. package/commonjs/read/parseDimensions.js.map +1 -0
  23. package/commonjs/read/parseFilePaths.js +83 -0
  24. package/commonjs/read/parseFilePaths.js.map +1 -0
  25. package/commonjs/read/parseProperties.js +48 -0
  26. package/commonjs/read/parseProperties.js.map +1 -0
  27. package/commonjs/read/parseSharedStrings.js +17 -0
  28. package/commonjs/read/parseSharedStrings.js.map +1 -0
  29. package/commonjs/read/parseSheet.js +25 -0
  30. package/commonjs/read/parseSheet.js.map +1 -0
  31. package/commonjs/read/parseStyles.js +72 -0
  32. package/commonjs/read/parseStyles.js.map +1 -0
  33. package/commonjs/read/readXlsx.js +25 -657
  34. package/commonjs/read/readXlsx.js.map +1 -1
  35. package/commonjs/types/URL.js +56 -2
  36. package/commonjs/types/URL.js.map +1 -1
  37. package/commonjs/xml/dom.js +17 -3
  38. package/commonjs/xml/dom.js.map +1 -1
  39. package/commonjs/xml/xlsx-xpath.js +10 -0
  40. package/commonjs/xml/xlsx-xpath.js.map +1 -1
  41. package/commonjs/xml/xlsx.js +22 -0
  42. package/commonjs/xml/xlsx.js.map +1 -1
  43. package/commonjs/xml/xmlNode.js +1 -1
  44. package/commonjs/xml/xmlNode.js.map +1 -1
  45. package/{index.d.ts.test → index.d.ts} +1 -4
  46. package/modules/read/coordinates.js +48 -0
  47. package/modules/read/coordinates.js.map +1 -0
  48. package/modules/read/dropEmptyColumns.js +45 -0
  49. package/modules/read/dropEmptyColumns.js.map +1 -0
  50. package/modules/read/dropEmptyColumns.test.js.map +1 -0
  51. package/modules/read/dropEmptyRows.js +48 -0
  52. package/modules/read/dropEmptyRows.js.map +1 -0
  53. package/modules/read/dropEmptyRows.test.js.map +1 -0
  54. package/modules/read/getData.js +88 -0
  55. package/modules/read/getData.js.map +1 -0
  56. package/modules/read/parseCell.js +59 -0
  57. package/modules/read/parseCell.js.map +1 -0
  58. package/modules/read/parseCellValue.js +192 -0
  59. package/modules/read/parseCellValue.js.map +1 -0
  60. package/modules/read/parseCells.js +19 -0
  61. package/modules/read/parseCells.js.map +1 -0
  62. package/modules/read/parseDimensions.js +38 -0
  63. package/modules/read/parseDimensions.js.map +1 -0
  64. package/modules/read/parseFilePaths.js +76 -0
  65. package/modules/read/parseFilePaths.js.map +1 -0
  66. package/modules/read/parseProperties.js +40 -0
  67. package/modules/read/parseProperties.js.map +1 -0
  68. package/modules/read/parseSharedStrings.js +9 -0
  69. package/modules/read/parseSharedStrings.js.map +1 -0
  70. package/modules/read/parseSheet.js +13 -0
  71. package/modules/read/parseSheet.js.map +1 -0
  72. package/modules/read/parseStyles.js +64 -0
  73. package/modules/read/parseStyles.js.map +1 -0
  74. package/modules/read/readXlsx.js +20 -653
  75. package/modules/read/readXlsx.js.map +1 -1
  76. package/modules/types/URL.js +56 -2
  77. package/modules/types/URL.js.map +1 -1
  78. package/modules/xml/dom.js +14 -3
  79. package/modules/xml/dom.js.map +1 -1
  80. package/modules/xml/xlsx-xpath.js +6 -0
  81. package/modules/xml/xlsx-xpath.js.map +1 -1
  82. package/modules/xml/xlsx.js +19 -1
  83. package/modules/xml/xlsx.js.map +1 -1
  84. package/modules/xml/xmlNode.js +1 -1
  85. package/modules/xml/xmlNode.js.map +1 -1
  86. package/node/{index.d.ts.test → index.d.ts} +1 -1
  87. package/package.json +6 -5
  88. package/schema/{index.d.ts.test → index.d.ts} +0 -0
  89. package/types.d.ts +1 -4
  90. package/commonjs/read/readXlsx.test.js.map +0 -1
  91. package/modules/read/readXlsx.test.js.map +0 -1
@@ -0,0 +1,48 @@
1
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
2
+
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+
5
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6
+
7
+ export default function dropEmptyRows(data) {
8
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
9
+ rowMap = _ref.rowMap,
10
+ _ref$accessor = _ref.accessor,
11
+ accessor = _ref$accessor === void 0 ? function (_) {
12
+ return _;
13
+ } : _ref$accessor,
14
+ onlyTrimAtTheEnd = _ref.onlyTrimAtTheEnd;
15
+
16
+ // Drop empty rows.
17
+ var i = data.length - 1;
18
+
19
+ while (i >= 0) {
20
+ // Check if the row is empty.
21
+ var empty = true;
22
+
23
+ for (var _iterator = _createForOfIteratorHelperLoose(data[i]), _step; !(_step = _iterator()).done;) {
24
+ var cell = _step.value;
25
+
26
+ if (accessor(cell) !== null) {
27
+ empty = false;
28
+ break;
29
+ }
30
+ } // Remove the empty row.
31
+
32
+
33
+ if (empty) {
34
+ data.splice(i, 1);
35
+
36
+ if (rowMap) {
37
+ rowMap.splice(i, 1);
38
+ }
39
+ } else if (onlyTrimAtTheEnd) {
40
+ break;
41
+ }
42
+
43
+ i--;
44
+ }
45
+
46
+ return data;
47
+ }
48
+ //# sourceMappingURL=dropEmptyRows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../source/read/dropEmptyRows.js"],"names":["dropEmptyRows","data","rowMap","accessor","_","onlyTrimAtTheEnd","i","length","empty","cell","splice"],"mappings":";;;;;;AAAA,eAAe,SAASA,aAAT,CAAuBC,IAAvB,EAIP;AAAA,iFAAJ,EAAI;AAAA,MAHNC,MAGM,QAHNA,MAGM;AAAA,2BAFNC,QAEM;AAAA,MAFNA,QAEM,8BAFK,UAAAC,CAAC;AAAA,WAAIA,CAAJ;AAAA,GAEN;AAAA,MADNC,gBACM,QADNA,gBACM;;AACN;AACA,MAAIC,CAAC,GAAGL,IAAI,CAACM,MAAL,GAAc,CAAtB;;AACA,SAAOD,CAAC,IAAI,CAAZ,EAAe;AACb;AACA,QAAIE,KAAK,GAAG,IAAZ;;AACA,yDAAmBP,IAAI,CAACK,CAAD,CAAvB,wCAA4B;AAAA,UAAjBG,IAAiB;;AAC1B,UAAIN,QAAQ,CAACM,IAAD,CAAR,KAAmB,IAAvB,EAA6B;AAC3BD,QAAAA,KAAK,GAAG,KAAR;AACA;AACD;AACF,KARY,CASb;;;AACA,QAAIA,KAAJ,EAAW;AACTP,MAAAA,IAAI,CAACS,MAAL,CAAYJ,CAAZ,EAAe,CAAf;;AACA,UAAIJ,MAAJ,EAAY;AACVA,QAAAA,MAAM,CAACQ,MAAP,CAAcJ,CAAd,EAAiB,CAAjB;AACD;AACF,KALD,MAKO,IAAID,gBAAJ,EAAsB;AAC3B;AACD;;AACDC,IAAAA,CAAC;AACF;;AACD,SAAOL,IAAP;AACD","sourcesContent":["export default function dropEmptyRows(data, {\r\n rowMap,\r\n accessor = _ => _,\r\n onlyTrimAtTheEnd\r\n} = {}) {\r\n // Drop empty rows.\r\n let i = data.length - 1\r\n while (i >= 0) {\r\n // Check if the row is empty.\r\n let empty = true\r\n for (const cell of data[i]) {\r\n if (accessor(cell) !== null) {\r\n empty = false\r\n break\r\n }\r\n }\r\n // Remove the empty row.\r\n if (empty) {\r\n data.splice(i, 1)\r\n if (rowMap) {\r\n rowMap.splice(i, 1)\r\n }\r\n } else if (onlyTrimAtTheEnd) {\r\n break\r\n }\r\n i--\r\n }\r\n return data\r\n}"],"file":"dropEmptyRows.js"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../source/read/dropEmptyRows.test.js"],"names":["dropEmptyRows","describe","it","onlyTrimAtTheEnd","should","deep","equal","rowMap"],"mappings":"AAAA,OAAOA,aAAP,MAA0B,iBAA1B;AAEAC,QAAQ,CAAC,eAAD,EAAkB,YAAM;AAC/BC,EAAAA,EAAE,CAAC,0CAAD,EAA6C,YAAM;AACpDF,IAAAA,aAAa,CAAC,CACb,CAAC,IAAD,EAAO,IAAP,EAAa,IAAb,CADa,EAEb,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,CAFa,EAGb,CAAC,IAAD,EAAO,GAAP,EAAY,IAAZ,CAHa,EAIb,CAAC,IAAD,EAAO,IAAP,EAAa,IAAb,CAJa,EAKb,CAAC,GAAD,EAAM,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,IAAP,EAAa,IAAb,CADa,EAEb,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,CAFa,EAGb,CAAC,IAAD,EAAO,GAAP,EAAY,IAAZ,CAHa,EAIb,CAAC,IAAD,EAAO,IAAP,EAAa,IAAb,CAJa,EAKb,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,CALa,CAAD,EAOb;AAAEO,MAAAA,MAAM,EAANA;AAAF,KAPa,CAAb,CAQCH,MARD,CAQQC,IARR,CAQaC,KARb,CAQmB,CAClB,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,CADkB,EAElB,CAAC,IAAD,EAAO,GAAP,EAAY,IAAZ,CAFkB,EAGlB,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,CAHkB,CARnB;AAcAC,IAAAA,MAAM,CAACH,MAAP,CAAcC,IAAd,CAAmBC,KAAnB,CAAyB,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAzB;AACA,GAlBC,CAAF;AAmBA,CAxDO,CAAR","sourcesContent":["import dropEmptyRows from './dropEmptyRows'\r\n\r\ndescribe('dropEmptyRows', () => {\r\n\tit('should drop empty rows (only at the end)', () => {\r\n\t\tdropEmptyRows([\r\n\t\t\t[null, null, null],\r\n\t\t\t['A', 'B', 'C'],\r\n\t\t\t[null, 'D', null],\r\n\t\t\t[null, null, null],\r\n\t\t\t['E', 'F', 'G'],\r\n\t\t\t[null, null, null]\r\n\t\t], {\r\n\t\t\tonlyTrimAtTheEnd: true\r\n\t\t})\r\n\t\t.should.deep.equal([\r\n\t\t\t[null, null, null],\r\n\t\t\t['A', 'B', 'C'],\r\n\t\t\t[null, 'D', null],\r\n\t\t\t[null, null, null],\r\n\t\t\t['E', 'F', 'G']\r\n\t\t])\r\n\t})\r\n\r\n\tit('should drop empty rows', () => {\r\n\t\tdropEmptyRows([\r\n\t\t\t[null, null, null],\r\n\t\t\t['A', 'B', 'C'],\r\n\t\t\t[null, 'D', null],\r\n\t\t\t[null, null, null],\r\n\t\t\t['E', 'F', 'G'],\r\n\t\t\t[null, null, null]\r\n\t\t])\r\n\t\t.should.deep.equal([\r\n\t\t\t['A', 'B', 'C'],\r\n\t\t\t[null, 'D', null],\r\n\t\t\t['E', 'F', 'G']\r\n\t\t])\r\n\t})\r\n\r\n\tit('should generate row map when dropping empty rows', () => {\r\n\t\tconst rowMap = [0, 1, 2, 3, 4]\r\n\r\n\t\tdropEmptyRows([\r\n\t\t\t[null, null, null],\r\n\t\t\t['A', 'B', 'C'],\r\n\t\t\t[null, 'D', null],\r\n\t\t\t[null, null, null],\r\n\t\t\t['E', 'F', 'G']\r\n\t\t],\r\n\t\t{ rowMap })\r\n\t\t.should.deep.equal([\r\n\t\t\t['A', 'B', 'C'],\r\n\t\t\t[null, 'D', null],\r\n\t\t\t['E', 'F', 'G']\r\n\t\t])\r\n\r\n\t\trowMap.should.deep.equal([1, 2, 4])\r\n\t})\r\n})"],"file":"dropEmptyRows.test.js"}
@@ -0,0 +1,88 @@
1
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
2
+
3
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+
5
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
+
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+
9
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
10
+
11
+ function _iterableToArrayLimit(arr, i) { var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]); if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
12
+
13
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
+
15
+ import dropEmptyRows from './dropEmptyRows';
16
+ import dropEmptyColumns from './dropEmptyColumns';
17
+ export default function getData(sheet, options) {
18
+ var dimensions = sheet.dimensions,
19
+ cells = sheet.cells; // If the sheet is empty.
20
+
21
+ if (cells.length === 0) {
22
+ return [];
23
+ }
24
+
25
+ var _dimensions = _slicedToArray(dimensions, 2),
26
+ leftTop = _dimensions[0],
27
+ rightBottom = _dimensions[1];
28
+
29
+ var colsCount = rightBottom.column - leftTop.column + 1;
30
+ var rowsCount = rightBottom.row - leftTop.row + 1; // Initialize spreadsheet data structure.
31
+
32
+ var data = new Array(rowsCount);
33
+ var i = 0;
34
+
35
+ while (i < rowsCount) {
36
+ data[i] = new Array(colsCount);
37
+ var j = 0;
38
+
39
+ while (j < colsCount) {
40
+ data[i][j] = null;
41
+ j++;
42
+ }
43
+
44
+ i++;
45
+ } // Fill in spreadsheet data structure.
46
+ // (this code implies that `cells` aren't necessarily sorted by row and column:
47
+ // maybe that's not correct, this piece code was initially copy-pasted
48
+ // from some other library that used `XPath`)
49
+
50
+
51
+ for (var _iterator = _createForOfIteratorHelperLoose(cells), _step; !(_step = _iterator()).done;) {
52
+ var cell = _step.value;
53
+ var row = cell.row - leftTop.row;
54
+ var column = cell.column - leftTop.column;
55
+ data[row][column] = cell.value;
56
+ } // Fill in the row map.
57
+
58
+
59
+ var rowMap = options.rowMap;
60
+
61
+ if (rowMap) {
62
+ var _i2 = 0;
63
+
64
+ while (_i2 < data.length) {
65
+ rowMap[_i2] = _i2;
66
+ _i2++;
67
+ }
68
+ } // Drop empty columns or rows.
69
+
70
+
71
+ data = dropEmptyRows(dropEmptyColumns(data, {
72
+ onlyTrimAtTheEnd: true
73
+ }), {
74
+ onlyTrimAtTheEnd: true,
75
+ rowMap: rowMap
76
+ }); // Optionally transform data before applying `schema`.
77
+
78
+ if (options.transformData) {
79
+ data = options.transformData(data); // data = options.transformData(data, {
80
+ // dropEmptyRowsAndColumns(data) {
81
+ // return dropEmptyRows(dropEmptyColumns(data), { rowMap })
82
+ // }
83
+ // })
84
+ }
85
+
86
+ return data;
87
+ }
88
+ //# sourceMappingURL=getData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../source/read/getData.js"],"names":["dropEmptyRows","dropEmptyColumns","getData","sheet","options","dimensions","cells","length","leftTop","rightBottom","colsCount","column","rowsCount","row","data","Array","i","j","cell","value","rowMap","onlyTrimAtTheEnd","transformData"],"mappings":";;;;;;;;;;;;;;AAAA,OAAOA,aAAP,MAA0B,iBAA1B;AACA,OAAOC,gBAAP,MAA6B,oBAA7B;AAEA,eAAe,SAASC,OAAT,CAAiBC,KAAjB,EAAwBC,OAAxB,EAAiC;AAC9C,MAAQC,UAAR,GAA8BF,KAA9B,CAAQE,UAAR;AAAA,MAAoBC,KAApB,GAA8BH,KAA9B,CAAoBG,KAApB,CAD8C,CAG9C;;AACA,MAAIA,KAAK,CAACC,MAAN,KAAiB,CAArB,EAAwB;AACtB,WAAO,EAAP;AACD;;AAED,mCAA+BF,UAA/B;A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aAAa,CAClBC,gBAAgB,CAACa,IAAD,EAAO;AAAEO,IAAAA,gBAAgB,EAAE;AAApB,GAAP,CADE,EAElB;AAAEA,IAAAA,gBAAgB,EAAE,IAApB;AAA0BD,IAAAA,MAAM,EAANA;AAA1B,GAFkB,CAApB,CA/C8C,CAoD9C;;AACA,MAAIhB,OAAO,CAACkB,aAAZ,EAA2B;AACzBR,IAAAA,IAAI,GAAGV,OAAO,CAACkB,aAAR,CAAsBR,IAAtB,CAAP,CADyB,CAEzB;AACA;AACA;AACA;AACA;AACD;;AAED,SAAOA,IAAP;AACD","sourcesContent":["import dropEmptyRows from './dropEmptyRows'\r\nimport dropEmptyColumns from './dropEmptyColumns'\r\n\r\nexport default function getData(sheet, options) {\r\n const { dimensions, cells } = sheet\r\n\r\n // If the sheet is empty.\r\n if (cells.length === 0) {\r\n return []\r\n }\r\n\r\n const [leftTop, rightBottom] = dimensions\r\n\r\n const colsCount = (rightBottom.column - leftTop.column) + 1\r\n const rowsCount = (rightBottom.row - leftTop.row) + 1\r\n\r\n // Initialize spreadsheet data structure.\r\n let data = new Array(rowsCount)\r\n let i = 0\r\n while (i < rowsCount) {\r\n data[i] = new Array(colsCount)\r\n let j = 0\r\n while (j < colsCount) {\r\n data[i][j] = null\r\n j++\r\n }\r\n i++\r\n }\r\n\r\n // Fill in spreadsheet data structure.\r\n // (this code implies that `cells` aren't necessarily sorted by row and column:\r\n // maybe that's not correct, this piece code was initially copy-pasted\r\n // from some other library that used `XPath`)\r\n for (const cell of cells) {\r\n const row = cell.row - leftTop.row\r\n const column = cell.column - leftTop.column\r\n data[row][column] = cell.value\r\n }\r\n\r\n // Fill in the row map.\r\n const { rowMap } = options\r\n if (rowMap) {\r\n let i = 0\r\n while (i < data.length) {\r\n rowMap[i] = i\r\n i++\r\n }\r\n }\r\n\r\n // Drop empty columns or rows.\r\n data = dropEmptyRows(\r\n dropEmptyColumns(data, { onlyTrimAtTheEnd: true }),\r\n { onlyTrimAtTheEnd: true, rowMap }\r\n )\r\n\r\n // Optionally transform data before applying `schema`.\r\n if (options.transformData) {\r\n data = options.transformData(data)\r\n // data = options.transformData(data, {\r\n // dropEmptyRowsAndColumns(data) {\r\n // return dropEmptyRows(dropEmptyColumns(data), { rowMap })\r\n // }\r\n // })\r\n }\r\n\r\n return data\r\n}"],"file":"getData.js"}
@@ -0,0 +1,59 @@
1
+ import parseCellValue from './parseCellValue';
2
+ import { parseCellCoordinates } from './coordinates';
3
+ import { getCellValue, getCellInlineStringValue } from '../xml/xlsx'; // Example of a `<c/>`ell element:
4
+ //
5
+ // <c>
6
+ // <f>string</f> — formula.
7
+ // <v>string</v> — formula pre-computed value.
8
+ // <is>
9
+ // <t>string</t> — an `inlineStr` string (rather than a "common string" from a dictionary).
10
+ // <r>
11
+ // <rPr>
12
+ // ...
13
+ // </rPr>
14
+ // <t>string</t>
15
+ // </r>
16
+ // <rPh sb="1" eb="1">
17
+ // <t>string</t>
18
+ // </rPh>
19
+ // <phoneticPr fontId="1"/>
20
+ // </is>
21
+ // <extLst>
22
+ // <ext>
23
+ // <!--any element-->
24
+ // </ext>
25
+ // </extLst>
26
+ // </c>
27
+ //
28
+
29
+ export default function parseCell(node, sheet, xml, values, styles, properties, options) {
30
+ var coords = parseCellCoordinates(node.getAttribute('r'));
31
+ var valueElement = getCellValue(sheet, node); // For `xpath`, `value` can be `undefined` while for native `DOMParser` it's `null`.
32
+ // So using `value && ...` instead of `if (value !== undefined) { ... }` here
33
+ // for uniform compatibility with both `xpath` and native `DOMParser`.
34
+
35
+ var value = valueElement && valueElement.textContent;
36
+ var type;
37
+
38
+ if (node.hasAttribute('t')) {
39
+ type = node.getAttribute('t');
40
+ }
41
+
42
+ return {
43
+ row: coords[0],
44
+ column: coords[1],
45
+ value: parseCellValue(value, type, {
46
+ getInlineStringValue: function getInlineStringValue() {
47
+ return getCellInlineStringValue(sheet, node);
48
+ },
49
+ getStyleId: function getStyleId() {
50
+ return node.getAttribute('s');
51
+ },
52
+ styles: styles,
53
+ values: values,
54
+ properties: properties,
55
+ options: options
56
+ })
57
+ };
58
+ }
59
+ //# sourceMappingURL=parseCell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../source/read/parseCell.js"],"names":["parseCellValue","parseCellCoordinates","getCellValue","getCellInlineStringValue","parseCell","node","sheet","xml","values","styles","properties","options","coords","getAttribute","valueElement","value","textContent","type","hasAttribute","row","column","getInlineStringValue","getStyleId"],"mappings":"AAAA,OAAOA,cAAP,MAA2B,kBAA3B;AAEA,SACEC,oBADF,QAEO,eAFP;AAIA,SACEC,YADF,EAEEC,wBAFF,QAGO,aAHP,C,CAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,SAAT,CAAmBC,IAAnB,EAAyBC,KAAzB,EAAgCC,GAAhC,EAAqCC,MAArC,EAA6CC,MAA7C,EAAqDC,UAArD,EAAiEC,OAAjE,EAA0E;AACvF,MAAMC,MAAM,GAAGX,oBAAoB,CAACI,IAAI,CAACQ,YAAL,CAAkB,GAAlB,CAAD,CAAnC;AAEA,MAAMC,YAAY,GAAGZ,YAAY,CAACI,KAAD,EAAQD,IAAR,CAAjC,CAHuF,CAKvF;AACA;AACA;;AACA,MAAIU,KAAK,GAAGD,YAAY,IAAIA,YAAY,CAACE,WAAzC;AAEA,MAAIC,IAAJ;;AACA,MAAIZ,IAAI,CAACa,YAAL,CAAkB,GAAlB,CAAJ,EAA4B;AAC1BD,IAAAA,IAAI,GAAGZ,IAAI,CAACQ,YAAL,CAAkB,GAAlB,CAAP;AACD;;AAED,SAAO;AACLM,IAAAA,GAAG,EAAEP,MAAM,CAAC,CAAD,CADN;AAELQ,IAAAA,MAAM,EAAER,MAAM,CAAC,CAAD,CAFT;AAGLG,IAAAA,KAAK,EAAEf,cAAc,CAACe,KAAD,EAAQE,IAAR,EAAc;AACjCI,MAAAA,oBAAoB,EAAE;AAAA,eAAMlB,wBAAwB,CAACG,KAAD,EAAQD,IAAR,CAA9B;AAAA,OADW;AAEjCiB,MAAAA,UAAU,EAAE;AAAA,eAAMjB,IAAI,CAACQ,YAAL,CAAkB,GAAlB,CAAN;AAAA,OAFqB;AAGjCJ,MAAAA,MAAM,EAANA,MAHiC;AAIjCD,MAAAA,MAAM,EAANA,MAJiC;AAKjCE,MAAAA,UAAU,EAAVA,UALiC;AAMjCC,MAAAA,OAAO,EAAPA;AANiC,KAAd;AAHhB,GAAP;AAYD","sourcesContent":["import parseCellValue from './parseCellValue'\r\n\r\nimport {\r\n parseCellCoordinates\r\n} from './coordinates'\r\n\r\nimport {\r\n getCellValue,\r\n getCellInlineStringValue\r\n} from '../xml/xlsx'\r\n\r\n// Example of a `<c/>`ell element:\r\n//\r\n// <c>\r\n// <f>string</f> — formula.\r\n// <v>string</v> — formula pre-computed value.\r\n// <is>\r\n// <t>string</t> — an `inlineStr` string (rather than a \"common string\" from a dictionary).\r\n// <r>\r\n// <rPr>\r\n// ...\r\n// </rPr>\r\n// <t>string</t>\r\n// </r>\r\n// <rPh sb=\"1\" eb=\"1\">\r\n// <t>string</t>\r\n// </rPh>\r\n// <phoneticPr fontId=\"1\"/>\r\n// </is>\r\n// <extLst>\r\n// <ext>\r\n// <!--any element-->\r\n// </ext>\r\n// </extLst>\r\n// </c>\r\n//\r\nexport default function parseCell(node, sheet, xml, values, styles, properties, options) {\r\n const coords = parseCellCoordinates(node.getAttribute('r'))\r\n\r\n const valueElement = getCellValue(sheet, node)\r\n\r\n // For `xpath`, `value` can be `undefined` while for native `DOMParser` it's `null`.\r\n // So using `value && ...` instead of `if (value !== undefined) { ... }` here\r\n // for uniform compatibility with both `xpath` and native `DOMParser`.\r\n let value = valueElement && valueElement.textContent\r\n\r\n let type\r\n if (node.hasAttribute('t')) {\r\n type = node.getAttribute('t')\r\n }\r\n\r\n return {\r\n row: coords[0],\r\n column: coords[1],\r\n value: parseCellValue(value, type, {\r\n getInlineStringValue: () => getCellInlineStringValue(sheet, node),\r\n getStyleId: () => node.getAttribute('s'),\r\n styles,\r\n values,\r\n properties,\r\n options\r\n })\r\n }\r\n}"],"file":"parseCell.js"}
@@ -0,0 +1,192 @@
1
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
2
+
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+
5
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6
+
7
+ import parseDate from './parseDate'; // https://hexdocs.pm/xlsxir/number_styles.html
8
+
9
+ var BUILT_IN_DATE_NUMBER_FORMAT_IDS = [14, 15, 16, 17, 18, 19, 20, 21, 22, 27, 30, 36, 45, 46, 47, 50, 57];
10
+ export default function getCellValue(value, type, _ref) {
11
+ var getInlineStringValue = _ref.getInlineStringValue,
12
+ getStyleId = _ref.getStyleId,
13
+ styles = _ref.styles,
14
+ values = _ref.values,
15
+ properties = _ref.properties,
16
+ options = _ref.options;
17
+
18
+ if (!type) {
19
+ // Default cell type is "n" (numeric).
20
+ // http://www.datypic.com/sc/ooxml/t-ssml_CT_Cell.html
21
+ type = 'n';
22
+ } // Available Excel cell types:
23
+ // https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md
24
+ //
25
+ // Some other document (seems to be old):
26
+ // http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/ST_CellType.html
27
+ //
28
+
29
+
30
+ switch (type) {
31
+ // If the cell contains formula string.
32
+ case 'str':
33
+ value = value.trim();
34
+
35
+ if (value === '') {
36
+ value = undefined;
37
+ }
38
+
39
+ break;
40
+ // If the cell contains an "inline" (not "shared") string.
41
+
42
+ case 'inlineStr':
43
+ value = getInlineStringValue();
44
+
45
+ if (value === undefined) {
46
+ throw new Error("Unsupported \"inline string\" cell value structure"); // : ${cellNode.textContent}`)
47
+ }
48
+
49
+ value = value.trim();
50
+
51
+ if (value === '') {
52
+ value = undefined;
53
+ }
54
+
55
+ break;
56
+ // If the cell contains a "shared" string.
57
+ // "Shared" strings is a way for an Excel editor to reduce
58
+ // the file size by storing "commonly used" strings in a dictionary
59
+ // and then referring to such strings by their index in that dictionary.
60
+
61
+ case 's':
62
+ // If a cell has no value then there's no `<c/>` element for it.
63
+ // If a `<c/>` element exists then it's not empty.
64
+ // The `<v/>`alue is a key in the "shared strings" dictionary of the
65
+ // XLSX file, so look it up in the `values` dictionary by the numeric key.
66
+ value = values[parseInt(value)];
67
+ value = value.trim();
68
+
69
+ if (value === '') {
70
+ value = undefined;
71
+ }
72
+
73
+ break;
74
+
75
+ case 'b':
76
+ value = value === '1' ? true : false;
77
+ break;
78
+ // Stub: blank stub cell that is ignored by data processing utilities.
79
+
80
+ case 'z':
81
+ value = undefined;
82
+ break;
83
+ // Error: `value` is a numeric code.
84
+ // They also wrote: "and `w` property stores its common name".
85
+ // It's unclear what they meant by that.
86
+
87
+ case 'e':
88
+ value = decodeError(value);
89
+ break;
90
+ // Date: a string to be parsed as a date.
91
+ // (usually a string in "ISO 8601" format)
92
+
93
+ case 'd':
94
+ if (value === undefined) {
95
+ break;
96
+ }
97
+
98
+ value = new Date(value);
99
+ break;
100
+
101
+ case 'n':
102
+ if (value === undefined) {
103
+ break;
104
+ }
105
+
106
+ value = parseFloat(value); // XLSX does have "d" type for dates, but it's not commonly used.
107
+ // specific format for dates.
108
+ // Sometimes a date can be heuristically detected.
109
+ // https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777
110
+ //
111
+ // Format IDs:
112
+ // https://xlsxwriter.readthedocs.io/format.html#format-set-num-format
113
+ //
114
+
115
+ var styleId = getStyleId();
116
+
117
+ if (styleId) {
118
+ // styleId = parseInt(styleId)
119
+ var style = styles[styleId];
120
+
121
+ if (!style) {
122
+ throw new Error("Cell style not found: ".concat(styleId));
123
+ }
124
+
125
+ if (BUILT_IN_DATE_NUMBER_FORMAT_IDS.indexOf(parseInt(style.numberFormat.id)) >= 0 || options.dateFormat && style.numberFormat.template === options.dateFormat || options.smartDateParser !== false && style.numberFormat.template && isDateTemplate(style.numberFormat.template)) {
126
+ value = parseDate(value, properties);
127
+ }
128
+ }
129
+
130
+ break;
131
+
132
+ default:
133
+ throw new TypeError("Cell type not supported: ".concat(type));
134
+ } // Convert empty values to `null`.
135
+
136
+
137
+ if (value === undefined) {
138
+ value = null;
139
+ }
140
+
141
+ return value;
142
+ } // Decodes numeric error code to a string code.
143
+ // https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md
144
+
145
+ function decodeError(errorCode) {
146
+ // While the error values are determined by the application,
147
+ // the following are some example error values that could be used:
148
+ switch (errorCode) {
149
+ case 0x00:
150
+ return '#NULL!';
151
+
152
+ case 0x07:
153
+ return '#DIV/0!';
154
+
155
+ case 0x0F:
156
+ return '#VALUE!';
157
+
158
+ case 0x17:
159
+ return '#REF!';
160
+
161
+ case 0x1D:
162
+ return '#NAME?';
163
+
164
+ case 0x24:
165
+ return '#NUM!';
166
+
167
+ case 0x2A:
168
+ return '#N/A';
169
+
170
+ case 0x2B:
171
+ return '#GETTING_DATA';
172
+
173
+ default:
174
+ // Such error code doesn't exist. I made it up.
175
+ return "#ERROR_".concat(errorCode);
176
+ }
177
+ }
178
+
179
+ function isDateTemplate(template) {
180
+ var tokens = template.split(/\W+/);
181
+
182
+ for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) {
183
+ var token = _step.value;
184
+
185
+ if (['MM', 'DD', 'YY', 'YYYY'].indexOf(token) < 0) {
186
+ return false;
187
+ }
188
+ }
189
+
190
+ return true;
191
+ }
192
+ //# sourceMappingURL=parseCellValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../source/read/parseCellValue.js"],"names":["parseDate","BUILT_IN_DATE_NUMBER_FORMAT_IDS","getCellValue","value","type","getInlineStringValue","getStyleId","styles","values","properties","options","trim","undefined","Error","parseInt","decodeError","Date","parseFloat","styleId","style","indexOf","numberFormat","id","dateFormat","template","smartDateParser","isDateTemplate","TypeError","errorCode","tokens","split","token"],"mappings":";;;;;;AAAA,OAAOA,SAAP,MAAsB,aAAtB,C,CAEA;;AACA,IAAMC,+BAA+B,GAAG,CAAC,EAAD,EAAI,EAAJ,EAAO,EAAP,EAAU,EAAV,EAAa,EAAb,EAAgB,EAAhB,EAAmB,EAAnB,EAAsB,EAAtB,EAAyB,EAAzB,EAA4B,EAA5B,EAA+B,EAA/B,EAAkC,EAAlC,EAAqC,EAArC,EAAwC,EAAxC,EAA2C,EAA3C,EAA8C,EAA9C,EAAiD,EAAjD,CAAxC;AAEA,eAAe,SAASC,YAAT,CAAsBC,KAAtB,EAA6BC,IAA7B,QAOZ;AAAA,MANFC,oBAME,QANFA,oBAME;AAAA,MALFC,UAKE,QALFA,UAKE;AAAA,MAJFC,MAIE,QAJFA,MAIE;AAAA,MAHFC,MAGE,QAHFA,MAGE;AAAA,MAFFC,UAEE,QAFFA,UAEE;AAAA,MADFC,OACE,QADFA,OACE;;AACD,MAAI,CAACN,IAAL,EAAW;AACT;AACA;AACAA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AO,OAAP;;AACF,SAAK,IAAL;AACE,aAAO,MAAP;;AACF,SAAK,IAAL;AACE,aAAO,eAAP;;AACF;AACE;AACA,8BAAiBA,SAAjB;AAnBJ;AAqBD;;AAED,SAASF,cAAT,CAAwBF,QAAxB,EAAkC;AAChC,MAAMK,MAAM,GAAGL,QAAQ,CAACM,KAAT,CAAe,KAAf,CAAf;;AACA,uDAAoBD,MAApB,wCAA4B;AAAA,QAAjBE,KAAiB;;AAC1B,QAAI,CAAC,IAAD,EAAO,IAAP,EAAa,IAAb,EAAmB,MAAnB,EAA2BX,OAA3B,CAAmCW,KAAnC,IAA4C,CAAhD,EAAmD;AACjD,aAAO,KAAP;AACD;AACF;;AACD,SAAO,IAAP;AACD","sourcesContent":["import parseDate from './parseDate'\r\n\r\n// https://hexdocs.pm/xlsxir/number_styles.html\r\nconst BUILT_IN_DATE_NUMBER_FORMAT_IDS = [14,15,16,17,18,19,20,21,22,27,30,36,45,46,47,50,57]\r\n\r\nexport default function getCellValue(value, type, {\r\n\tgetInlineStringValue,\r\n\tgetStyleId,\r\n\tstyles,\r\n\tvalues,\r\n\tproperties,\r\n\toptions\r\n}) {\r\n if (!type) {\r\n // Default cell type is \"n\" (numeric).\r\n // http://www.datypic.com/sc/ooxml/t-ssml_CT_Cell.html\r\n type = 'n'\r\n }\r\n\r\n // Available Excel cell types:\r\n // https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md\r\n //\r\n // Some other document (seems to be old):\r\n // http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/ST_CellType.html\r\n //\r\n switch (type) {\r\n // If the cell contains formula string.\r\n case 'str':\r\n value = value.trim()\r\n if (value === '') {\r\n value = undefined\r\n }\r\n break\r\n\r\n // If the cell contains an \"inline\" (not \"shared\") string.\r\n case 'inlineStr':\r\n value = getInlineStringValue()\r\n if (value === undefined) {\r\n throw new Error(`Unsupported \"inline string\" cell value structure`) // : ${cellNode.textContent}`)\r\n }\r\n value = value.trim()\r\n if (value === '') {\r\n value = undefined\r\n }\r\n break\r\n\r\n // If the cell contains a \"shared\" string.\r\n // \"Shared\" strings is a way for an Excel editor to reduce\r\n // the file size by storing \"commonly used\" strings in a dictionary\r\n // and then referring to such strings by their index in that dictionary.\r\n case 's':\r\n // If a cell has no value then there's no `<c/>` element for it.\r\n // If a `<c/>` element exists then it's not empty.\r\n // The `<v/>`alue is a key in the \"shared strings\" dictionary of the\r\n // XLSX file, so look it up in the `values` dictionary by the numeric key.\r\n value = values[parseInt(value)]\r\n value = value.trim()\r\n if (value === '') {\r\n value = undefined\r\n }\r\n break\r\n\r\n case 'b':\r\n value = value === '1' ? true : false\r\n break\r\n\r\n // Stub: blank stub cell that is ignored by data processing utilities.\r\n case 'z':\r\n value = undefined\r\n break\r\n\r\n // Error: `value` is a numeric code.\r\n // They also wrote: \"and `w` property stores its common name\".\r\n // It's unclear what they meant by that.\r\n case 'e':\r\n value = decodeError(value)\r\n break\r\n\r\n // Date: a string to be parsed as a date.\r\n // (usually a string in \"ISO 8601\" format)\r\n case 'd':\r\n if (value === undefined) {\r\n break\r\n }\r\n value = new Date(value)\r\n break\r\n\r\n case 'n':\r\n if (value === undefined) {\r\n break\r\n }\r\n value = parseFloat(value)\r\n // XLSX does have \"d\" type for dates, but it's not commonly used.\r\n // specific format for dates.\r\n // Sometimes a date can be heuristically detected.\r\n // https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777\r\n //\r\n // Format IDs:\r\n // https://xlsxwriter.readthedocs.io/format.html#format-set-num-format\r\n //\r\n const styleId = getStyleId()\r\n if (styleId) {\r\n // styleId = parseInt(styleId)\r\n const style = styles[styleId]\r\n if (!style) {\r\n throw new Error(`Cell style not found: ${styleId}`)\r\n }\r\n if (BUILT_IN_DATE_NUMBER_FORMAT_IDS.indexOf(parseInt(style.numberFormat.id)) >= 0 ||\r\n (options.dateFormat && style.numberFormat.template === options.dateFormat) ||\r\n (options.smartDateParser !== false && style.numberFormat.template && isDateTemplate(style.numberFormat.template))) {\r\n value = parseDate(value, properties)\r\n }\r\n }\r\n break\r\n\r\n default:\r\n throw new TypeError(`Cell type not supported: ${type}`)\r\n }\r\n\r\n // Convert empty values to `null`.\r\n if (value === undefined) {\r\n value = null\r\n }\r\n\r\n return value\r\n}\r\n\r\n// Decodes numeric error code to a string code.\r\n// https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md\r\nfunction decodeError(errorCode) {\r\n // While the error values are determined by the application,\r\n // the following are some example error values that could be used:\r\n switch (errorCode) {\r\n case 0x00:\r\n return '#NULL!'\r\n case 0x07:\r\n return '#DIV/0!'\r\n case 0x0F:\r\n return '#VALUE!'\r\n case 0x17:\r\n return '#REF!'\r\n case 0x1D:\r\n return '#NAME?'\r\n case 0x24:\r\n return '#NUM!'\r\n case 0x2A:\r\n return '#N/A'\r\n case 0x2B:\r\n return '#GETTING_DATA'\r\n default:\r\n // Such error code doesn't exist. I made it up.\r\n return `#ERROR_${errorCode}`\r\n }\r\n}\r\n\r\nfunction isDateTemplate(template) {\r\n const tokens = template.split(/\\W+/)\r\n for (const token of tokens) {\r\n if (['MM', 'DD', 'YY', 'YYYY'].indexOf(token) < 0) {\r\n return false\r\n }\r\n }\r\n return true\r\n}\r\n"],"file":"parseCellValue.js"}
@@ -0,0 +1,19 @@
1
+ import parseCell from './parseCell';
2
+ import { getCells, getMergedCells } from '../xml/xlsx';
3
+ export default function parseCells(sheet, xml, values, styles, properties, options) {
4
+ var cells = getCells(sheet);
5
+
6
+ if (cells.length === 0) {
7
+ return [];
8
+ } // const mergedCells = getMergedCells(sheet)
9
+ // for (const mergedCell of mergedCells) {
10
+ // const [from, to] = mergedCell.split(':').map(parseCellCoordinates)
11
+ // console.log('Merged Cell.', 'From:', from, 'To:', to)
12
+ // }
13
+
14
+
15
+ return cells.map(function (node) {
16
+ return parseCell(node, sheet, xml, values, styles, properties, options);
17
+ });
18
+ }
19
+ //# sourceMappingURL=parseCells.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../source/read/parseCells.js"],"names":["parseCell","getCells","getMergedCells","parseCells","sheet","xml","values","styles","properties","options","cells","length","map","node"],"mappings":"AAAA,OAAOA,SAAP,MAAsB,aAAtB;AAEA,SACEC,QADF,EAEEC,cAFF,QAGO,aAHP;AAKA,eAAe,SAASC,UAAT,CAAoBC,KAApB,EAA2BC,GAA3B,EAAgCC,MAAhC,EAAwCC,MAAxC,EAAgDC,UAAhD,EAA4DC,OAA5D,EAAqE;AAClF,MAAMC,KAAK,GAAGT,QAAQ,CAACG,KAAD,CAAtB;;AAEA,MAAIM,KAAK,CAACC,MAAN,KAAiB,CAArB,EAAwB;AACtB,WAAO,EAAP;AACD,GALiF,CAOlF;AACA;AACA;AACA;AACA;;;AAEA,SAAOD,KAAK,CAACE,GAAN,CAAU,UAACC,IAAD,EAAU;AACzB,WAAOb,SAAS,CAACa,IAAD,EAAOT,KAAP,EAAcC,GAAd,EAAmBC,MAAnB,EAA2BC,MAA3B,EAAmCC,UAAnC,EAA+CC,OAA/C,CAAhB;AACD,GAFM,CAAP;AAGD","sourcesContent":["import parseCell from './parseCell'\r\n\r\nimport {\r\n getCells,\r\n getMergedCells\r\n} from '../xml/xlsx'\r\n\r\nexport default function parseCells(sheet, xml, values, styles, properties, options) {\r\n const cells = getCells(sheet)\r\n\r\n if (cells.length === 0) {\r\n return []\r\n }\r\n\r\n // const mergedCells = getMergedCells(sheet)\r\n // for (const mergedCell of mergedCells) {\r\n // const [from, to] = mergedCell.split(':').map(parseCellCoordinates)\r\n // console.log('Merged Cell.', 'From:', from, 'To:', to)\r\n // }\r\n\r\n return cells.map((node) => {\r\n return parseCell(node, sheet, xml, values, styles, properties, options)\r\n })\r\n}"],"file":"parseCells.js"}
@@ -0,0 +1,38 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+
5
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
+
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
8
+
9
+ function _iterableToArrayLimit(arr, i) { var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]); if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
10
+
11
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
+
13
+ import { parseCellCoordinates } from './coordinates';
14
+ import { getDimensions } from '../xml/xlsx';
15
+ export default function parseDimensions(sheet) {
16
+ var dimensions = getDimensions(sheet);
17
+
18
+ if (dimensions) {
19
+ dimensions = dimensions.split(':').map(parseCellCoordinates).map(function (_ref) {
20
+ var _ref2 = _slicedToArray(_ref, 2),
21
+ row = _ref2[0],
22
+ column = _ref2[1];
23
+
24
+ return {
25
+ row: row,
26
+ column: column
27
+ };
28
+ }); // When there's only a single cell on a sheet
29
+ // there can sometimes be just "A1" for the dimensions string.
30
+
31
+ if (dimensions.length === 1) {
32
+ dimensions = [dimensions[0], dimensions[0]];
33
+ }
34
+
35
+ return dimensions;
36
+ }
37
+ }
38
+ //# sourceMappingURL=parseDimensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../source/read/parseDimensions.js"],"names":["parseCellCoordinates","getDimensions","parseDimensions","sheet","dimensions","split","map","row","column","length"],"mappings":";;;;;;;;;;;;AAAA,SACEA,oBADF,QAEO,eAFP;AAIA,SACEC,aADF,QAEO,aAFP;AAIA,eAAe,SAASC,eAAT,CAAyBC,KAAzB,EAAgC;AAC7C,MAAIC,UAAU,GAAGH,aAAa,CAACE,KAAD,CAA9B;;AACA,MAAIC,UAAJ,EAAgB;AACdA,IAAAA,UAAU,GAAGA,UAAU,CAACC,KAAX,CAAiB,GAAjB,EAAsBC,GAAtB,CAA0BN,oBAA1B,EAAgDM,GAAhD,CAAoD;AAAA;AAAA,UAAEC,GAAF;AAAA,UAAOC,MAAP;;AAAA,aAAoB;AACnFD,QAAAA,GAAG,EAAHA,GADmF;AAEnFC,QAAAA,MAAM,EAANA;AAFmF,OAApB;AAAA,KAApD,CAAb,CADc,CAKd;AACA;;AACA,QAAIJ,UAAU,CAACK,MAAX,KAAsB,CAA1B,EAA6B;AAC3BL,MAAAA,UAAU,GAAG,CAACA,UAAU,CAAC,CAAD,CAAX,EAAgBA,UAAU,CAAC,CAAD,CAA1B,CAAb;AACD;;AACD,WAAOA,UAAP;AACD;AACF","sourcesContent":["import {\r\n parseCellCoordinates\r\n} from './coordinates'\r\n\r\nimport {\r\n getDimensions\r\n} from '../xml/xlsx'\r\n\r\nexport default function parseDimensions(sheet) {\r\n let dimensions = getDimensions(sheet)\r\n if (dimensions) {\r\n dimensions = dimensions.split(':').map(parseCellCoordinates).map(([row, column]) => ({\r\n row,\r\n column\r\n }))\r\n // When there's only a single cell on a sheet\r\n // there can sometimes be just \"A1\" for the dimensions string.\r\n if (dimensions.length === 1) {\r\n dimensions = [dimensions[0], dimensions[0]]\r\n }\r\n return dimensions\r\n }\r\n}\r\n\r\n"],"file":"parseDimensions.js"}
@@ -0,0 +1,76 @@
1
+ import { getRelationships } from '../xml/xlsx';
2
+ /**
3
+ * Returns sheet file paths.
4
+ * Seems that the correct place to look for the `sheetId` -> `filename` mapping
5
+ * is `xl/_rels/workbook.xml.rels` file.
6
+ * https://github.com/tidyverse/readxl/issues/104
7
+ * @param {string} content — `xl/_rels/workbook.xml.rels` file contents.
8
+ * @param {object} xml
9
+ * @return {object}
10
+ */
11
+
12
+ export default function parseFilePaths(content, xml) {
13
+ // Example:
14
+ // <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
15
+ // ...
16
+ // <Relationship
17
+ // Id="rId3"
18
+ // Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
19
+ // Target="worksheets/sheet1.xml"/>
20
+ // </Relationships>
21
+ var document = xml.createDocument(content);
22
+ var filePaths = {
23
+ sheets: {},
24
+ sharedStrings: undefined,
25
+ styles: undefined
26
+ };
27
+
28
+ var addFilePathInfo = function addFilePathInfo(relationship) {
29
+ var filePath = relationship.getAttribute('Target');
30
+ var fileType = relationship.getAttribute('Type');
31
+
32
+ switch (fileType) {
33
+ case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles':
34
+ filePaths.styles = getFilePath(filePath);
35
+ break;
36
+
37
+ case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings':
38
+ filePaths.sharedStrings = getFilePath(filePath);
39
+ break;
40
+
41
+ case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet':
42
+ filePaths.sheets[relationship.getAttribute('Id')] = getFilePath(filePath);
43
+ break;
44
+ }
45
+ };
46
+
47
+ getRelationships(document).forEach(addFilePathInfo); // Seems like "sharedStrings.xml" is not required to exist.
48
+ // For example, when the spreadsheet doesn't contain any strings.
49
+ // https://github.com/catamphetamine/read-excel-file/issues/85
50
+ // if (!filePaths.sharedStrings) {
51
+ // throw new Error('"sharedStrings.xml" file not found in the *.xlsx file')
52
+ // }
53
+
54
+ return filePaths;
55
+ }
56
+
57
+ function getFilePath(path) {
58
+ // Normally, `path` is a relative path inside the ZIP archive,
59
+ // like "worksheets/sheet1.xml", or "sharedStrings.xml", or "styles.xml".
60
+ // There has been one weird case when file path was an absolute path,
61
+ // like "/xl/worksheets/sheet1.xml" (specifically for sheets):
62
+ // https://github.com/catamphetamine/read-excel-file/pull/95
63
+ // Other libraries (like `xlsx`) and software (like Google Docs)
64
+ // seem to support such absolute file paths, so this library does too.
65
+ if (path[0] === '/') {
66
+ return path.slice('/'.length);
67
+ } // // Seems like a path could also be a URL.
68
+ // // http://officeopenxml.com/anatomyofOOXML-xlsx.php
69
+ // if (/^[a-z]+\:\/\//.test(path)) {
70
+ // return path
71
+ // }
72
+
73
+
74
+ return 'xl/' + path;
75
+ }
76
+ //# sourceMappingURL=parseFilePaths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../source/read/parseFilePaths.js"],"names":["getRelationships","parseFilePaths","content","xml","document","createDocument","filePaths","sheets","sharedStrings","undefined","styles","addFilePathInfo","relationship","filePath","getAttribute","fileType","getFilePath","forEach","path","slice","length"],"mappings":"AAAA,SACEA,gBADF,QAEO,aAFP;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,cAAT,CAAwBC,OAAxB,EAAiCC,GAAjC,EAAsC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAQ,GAAGD,GAAG,CAACE,cAAJ,CAAmBH,OAAnB,CAAjB;AAEA,MAAMI,SAAS,GAAG;AAChBC,IAAAA,MAAM,EAAE,EADQ;AAEhBC,IAAAA,aAAa,EAAEC,SAFC;AAGhBC,IAAAA,MAAM,EAAED;AAHQ,GAAlB;;AAMA,MAAME,eAAe,GAAG,SAAlBA,eAAkB,CAACC,YAAD,EAAkB;AACxC,QAAMC,QAAQ,GAAGD,YAAY,CAACE,YAAb,CAA0B,QAA1B,CAAjB;AACA,QAAMC,QAAQ,GAAGH,YAAY,CAACE,YAAb,CAA0B,MAA1B,CAAjB;;AACA,YAAQC,QAAR;AACE,WAAK,4EAAL;AACET,QAAAA,SAAS,CAACI,MAAV,GAAmBM,WAAW,CAACH,QAAD,CAA9B;AACA;;AACF,WAAK,mFAAL;AACEP,QAAAA,SAAS,CAACE,aAAV,GAA0BQ,WAAW,CAACH,QAAD,CAArC;AACA;;AACF,WAAK,+EAAL;AACEP,QAAAA,SAAS,CAACC,MAAV,CAAiBK,YAAY,CAACE,YAAb,CAA0B,IAA1B,CAAjB,IAAoDE,WAAW,CAACH,QAAD,CAA/D;AACA;AATJ;AAWD,GAdD;;AAgBAb,EAAAA,gBAAgB,CAACI,QAAD,CAAhB,CAA2Ba,OAA3B,CAAmCN,eAAnC,EAjCmD,CAmCnD;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAOL,SAAP;AACD;;AAED,SAASU,WAAT,CAAqBE,IAArB,EAA2B;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAIA,IAAI,CAAC,CAAD,CAAJ,KAAY,GAAhB,EAAqB;AACnB,WAAOA,IAAI,CAACC,KAAL,CAAW,IAAIC,MAAf,CAAP;AACD,GAVwB,CAWzB;AACA;AACA;AACA;AACA;;;AACA,SAAO,QAAQF,IAAf;AACD","sourcesContent":["import {\r\n getRelationships\r\n} from '../xml/xlsx'\r\n\r\n/**\r\n * Returns sheet file paths.\r\n * Seems that the correct place to look for the `sheetId` -> `filename` mapping\r\n * is `xl/_rels/workbook.xml.rels` file.\r\n * https://github.com/tidyverse/readxl/issues/104\r\n * @param {string} content — `xl/_rels/workbook.xml.rels` file contents.\r\n * @param {object} xml\r\n * @return {object}\r\n */\r\nexport default function parseFilePaths(content, xml) {\r\n // Example:\r\n // <Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\r\n // ...\r\n // <Relationship\r\n // Id=\"rId3\"\r\n // Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet\"\r\n // Target=\"worksheets/sheet1.xml\"/>\r\n // </Relationships>\r\n const document = xml.createDocument(content)\r\n\r\n const filePaths = {\r\n sheets: {},\r\n sharedStrings: undefined,\r\n styles: undefined\r\n }\r\n\r\n const addFilePathInfo = (relationship) => {\r\n const filePath = relationship.getAttribute('Target')\r\n const fileType = relationship.getAttribute('Type')\r\n switch (fileType) {\r\n case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles':\r\n filePaths.styles = getFilePath(filePath)\r\n break\r\n case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings':\r\n filePaths.sharedStrings = getFilePath(filePath)\r\n break\r\n case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet':\r\n filePaths.sheets[relationship.getAttribute('Id')] = getFilePath(filePath)\r\n break\r\n }\r\n }\r\n\r\n getRelationships(document).forEach(addFilePathInfo)\r\n\r\n // Seems like \"sharedStrings.xml\" is not required to exist.\r\n // For example, when the spreadsheet doesn't contain any strings.\r\n // https://github.com/catamphetamine/read-excel-file/issues/85\r\n // if (!filePaths.sharedStrings) {\r\n // throw new Error('\"sharedStrings.xml\" file not found in the *.xlsx file')\r\n // }\r\n\r\n return filePaths\r\n}\r\n\r\nfunction getFilePath(path) {\r\n // Normally, `path` is a relative path inside the ZIP archive,\r\n // like \"worksheets/sheet1.xml\", or \"sharedStrings.xml\", or \"styles.xml\".\r\n // There has been one weird case when file path was an absolute path,\r\n // like \"/xl/worksheets/sheet1.xml\" (specifically for sheets):\r\n // https://github.com/catamphetamine/read-excel-file/pull/95\r\n // Other libraries (like `xlsx`) and software (like Google Docs)\r\n // seem to support such absolute file paths, so this library does too.\r\n if (path[0] === '/') {\r\n return path.slice('/'.length)\r\n }\r\n // // Seems like a path could also be a URL.\r\n // // http://officeopenxml.com/anatomyofOOXML-xlsx.php\r\n // if (/^[a-z]+\\:\\/\\//.test(path)) {\r\n // return path\r\n // }\r\n return 'xl/' + path\r\n}"],"file":"parseFilePaths.js"}