read-excel-file 9.3.3 → 9.3.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.
Files changed (255) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +32 -2
  3. package/browser/index.cjs +3 -0
  4. package/browser/index.d.ts +16 -0
  5. package/browser/index.js +4 -1
  6. package/bundle/read-excel-file.min.js +1 -1
  7. package/bundle/read-excel-file.min.js.map +1 -1
  8. package/commonjs/export/convertInputToNodeStream.js +0 -12
  9. package/commonjs/export/convertInputToNodeStream.js.map +1 -1
  10. package/commonjs/export/parseSheet.js +14 -7
  11. package/commonjs/export/parseSheet.js.map +1 -1
  12. package/commonjs/export/readSheetBrowser.js +3 -6
  13. package/commonjs/export/readSheetBrowser.js.map +1 -1
  14. package/commonjs/export/readSheetNode.js +3 -6
  15. package/commonjs/export/readSheetNode.js.map +1 -1
  16. package/commonjs/export/readSheetUniversal.js +2 -2
  17. package/commonjs/export/readSheetUniversal.js.map +1 -1
  18. package/commonjs/export/readSheetWebWorker.js +5 -5
  19. package/commonjs/export/readSheetWebWorker.js.map +1 -1
  20. package/commonjs/export/readXlsxFileBrowser.js +3 -6
  21. package/commonjs/export/readXlsxFileBrowser.js.map +1 -1
  22. package/commonjs/export/readXlsxFileNode.js +3 -6
  23. package/commonjs/export/readXlsxFileNode.js.map +1 -1
  24. package/commonjs/export/readXlsxFileUniversal.js +2 -2
  25. package/commonjs/export/readXlsxFileUniversal.js.map +1 -1
  26. package/commonjs/export/readXlsxFileWebWorker.js +5 -5
  27. package/commonjs/export/readXlsxFileWebWorker.js.map +1 -1
  28. package/commonjs/export/unpackXlsxFileBrowser.js +15 -4
  29. package/commonjs/export/unpackXlsxFileBrowser.js.map +1 -1
  30. package/commonjs/export/unpackXlsxFileBrowser.test.js.map +1 -0
  31. package/commonjs/export/unpackXlsxFileNode.js +32 -5
  32. package/commonjs/export/unpackXlsxFileNode.js.map +1 -1
  33. package/commonjs/export/unpackXlsxFileNode.test.js.map +1 -0
  34. package/commonjs/export/unpackXlsxFileUniversal.js +14 -3
  35. package/commonjs/export/unpackXlsxFileUniversal.js.map +1 -1
  36. package/commonjs/export/unpackXlsxFileUniversal.test.js.map +1 -0
  37. package/commonjs/parseSheetData/parseSheetData.js +9 -6
  38. package/commonjs/parseSheetData/parseSheetData.js.map +1 -1
  39. package/commonjs/saxen/parser.js +1 -1
  40. package/commonjs/saxen/parser.js.map +1 -1
  41. package/commonjs/utility/convertValuesFromUint8ArraysToStrings.js +100 -0
  42. package/commonjs/utility/convertValuesFromUint8ArraysToStrings.js.map +1 -0
  43. package/commonjs/xlsx/InvalidSpreadsheetError.js +55 -0
  44. package/commonjs/xlsx/InvalidSpreadsheetError.js.map +1 -0
  45. package/commonjs/xlsx/SheetNotFoundError.js +55 -0
  46. package/commonjs/xlsx/SheetNotFoundError.js.map +1 -0
  47. package/commonjs/xlsx/file/InputValidationStream.js +101 -0
  48. package/commonjs/xlsx/file/InputValidationStream.js.map +1 -0
  49. package/commonjs/xlsx/file/InputValidationStream.test.js.map +1 -0
  50. package/commonjs/xlsx/file/InvalidInputError.js +105 -0
  51. package/commonjs/xlsx/file/InvalidInputError.js.map +1 -0
  52. package/commonjs/xlsx/file/createFileTypeDetector.js +70 -0
  53. package/commonjs/xlsx/file/createFileTypeDetector.js.map +1 -0
  54. package/commonjs/xlsx/file/createFileTypeDetector.test.js.map +1 -0
  55. package/commonjs/xlsx/file/validateLeadingBytes.js +47 -0
  56. package/commonjs/xlsx/file/validateLeadingBytes.js.map +1 -0
  57. package/commonjs/xlsx/file/validateLeadingBytes.test.js.map +1 -0
  58. package/commonjs/xlsx/isDateFormat.js +32 -27
  59. package/commonjs/xlsx/isDateFormat.js.map +1 -1
  60. package/commonjs/xlsx/isDateFormatStyle.js +19 -21
  61. package/commonjs/xlsx/isDateFormatStyle.js.map +1 -1
  62. package/commonjs/xlsx/parseCell.js +252 -115
  63. package/commonjs/xlsx/parseCell.js.map +1 -1
  64. package/commonjs/xlsx/parseCellAddress.js +22 -18
  65. package/commonjs/xlsx/parseCellAddress.js.map +1 -1
  66. package/commonjs/xlsx/parseExcelDate.js +4 -124
  67. package/commonjs/xlsx/parseExcelDate.js.map +1 -1
  68. package/commonjs/xlsx/parseExcelDate.test.js.map +1 -1
  69. package/commonjs/xlsx/parseExcelTimestamp.js +139 -0
  70. package/commonjs/xlsx/parseExcelTimestamp.js.map +1 -0
  71. package/commonjs/xlsx/parseFilePaths.js +48 -47
  72. package/commonjs/xlsx/parseFilePaths.js.map +1 -1
  73. package/commonjs/xlsx/parseSharedStrings.js +91 -36
  74. package/commonjs/xlsx/parseSharedStrings.js.map +1 -1
  75. package/commonjs/xlsx/parseSheet.js +527 -69
  76. package/commonjs/xlsx/parseSheet.js.map +1 -1
  77. package/commonjs/xlsx/parseSpreadsheetContents.js +154 -83
  78. package/commonjs/xlsx/parseSpreadsheetContents.js.map +1 -1
  79. package/commonjs/xlsx/parseSpreadsheetInfo.js +60 -59
  80. package/commonjs/xlsx/parseSpreadsheetInfo.js.map +1 -1
  81. package/commonjs/xlsx/parseStyles.js +75 -75
  82. package/commonjs/xlsx/parseStyles.js.map +1 -1
  83. package/commonjs/xml/parseXml.js +112 -0
  84. package/commonjs/xml/parseXml.js.map +1 -0
  85. package/commonjs/xml/parseXml.test.js.map +1 -0
  86. package/commonjs/xml/parseXmlStream.js.map +1 -1
  87. package/commonjs/xml/parseXmlStream.sax.js +69 -28
  88. package/commonjs/xml/parseXmlStream.sax.js.map +1 -1
  89. package/commonjs/xml/parseXmlStream.saxen.js +66 -40
  90. package/commonjs/xml/parseXmlStream.saxen.js.map +1 -1
  91. package/commonjs/zip/UnzipError.js +55 -0
  92. package/commonjs/zip/UnzipError.js.map +1 -0
  93. package/commonjs/zip/unzipFromArrayBuffer.js +21 -1
  94. package/commonjs/zip/unzipFromArrayBuffer.js.map +1 -1
  95. package/commonjs/zip/unzipFromArrayBuffer.test.js.map +1 -0
  96. package/commonjs/zip/unzipFromStream.fflate.js +43 -35
  97. package/commonjs/zip/unzipFromStream.fflate.js.map +1 -1
  98. package/commonjs/zip/unzipFromStream.js +188 -6
  99. package/commonjs/zip/unzipFromStream.js.map +1 -1
  100. package/commonjs/zip/unzipFromStream.unzipper.js +19 -34
  101. package/commonjs/zip/unzipFromStream.unzipper.js.map +1 -1
  102. package/modules/export/convertInputToNodeStream.js +0 -12
  103. package/modules/export/convertInputToNodeStream.js.map +1 -1
  104. package/modules/export/parseSheet.js +13 -6
  105. package/modules/export/parseSheet.js.map +1 -1
  106. package/modules/export/readSheetBrowser.js +3 -5
  107. package/modules/export/readSheetBrowser.js.map +1 -1
  108. package/modules/export/readSheetNode.js +3 -5
  109. package/modules/export/readSheetNode.js.map +1 -1
  110. package/modules/export/readSheetUniversal.js +2 -2
  111. package/modules/export/readSheetUniversal.js.map +1 -1
  112. package/modules/export/readSheetWebWorker.js +7 -8
  113. package/modules/export/readSheetWebWorker.js.map +1 -1
  114. package/modules/export/readXlsxFileBrowser.js +3 -5
  115. package/modules/export/readXlsxFileBrowser.js.map +1 -1
  116. package/modules/export/readXlsxFileNode.js +3 -5
  117. package/modules/export/readXlsxFileNode.js.map +1 -1
  118. package/modules/export/readXlsxFileUniversal.js +2 -2
  119. package/modules/export/readXlsxFileUniversal.js.map +1 -1
  120. package/modules/export/readXlsxFileWebWorker.js +7 -8
  121. package/modules/export/readXlsxFileWebWorker.js.map +1 -1
  122. package/modules/export/unpackXlsxFileBrowser.js +15 -4
  123. package/modules/export/unpackXlsxFileBrowser.js.map +1 -1
  124. package/modules/export/unpackXlsxFileBrowser.test.js.map +1 -0
  125. package/modules/export/unpackXlsxFileNode.js +32 -5
  126. package/modules/export/unpackXlsxFileNode.js.map +1 -1
  127. package/modules/export/unpackXlsxFileNode.test.js.map +1 -0
  128. package/modules/export/unpackXlsxFileUniversal.js +14 -3
  129. package/modules/export/unpackXlsxFileUniversal.js.map +1 -1
  130. package/modules/export/unpackXlsxFileUniversal.test.js.map +1 -0
  131. package/modules/parseSheetData/parseSheetData.js +9 -6
  132. package/modules/parseSheetData/parseSheetData.js.map +1 -1
  133. package/modules/saxen/parser.js +1 -1
  134. package/modules/saxen/parser.js.map +1 -1
  135. package/modules/utility/convertValuesFromUint8ArraysToStrings.js +92 -0
  136. package/modules/utility/convertValuesFromUint8ArraysToStrings.js.map +1 -0
  137. package/modules/xlsx/InvalidSpreadsheetError.js +50 -0
  138. package/modules/xlsx/InvalidSpreadsheetError.js.map +1 -0
  139. package/modules/xlsx/SheetNotFoundError.js +50 -0
  140. package/modules/xlsx/SheetNotFoundError.js.map +1 -0
  141. package/modules/xlsx/file/InputValidationStream.js +96 -0
  142. package/modules/xlsx/file/InputValidationStream.js.map +1 -0
  143. package/modules/xlsx/file/InputValidationStream.test.js.map +1 -0
  144. package/modules/xlsx/file/InvalidInputError.js +100 -0
  145. package/modules/xlsx/file/InvalidInputError.js.map +1 -0
  146. package/modules/xlsx/file/createFileTypeDetector.js +63 -0
  147. package/modules/xlsx/file/createFileTypeDetector.js.map +1 -0
  148. package/modules/xlsx/file/createFileTypeDetector.test.js.map +1 -0
  149. package/modules/xlsx/file/validateLeadingBytes.js +37 -0
  150. package/modules/xlsx/file/validateLeadingBytes.js.map +1 -0
  151. package/modules/xlsx/file/validateLeadingBytes.test.js.map +1 -0
  152. package/modules/xlsx/isDateFormat.js +31 -27
  153. package/modules/xlsx/isDateFormat.js.map +1 -1
  154. package/modules/xlsx/isDateFormatStyle.js +18 -21
  155. package/modules/xlsx/isDateFormatStyle.js.map +1 -1
  156. package/modules/xlsx/parseCell.js +251 -111
  157. package/modules/xlsx/parseCell.js.map +1 -1
  158. package/modules/xlsx/parseCellAddress.js +21 -18
  159. package/modules/xlsx/parseCellAddress.js.map +1 -1
  160. package/modules/xlsx/parseExcelDate.js +4 -124
  161. package/modules/xlsx/parseExcelDate.js.map +1 -1
  162. package/modules/xlsx/parseExcelDate.test.js.map +1 -1
  163. package/modules/xlsx/parseExcelTimestamp.js +133 -0
  164. package/modules/xlsx/parseExcelTimestamp.js.map +1 -0
  165. package/modules/xlsx/parseFilePaths.js +48 -47
  166. package/modules/xlsx/parseFilePaths.js.map +1 -1
  167. package/modules/xlsx/parseSharedStrings.js +91 -37
  168. package/modules/xlsx/parseSharedStrings.js.map +1 -1
  169. package/modules/xlsx/parseSheet.js +526 -68
  170. package/modules/xlsx/parseSheet.js.map +1 -1
  171. package/modules/xlsx/parseSpreadsheetContents.js +153 -81
  172. package/modules/xlsx/parseSpreadsheetContents.js.map +1 -1
  173. package/modules/xlsx/parseSpreadsheetInfo.js +60 -59
  174. package/modules/xlsx/parseSpreadsheetInfo.js.map +1 -1
  175. package/modules/xlsx/parseStyles.js +75 -75
  176. package/modules/xlsx/parseStyles.js.map +1 -1
  177. package/modules/xml/parseXml.js +106 -0
  178. package/modules/xml/parseXml.js.map +1 -0
  179. package/modules/xml/parseXml.test.js.map +1 -0
  180. package/modules/xml/parseXmlStream.js +2 -0
  181. package/modules/xml/parseXmlStream.js.map +1 -1
  182. package/modules/xml/parseXmlStream.sax.js +69 -28
  183. package/modules/xml/parseXmlStream.sax.js.map +1 -1
  184. package/modules/xml/parseXmlStream.saxen.js +67 -40
  185. package/modules/xml/parseXmlStream.saxen.js.map +1 -1
  186. package/modules/zip/UnzipError.js +49 -0
  187. package/modules/zip/UnzipError.js.map +1 -0
  188. package/modules/zip/unzipFromArrayBuffer.js +21 -1
  189. package/modules/zip/unzipFromArrayBuffer.js.map +1 -1
  190. package/modules/zip/unzipFromArrayBuffer.test.js.map +1 -0
  191. package/modules/zip/unzipFromStream.fflate.js +41 -35
  192. package/modules/zip/unzipFromStream.fflate.js.map +1 -1
  193. package/modules/zip/unzipFromStream.js +124 -1
  194. package/modules/zip/unzipFromStream.js.map +1 -1
  195. package/modules/zip/unzipFromStream.unzipper.js +19 -35
  196. package/modules/zip/unzipFromStream.unzipper.js.map +1 -1
  197. package/node/index.cjs +3 -0
  198. package/node/index.d.ts +16 -0
  199. package/node/index.js +3 -0
  200. package/package.json +5 -3
  201. package/types/InvalidInputError.d.ts +16 -0
  202. package/types/InvalidSpreadsheetError.d.ts +4 -0
  203. package/types/SheetNotFoundError.d.ts +4 -0
  204. package/universal/index.cjs +3 -0
  205. package/universal/index.d.ts +16 -0
  206. package/universal/index.js +3 -0
  207. package/web-worker/index.cjs +3 -0
  208. package/web-worker/index.d.ts +16 -0
  209. package/web-worker/index.js +3 -0
  210. package/commonjs/export/convertValuesFromUint8ArraysToStrings.js +0 -23
  211. package/commonjs/export/convertValuesFromUint8ArraysToStrings.js.map +0 -1
  212. package/commonjs/xlsx/convertCellsToData2dArray.js +0 -84
  213. package/commonjs/xlsx/convertCellsToData2dArray.js.map +0 -1
  214. package/commonjs/xlsx/dropEmptyColumns.js +0 -40
  215. package/commonjs/xlsx/dropEmptyColumns.js.map +0 -1
  216. package/commonjs/xlsx/dropEmptyColumns.test.js.map +0 -1
  217. package/commonjs/xlsx/dropEmptyRows.js +0 -43
  218. package/commonjs/xlsx/dropEmptyRows.js.map +0 -1
  219. package/commonjs/xlsx/dropEmptyRows.test.js.map +0 -1
  220. package/commonjs/xlsx/parseCellValue.js +0 -186
  221. package/commonjs/xlsx/parseCellValue.js.map +0 -1
  222. package/commonjs/xlsx/parseNumber.js +0 -20
  223. package/commonjs/xlsx/parseNumber.js.map +0 -1
  224. package/commonjs/xlsx/parseSharedString.js +0 -64
  225. package/commonjs/xlsx/parseSharedString.js.map +0 -1
  226. package/commonjs/xlsx/parseSheetData.js +0 -68
  227. package/commonjs/xlsx/parseSheetData.js.map +0 -1
  228. package/commonjs/xlsx/reconstructSheetDimensionsFromSheetCells.js +0 -29
  229. package/commonjs/xlsx/reconstructSheetDimensionsFromSheetCells.js.map +0 -1
  230. package/commonjs/xml/parseXmlStream.saxen.code.js +0 -953
  231. package/commonjs/xml/parseXmlStream.saxen.code.js.map +0 -1
  232. package/commonjs/xml/parseXmlStream.test.js.map +0 -1
  233. package/modules/export/convertValuesFromUint8ArraysToStrings.js +0 -17
  234. package/modules/export/convertValuesFromUint8ArraysToStrings.js.map +0 -1
  235. package/modules/xlsx/convertCellsToData2dArray.js +0 -77
  236. package/modules/xlsx/convertCellsToData2dArray.js.map +0 -1
  237. package/modules/xlsx/dropEmptyColumns.js +0 -34
  238. package/modules/xlsx/dropEmptyColumns.js.map +0 -1
  239. package/modules/xlsx/dropEmptyColumns.test.js.map +0 -1
  240. package/modules/xlsx/dropEmptyRows.js +0 -37
  241. package/modules/xlsx/dropEmptyRows.js.map +0 -1
  242. package/modules/xlsx/dropEmptyRows.test.js.map +0 -1
  243. package/modules/xlsx/parseCellValue.js +0 -180
  244. package/modules/xlsx/parseCellValue.js.map +0 -1
  245. package/modules/xlsx/parseNumber.js +0 -14
  246. package/modules/xlsx/parseNumber.js.map +0 -1
  247. package/modules/xlsx/parseSharedString.js +0 -55
  248. package/modules/xlsx/parseSharedString.js.map +0 -1
  249. package/modules/xlsx/parseSheetData.js +0 -55
  250. package/modules/xlsx/parseSheetData.js.map +0 -1
  251. package/modules/xlsx/reconstructSheetDimensionsFromSheetCells.js +0 -23
  252. package/modules/xlsx/reconstructSheetDimensionsFromSheetCells.js.map +0 -1
  253. package/modules/xml/parseXmlStream.saxen.code.js +0 -947
  254. package/modules/xml/parseXmlStream.saxen.code.js.map +0 -1
  255. package/modules/xml/parseXmlStream.test.js.map +0 -1
@@ -5,101 +5,559 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports["default"] = parseSheet;
8
- var _parseSheetData = _interopRequireWildcard(require("./parseSheetData.js"));
9
- var _parseCellAddress = _interopRequireDefault(require("./parseCellAddress.js"));
10
- var _reconstructSheetDimensionsFromSheetCells = _interopRequireDefault(require("./reconstructSheetDimensionsFromSheetCells.js"));
11
- var _convertCellsToData2dArray = _interopRequireDefault(require("./convertCellsToData2dArray.js"));
8
+ var _parseCell = _interopRequireWildcard(require("./parseCell.js"));
9
+ var _parseCellAddress3 = _interopRequireDefault(require("./parseCellAddress.js"));
10
+ var _InvalidSpreadsheetError = _interopRequireDefault(require("./InvalidSpreadsheetError.js"));
12
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
12
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
13
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
14
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
16
15
  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."); }
17
- 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); }
18
- 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; }
19
16
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
20
17
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
+ 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."); }
19
+ 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); }
20
+ 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; }
21
+ // An empty cell has `null` value.
22
+ var EMPTY_CELL_VALUE = null;
23
+
21
24
  /**
22
25
  * Parses a `sheet.xml` file.
23
26
  * @param {string} content
24
- * @param {function} parseXmlStream — SAX XML parser.
27
+ * @param {function} parseXml — SAX XML parser.
25
28
  * @param {object} options
26
29
  * @returns {Promise<SheetData>}
27
30
  */
28
- function parseSheet(content, parseXmlStream, _ref) {
31
+ function parseSheet(content, parseXml, _ref) {
29
32
  var sharedStrings = _ref.sharedStrings,
30
33
  styles = _ref.styles,
31
34
  epoch1904 = _ref.epoch1904,
32
35
  options = _ref.options;
33
- // When XML parser is finished, it returns a `state`
34
- // where it has accumulated the cells it encountered during parsing.
35
- // `getSheetData()` function reads the parser `state` and transforms it to `SheetData`.
36
- var getSheetData = function getSheetData(state) {
37
- var cells = (0, _parseSheetData["default"])(state.sheetData, sharedStrings, styles, epoch1904, options);
38
- var dimensions = state.dimension ? parseSheetDimensionRef(state.dimension) : (0, _reconstructSheetDimensionsFromSheetCells["default"])(cells);
39
- return (0, _convertCellsToData2dArray["default"])(cells, dimensions);
40
- };
41
- return parseXmlStream(content, {
42
- createInitialState: createInitialStateInSheet,
43
- onOpenTag: onOpenTagInSheet,
44
- onCloseTag: onCloseTagInSheet,
45
- onText: onTextInSheet
46
- }).then(function (state) {
47
- return getSheetData(state);
36
+ var parseCellParameters = [sharedStrings, styles, epoch1904, options.dateFormat,
37
+ // defaultDateFormat
38
+ options.smartDateParser !== false,
39
+ // dateTemplateParser
40
+ options.parseNumber // parseNumberCustom
41
+ ];
42
+
43
+ var rows = [];
44
+ var errors = [];
45
+ var state = createInitialState();
46
+ return parseXml(content, state, onOpenTag, onCloseTag, onText, onProgress).then(function () {
47
+ var _state$sheetData = state.sheetData,
48
+ rowCount = _state$sheetData.rowCount,
49
+ columnCount = _state$sheetData.columnCount,
50
+ dataRowCount = _state$sheetData.dataRowCount,
51
+ dataColumnCount = _state$sheetData.dataColumnCount;
52
+ // Drop (discard) empty rows at the bottom.
53
+ if (dataRowCount < rowCount) {
54
+ rows = rows.slice(0, dataRowCount);
55
+ }
56
+ // Drop (discard) empty columns at the right side.
57
+ if (dataColumnCount < columnCount) {
58
+ var i = 0;
59
+ while (i < rows.length) {
60
+ if (rows[i].length > dataColumnCount) {
61
+ rows[i] = rows[i].slice(0, dataColumnCount);
62
+ }
63
+ i++;
64
+ }
65
+ }
66
+ var startedAt = Date.now();
67
+ // Add `null` values where there're "gaps" at the right side of rows.
68
+ for (var _iterator = _createForOfIteratorHelperLoose(rows), _step; !(_step = _iterator()).done;) {
69
+ var row = _step.value;
70
+ while (row.length < dataColumnCount) {
71
+ row.push(EMPTY_CELL_VALUE);
72
+ }
73
+ }
74
+ return rows;
48
75
  });
49
- }
50
- function createInitialStateInSheet() {
51
- return {
52
- dimension: undefined,
53
- sheetData: undefined
54
- };
55
- }
56
- function onOpenTagInSheet(tagName, attributes, state) {
57
- if (tagName === 'dimension') {
58
- state.dimension = attributes.ref;
59
- } else if (tagName === 'sheetData') {
60
- state.sheetData = (0, _parseSheetData.createInitialStateInSheetData)();
61
- } else if (state.sheetData) {
62
- (0, _parseSheetData.onOpenTagInSheetData)(tagName, attributes, state.sheetData);
76
+ function createInitialState() {
77
+ return {
78
+ dimension: undefined,
79
+ sheetData: undefined
80
+ };
63
81
  }
64
- }
65
- function onCloseTagInSheet(tagName, state) {
66
- if (state.sheetData) {
67
- (0, _parseSheetData.onCloseTagInSheetData)(tagName, state.sheetData);
82
+ function getRowsFromState(state) {
83
+ return state.sheetData.rows;
68
84
  }
69
- }
70
- function onTextInSheet(text, state) {
71
- if (state.sheetData) {
72
- (0, _parseSheetData.onTextInSheetData)(text, state.sheetData);
85
+ function setRowsInState(state, rows) {
86
+ state.sheetData.rowIndexShift += state.sheetData.rows.length - rows.length;
87
+ state.sheetData.rows = rows;
88
+ }
89
+ function getErrorsFromState(state) {
90
+ return state.sheetData.errors;
91
+ }
92
+ function setErrorsInState(state, errors) {
93
+ state.sheetData.errors = errors;
73
94
  }
74
- }
75
95
 
76
- /**
77
- * Sheet "dimension" defines the spreadsheet area containing all non-empty cells.
78
- * Any cells outside the "dimension" are considered empty and should be ignored.
79
- * https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1
80
- * @param {string} `ref` — The value of `<dimension ref/>` attribute.
81
- * @returns {object[]} `undefined` or `[{ row, column }, { row, column }]` — "From row number and column number to row number and column number".
82
- */
83
- function parseSheetDimensionRef(ref) {
84
- var dimensions = ref.split(':').map(_parseCellAddress["default"]).map(function (_ref2) {
85
- var _ref3 = _slicedToArray(_ref2, 2),
86
- row = _ref3[0],
87
- column = _ref3[1];
96
+ // Throw an error as soon as a non-recoverable error is encountered when parsing a cell.
97
+ var THROW_ON_FIRST_CELL_ERROR = true;
98
+ function throwInvalidCellError(_ref2) {
99
+ var row = _ref2.row,
100
+ column = _ref2.column,
101
+ error = _ref2.error;
102
+ // The sheet name or index is unknown, so it's not reported here.
103
+ throw new _InvalidSpreadsheetError["default"]("<c/> at row ".concat(row, ", col ").concat(column, ": ").concat(error));
104
+ }
105
+ function onProgress(end) {
106
+ // Here, it could look at `state.dimension?` in order to avoid reading unused cells.
107
+ // For example, there could be a sheet with a million rows and a million columns
108
+ // but only the top-left cell in that sheet would be not an empty cell.
109
+ // The rest of the cells could be empty, but it would be valid for such sheet to exist.
110
+ // So there would be empty `<row/>` or `<c/>` elements all around, and those could be skipped
111
+ // if `<dimension/>` element is present in the `sheet.xml` file.
112
+ // The `<dimension/>` element tells which area of the sheet really contains non-empty data.
113
+ // But it's an optional element, and also there's an additional question of:
114
+ // "What should happen if an .xlsx writer sets it erroneously? Should it auto-repair such sheet?".
115
+ // I imagine, such situations aren't really possible in real life but still mathematically it's possible,
116
+ // because the `<dimension/>` element is more of a "supplementary" or "advisory" one
117
+ // and it's not supposed to "break" anything in case its value is incorrect.
118
+ // So that's why `read-excel-file` just simply ignores the `<dimension/>` element
119
+ // even though it can read and "understand" it.
120
+ // console.log(state.dimension)
121
+ var rowsRead = getRowsFromState(state);
122
+ var errorsEncountered = getErrorsFromState(state);
123
+ if (end) {
124
+ rows = rows.concat(rowsRead);
125
+ errors = errors.concat(errorsEncountered);
126
+ if (errors.length > 0) {
127
+ throwInvalidCellError(errors[0]);
128
+ }
129
+ } else {
130
+ if (rowsRead.length > 1) {
131
+ // The rows except for the last one have already been "finalized",
132
+ // i.e. it can be said that those rows don't have any more cells yet to be parsed.
133
+ // The last row is still being read so it's not "finalized" yet,
134
+ // i.e. it's unknown at this point whether there will be more cells of it.
135
+ var finalizedRows = rowsRead.slice(0, -1);
136
+ // Move the finalized rows from the "in-progress" rows to the "result" rows.
137
+ rows = rows.concat(finalizedRows);
138
+ // Add any errors that have been encountered while parsing this chunk of rows.
139
+ errors = errors.concat(errorsEncountered);
140
+ // Proceeed with just the last row and the next chunk.
141
+ setRowsInState(state, rowsRead.slice(-1));
142
+ // Proceeed with clean errors list.
143
+ setErrorsInState(state, []);
144
+ }
145
+ }
146
+ }
147
+ function onOpenTag(tagName, attributes, state) {
148
+ if (tagName === 'dimension') {
149
+ state.dimension = parseSheetDimensionRef(attributes.ref);
150
+ } else if (tagName === 'sheetData') {
151
+ state.sheetData = createInitialStateInSheetData();
152
+ } else if (state.sheetData) {
153
+ onOpenTagInSheetData(tagName, attributes, state.sheetData);
154
+ }
155
+ }
156
+ function onCloseTag(tagName, state) {
157
+ if (state.sheetData) {
158
+ onCloseTagInSheetData(tagName, state.sheetData);
159
+ }
160
+ }
161
+ function onText(text, state) {
162
+ if (state.sheetData) {
163
+ onTextInSheetData(text, state.sheetData);
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Sheet "dimension" defines the spreadsheet area containing all non-empty cells.
169
+ * Any cells outside the "dimension" are considered empty and should be ignored.
170
+ * https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1
171
+ * @param {string} `ref` — The value of `<dimension ref/>` attribute.
172
+ * @returns {[[number,number],[number,number]]} `undefined` or `[{ row, column }, { row, column }]` — "From row number and column number to row number and column number".
173
+ */
174
+ function parseSheetDimensionRef(ref) {
175
+ var dimensions = ref.split(':').map(_parseCellAddress3["default"]);
176
+ // Sometimes there can be just a single cell as a spreadsheet's "dimensions".
177
+ // For example, the default "dimensions" in Apache POI library is "A1",
178
+ // meaning that only the first cell in the spreadsheet is used.
179
+ //
180
+ // A quote from Apache POI library:
181
+ // "Single cell ranges are formatted like single cell references (e.g. 'A1' instead of 'A1:A1')."
182
+ //
183
+ if (dimensions.length === 1) {
184
+ dimensions = [dimensions[0], dimensions[0]];
185
+ }
186
+ return dimensions;
187
+ }
188
+
189
+ // Sheet Data
190
+
191
+ function createInitialStateInSheetData() {
192
+ return {
193
+ c: undefined,
194
+ rows: [],
195
+ row: undefined,
196
+ rowNumber: undefined,
197
+ // How many rows have been removed from the start of `state.rows`
198
+ // as part of `onProgress()` handler calls.
199
+ rowIndexShift: 0,
200
+ // Current position in the sheet.
201
+ cursor: [0, 0],
202
+ // Total row count.
203
+ rowCount: 0,
204
+ // Total column count.
205
+ columnCount: 0,
206
+ // Non-empty row count.
207
+ dataRowCount: 0,
208
+ // Non-empty column count.
209
+ dataColumnCount: 0,
210
+ // Cell with errors.
211
+ errors: []
212
+ };
213
+ }
214
+ function onOpenTagInSheetData(tagName, attributes, state) {
215
+ if (tagName === 'row') {
216
+ // Read an optional `r` attribute, which represents a 1-based row number.
217
+ // If the `r` attribute is not present on a `<row>` then the row number is either defined by
218
+ // `<c>` elements in it, or just assumed to be "previous row number + 1".
219
+ if (attributes.r) {
220
+ state.rowNumber = Number(attributes.r);
221
+ }
222
+ state.row = [];
223
+ } else if (tagName === 'c') {
224
+ state.c = createInitialStateInCell();
225
+ state.c.attributes = attributes;
226
+ } else if (state.c) {
227
+ onOpenTagInCell(tagName, attributes, state.c);
228
+ }
229
+ }
230
+ function onCloseTagInSheetData(tagName, state) {
231
+ if (tagName === 'row') {
232
+ // If the row number is known, check for any inter-row gaps that it might introduce.
233
+ if (state.rowNumber) {
234
+ // Google AI says that `<row>` elements must be ordered by row number ascending,
235
+ // so the code assumes that there can't be an out-of-order `<row>`.
236
+ var previousRowNumber = state.rowIndexShift + state.rows.length;
237
+ if (state.rowNumber <= previousRowNumber) {
238
+ throw new _InvalidSpreadsheetError["default"]("Out-of-place <row/> number ".concat(state.rowNumber, " follows <row/> number ").concat(previousRowNumber));
239
+ }
240
+ // Insert empty rows where there're gaps between the rows.
241
+ while (state.rowNumber > state.rowIndexShift + state.rows.length + 1) {
242
+ state.rows.push([]);
243
+ }
244
+ }
245
+ // Add the parsed row to the list of rows.
246
+ state.rows.push(state.row);
247
+ // Update the total non-empty row count.
248
+ if (state.row.length > 0) {
249
+ state.dataRowCount = state.rowNumber;
250
+ }
251
+ // Update the total row count.
252
+ if (state.rowNumber > state.rowCount) {
253
+ state.rowCount = state.rowNumber;
254
+ }
255
+ // Reset state.
256
+ state.row = undefined;
257
+ state.rowNumber = undefined;
258
+ } else if (tagName === 'c') {
259
+ var cell = parseCellFromXmlData(state.c);
260
+ // Google AI says that the Open XML specification (ISO/IEC 29500) strictly dictates
261
+ // that `<c>` elements within `sheet.xml` (or specifically `<sheetData>`)
262
+ // must be written in ascending order of their `r` attributes (e.g., "A1", "B1", "C1").
263
+ if (cell.row < state.cursor[0] || cell.row === state.cursor[0] && cell.column <= state.cursor[1]) {
264
+ throw new _InvalidSpreadsheetError["default"]("Out-of-place <c/> at row ".concat(cell.row, " col ").concat(cell.column, " follows <c/> at row ").concat(state.cursor[0], " col ").concat(state.cursor[1]));
265
+ }
266
+ // Update the cursor.
267
+ state.cursor[0] = cell.row;
268
+ state.cursor[1] = cell.column;
269
+ // If the `r` attribute is not present on a `<row>` then the row number is either defined by
270
+ // `<c>` elements in it, or just assumed to be "previous row number + 1".
271
+ if (!state.rowNumber) {
272
+ state.rowNumber = cell.row;
273
+ }
274
+ // If the cell has an error.
275
+ if (cell.error) {
276
+ if (THROW_ON_FIRST_CELL_ERROR) {
277
+ throwInvalidCellError(cell);
278
+ }
279
+ state.errors.push(cell);
280
+ }
281
+ // If the cell is not empty.
282
+ else if (cell.value !== EMPTY_CELL_VALUE) {
283
+ // Insert empty cells where there're gaps between the columns.
284
+ while (cell.column > state.row.length + 1) {
285
+ state.row.push(EMPTY_CELL_VALUE);
286
+ }
287
+ // Add the parsed cell value to the list of cell values in the current row.
288
+ state.row.push(cell.value);
289
+ // Update the total non-empty column count.
290
+ if (cell.column > state.dataColumnCount) {
291
+ state.dataColumnCount = cell.column;
292
+ }
293
+ }
294
+ // Update the total column count.
295
+ if (cell.column > state.columnCount) {
296
+ state.columnCount = cell.column;
297
+ }
298
+ // Reset state.
299
+ state.c = undefined;
300
+ } else if (state.c) {
301
+ onCloseTagInCell(tagName, state.c);
302
+ }
303
+ }
304
+ function onTextInSheetData(text, state) {
305
+ if (state.c) {
306
+ onTextInCell(text, state.c);
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Parses the XML values of a `<c/>` element into an object representing a cell value.
312
+ * @param {object} — `{ attributes: Record<string,string>, inlineString?: string, vText?: string }`. If `<v/>` element is present but is empty, `vText` will be an empty string. If `<v/>` element is absent, `vText` will be `undefined`.
313
+ * @returns {object} Either `{ row: number, column: number, error: string }` or `{ row: number, column: number, value: string|number|boolean|null }`
314
+ */
315
+ function parseCellFromXmlData(_ref3) {
316
+ var attributes = _ref3.attributes,
317
+ inlineString = _ref3.inlineString,
318
+ vText = _ref3.vText;
319
+ var _parseCellAddress = (0, _parseCellAddress3["default"])(attributes.r),
320
+ _parseCellAddress2 = _slicedToArray(_parseCellAddress, 2),
321
+ row = _parseCellAddress2[0],
322
+ column = _parseCellAddress2[1];
323
+ var errorOrTypeAndValue = parseCellAndTrimValue(attributes.t, attributes.s, vText, inlineString, parseCellParameters, options.trim !== false);
324
+ if (typeof errorOrTypeAndValue === 'string') {
325
+ return {
326
+ row: row,
327
+ column: column,
328
+ error: errorOrTypeAndValue
329
+ // // Report the "raw" unparsed value of the cell for potential debugging.
330
+ // // Also report the cell type and the format in case of a numeric value.
331
+ // //
332
+ // // For "inline string" cells, the value should actually be the `inlineString` argument
333
+ // // rather than `vText` argument, but the only case when it could throw an error
334
+ // // when parsing an "inline string" cell is `VALUE_MISSING` which means that
335
+ // // `inlineString` argument is `undefined`, same as `vText` argument in this case,
336
+ // // so the resulting `value` property is correct anyway.
337
+ // //
338
+ // value: vText,
339
+ // type: attributes.t,
340
+ // formatId: attributes.s
341
+ };
342
+ }
343
+
88
344
  return {
89
345
  row: row,
90
- column: column
346
+ column: column,
347
+ value: parseCellValue(errorOrTypeAndValue[1], errorOrTypeAndValue[0])
91
348
  };
92
- });
93
- // Sometimes there can be just a single cell as a spreadsheet's "dimensions".
94
- // For example, the default "dimensions" in Apache POI library is "A1",
95
- // meaning that only the first cell in the spreadsheet is used.
96
- //
97
- // A quote from Apache POI library:
98
- // "Single cell ranges are formatted like single cell references (e.g. 'A1' instead of 'A1:A1')."
349
+ }
350
+
351
+ // Here, it could also parse "merged cells" and then return them in some special way.
352
+ // But then it's not clear what should be the way to return such merged cells.
353
+ // I.e. should it just return it as a duplicate value in each one of the merged cells?
354
+ // Or should it keep the current behavior of only returning the value of the top-most left-most cell
355
+ // and then just return `null` for the rest of the cells in a "merged cells" group?
356
+ // Perhaps the latter (current) approach is the most sensible one, so there's no need
357
+ // to change anything.
99
358
  //
100
- if (dimensions.length === 1) {
101
- dimensions = [dimensions[0], dimensions[0]];
359
+ // const mergedCells = getMergedCellCoordinates(sheetDocument)
360
+ // for (const mergedCell of mergedCells) {
361
+ // const [from, to] = mergedCell.split(':').map(parseCellAddress)
362
+ // console.log('Merged Cell.', 'From:', from, 'To:', to)
363
+ // }
364
+
365
+ // Cell
366
+
367
+ /**
368
+ * Parses a cell from the info extracted from the cell XML.
369
+ * If the cell is of type string, it trims the value (by default).
370
+ *
371
+ * Receives same arguments as `parseCell()` function, with an additional argument
372
+ * `trimStrings: boolean` which tells if it should trim any string values.
373
+ *
374
+ * Produces same result as `parseCell()` function, except for cells of type "e".
375
+ */
376
+ function parseCellAndTrimValue(t, s, v, inlineString, parameters, trimStrings) {
377
+ // Parse cell value from cell XML.
378
+ var errorOrTypeAndValue = parseCellWithRepairAbility(t, s, v, inlineString, parameters);
379
+ // Trim any text cell values (by default)
380
+ if (Array.isArray(errorOrTypeAndValue) && errorOrTypeAndValue[0] === 's') {
381
+ // A developer could optionally disable the automatic trimming of all strings.
382
+ // For example, leading spaces might express a tree-like hierarchy, in which case they should be preserved.
383
+ // https://github.com/catamphetamine/read-excel-file/pull/106#issuecomment-1136062917
384
+ if (trimStrings) {
385
+ errorOrTypeAndValue[1] = errorOrTypeAndValue[1].trim();
386
+ }
387
+ // Convert empty strings to `null`
388
+ if (errorOrTypeAndValue[1] === '') {
389
+ return _parseCell.EMPTY_CELL;
390
+ }
391
+ }
392
+ // Return the cell's type and value.
393
+ return errorOrTypeAndValue;
394
+ }
395
+
396
+ /**
397
+ * Parses cell value and optionally repairs any repairable errors.
398
+ * Receives same arguments as `parseCell()` function.
399
+ * Produces same result as `parseCell()` function, except for cells of type "e".
400
+ */
401
+ function parseCellWithRepairAbility(t, s, v, inlineString, parameters) {
402
+ // Parse cell value from cell XML.
403
+ var errorOrTypeAndValue = (0, _parseCell["default"])(t, s, v, inlineString, parameters);
404
+ // If the cell value was expected but is missing,
405
+ // it is considered a repairable situation.
406
+ if (errorOrTypeAndValue === 'VALUE_MISSING') {
407
+ // The default cell type is "n" (numeric), according to XLSX specification.
408
+ switch (t || 'n') {
409
+ // * If the cell is defined by a formula.
410
+ // * Or contains an inline string.
411
+ // * Or contains a shared string.
412
+ // * Or contains a boolean value.
413
+ case 'str':
414
+ case 'inlineStr':
415
+ case 's':
416
+ case 'b':
417
+ // * If the formula result is not pre-computed (which is allowed by the spec)
418
+ // then just ignore this cell.
419
+ // * If the inline string value is not specified then just ignore this cell.
420
+ // * If the shared string index is not specified then just ignore this cell.
421
+ // * If the boolean value is not specified then just ignore this cell.
422
+ return _parseCell.EMPTY_CELL;
423
+ }
424
+ }
425
+ // If the cell contains a formula that couldn't be calculated due to an error,
426
+ // simply ignore such cell and assume it to be empty.
427
+ if (t === 'e') {
428
+ return _parseCell.EMPTY_CELL;
429
+ }
430
+ // Return either the error code or the cell's type and value.
431
+ return errorOrTypeAndValue;
432
+ }
433
+
434
+ /**
435
+ * For certain types of cell, it transforms the value.
436
+ * Specifically, for cells of type "n" or "d", it transforms the value to `Number` or `Date` respectively.
437
+ *
438
+ * The reason it is done separately is because before this function is called,
439
+ * the cells are easily "serializable". And after this function is called,
440
+ * some of the cells' `value` properties become instances of `Date` class or any other class,
441
+ * such as `BigInt`, serializing which would require additional manual steps to be performed.
442
+ * Serializing cells could be utilized in case of "transferring" data between workers
443
+ * with a `transferList`, argument which could hypothetically result in better performance
444
+ * and less time being blocked by the "synchronous" JSON serialization.
445
+ *
446
+ * @param {string|number|boolean|null} value
447
+ * @param {string} type — One of: "s", "n", "d", "b", "-"
448
+ * @return {string|ParsedNumber|Date|boolean|null}
449
+ */
450
+ function parseCellValue(value, type) {
451
+ if (type === 'n') {
452
+ // Parse number from string.
453
+ // Supports custom parsing function to work around the javascript number precision limitation.
454
+ // https://gitlab.com/catamphetamine/read-excel-file/-/issues/85
455
+ if (options.parseNumber) {
456
+ return options.parseNumber(value);
457
+ }
458
+ return value;
459
+ } else if (type === 'd') {
460
+ return new Date(value);
461
+ } else {
462
+ return value;
463
+ }
464
+ }
465
+ function createInitialStateInCell() {
466
+ return {
467
+ v: false,
468
+ is: false,
469
+ t: false,
470
+ r: false,
471
+ rPh: false,
472
+ vText: undefined,
473
+ inlineString: undefined,
474
+ attributes: undefined
475
+ };
476
+ }
477
+ function onOpenTagInCell(tagName, attributes, state) {
478
+ if (tagName === 'v') {
479
+ state.v = true;
480
+ } else if (tagName === 'is') {
481
+ // The possible children of <is> are:
482
+ // * <t> (Text): The standard child to hold plain, simple text.
483
+ // * <r> (Rich Text Run): Used for applying different formatting styles (like bold or italic) to specific segments of text within a single cell.
484
+ // * <rPh> (Phonetic Run): Used primarily for East Asian languages to provide phonetic reading/pronunciation data (e.g., furigana in Japanese). It associates a phonetic pronunciation run right alongside the base string text tag <t>.
485
+ // * <phoneticPr> (Phonetic Properties): Defines formatting and settings for the phonetic text.
486
+ state.is = true;
487
+ state.inlineString = '';
488
+ } else if (tagName === 't') {
489
+ state.t = true;
490
+ } else if (tagName === 'r') {
491
+ // The possible children of <r/> are:
492
+ // * <rPr> (Run Properties): The formatting properties for the text (font, size, color, bold, italic, etc.).
493
+ // * <t> (Text): The actual text payload.
494
+ // * <rPh> (Phonetic Run): Phonetic pronunciation guidance (used for East Asian languages like Japanese). It associates a phonetic pronunciation run right alongside the base string text tag <t>.
495
+ state.r = true;
496
+ } else if (tagName === 'rPh') {
497
+ // The possible children of <rPh/> are:
498
+ // * <t> (Text): Contains the actual phonetic text or reading (usually in Katakana for Japanese) that corresponds to the associated character string.
499
+ state.rPh = true;
500
+ }
501
+ }
502
+ function onCloseTagInCell(tagName, state) {
503
+ if (tagName === 'v') {
504
+ state.v = false;
505
+ // If the `<v/>` element is present but is empty,
506
+ // reassign `vText` property from `undefined` to an empty string `""`.
507
+ // This is to differentiate between two separate cases:
508
+ // * When `<f/>` formula is present but its result is not pre-computed (`<v/>` is absent)
509
+ // * When `<f/>` formula is present and its result is an empty string (`<v/>` is present but empty)
510
+ state.vText || (state.vText = '');
511
+ } else if (tagName === 'is') {
512
+ state.is = false;
513
+ } else if (tagName === 't') {
514
+ state.t = false;
515
+ } else if (tagName === 'r') {
516
+ state.r = false;
517
+ } else if (tagName === 'rPh') {
518
+ state.rPh = false;
519
+ }
520
+ }
521
+ function onTextInCell(text, state) {
522
+ if (state.v) {
523
+ state.vText = text;
524
+ } else if (state.is) {
525
+ if (state.rPh) {
526
+ // Ignore anything inside `<rPh/>` tags
527
+ } else if (state.t) {
528
+ if (state.r) {
529
+ // An `<r/>` element could contain multiple `<t/>` elements,
530
+ // the text content from all of which should be concatenated.
531
+ state.inlineString += text;
532
+ } else {
533
+ state.inlineString = text;
534
+ }
535
+ }
536
+ }
537
+ }
538
+
539
+ // Dimensions
540
+
541
+ function getSheetDimensions(cells) {
542
+ // The left-top boundary is ignored and is always assumed to be `0, 0`.
543
+ // It used to be not ignored in the past but that produced confusing behavior
544
+ // when empty rows or columns at the start of a sheet were discarded,
545
+ // and that was not something that users of this package expected.
546
+ // https://github.com/catamphetamine/read-excel-file/issues/102#issuecomment-973238655
547
+ var minRow = cells.length === 0 ? 0 : 1;
548
+ var minCol = cells.length === 0 ? 0 : 1;
549
+ var maxRow = 0;
550
+ var maxCol = 0;
551
+ for (var _iterator2 = _createForOfIteratorHelperLoose(cells), _step2; !(_step2 = _iterator2()).done;) {
552
+ var cell = _step2.value;
553
+ if (maxRow < cell.row) {
554
+ maxRow = cell.row;
555
+ }
556
+ if (maxCol < cell.column) {
557
+ maxCol = cell.column;
558
+ }
559
+ }
560
+ return [[minRow, minCol], [maxRow, maxCol]];
102
561
  }
103
- return dimensions;
104
562
  }
105
563
  //# sourceMappingURL=parseSheet.js.map