worksheet-reader.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. "use strict";
  2. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  3. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
  4. 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); }
  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. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  7. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  8. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  10. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  12. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  14. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  17. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18. function _awaitAsyncGenerator(value) { return new _AwaitValue(value); }
  19. function _wrapAsyncGenerator(fn) { return function () { return new _AsyncGenerator(fn.apply(this, arguments)); }; }
  20. function _AsyncGenerator(gen) { var front, back; function send(key, arg) { return new Promise(function (resolve, reject) { var request = { key: key, arg: arg, resolve: resolve, reject: reject, next: null }; if (back) { back = back.next = request; } else { front = back = request; resume(key, arg); } }); } function resume(key, arg) { try { var result = gen[key](arg); var value = result.value; var wrappedAwait = value instanceof _AwaitValue; Promise.resolve(wrappedAwait ? value.wrapped : value).then(function (arg) { if (wrappedAwait) { resume(key === "return" ? "return" : "next", arg); return; } settle(result.done ? "return" : "normal", arg); }, function (err) { resume("throw", err); }); } catch (err) { settle("throw", err); } } function settle(type, value) { switch (type) { case "return": front.resolve({ value: value, done: true }); break; case "throw": front.reject(value); break; default: front.resolve({ value: value, done: false }); break; } front = front.next; if (front) { resume(front.key, front.arg); } else { back = null; } } this._invoke = send; if (typeof gen.return !== "function") { this.return = undefined; } }
  21. if (typeof Symbol === "function" && Symbol.asyncIterator) { _AsyncGenerator.prototype[Symbol.asyncIterator] = function () { return this; }; }
  22. _AsyncGenerator.prototype.next = function (arg) { return this._invoke("next", arg); };
  23. _AsyncGenerator.prototype.throw = function (arg) { return this._invoke("throw", arg); };
  24. _AsyncGenerator.prototype.return = function (arg) { return this._invoke("return", arg); };
  25. function _AwaitValue(value) { this.wrapped = value; }
  26. function _asyncIterator(iterable) { var method; if (typeof Symbol !== "undefined") { if (Symbol.asyncIterator) { method = iterable[Symbol.asyncIterator]; if (method != null) return method.call(iterable); } if (Symbol.iterator) { method = iterable[Symbol.iterator]; if (method != null) return method.call(iterable); } } throw new TypeError("Object is not async iterable"); }
  27. var _require = require('events'),
  28. EventEmitter = _require.EventEmitter;
  29. var parseSax = require('../../utils/parse-sax');
  30. var _ = require('../../utils/under-dash');
  31. var utils = require('../../utils/utils');
  32. var colCache = require('../../utils/col-cache');
  33. var Dimensions = require('../../doc/range');
  34. var Row = require('../../doc/row');
  35. var Column = require('../../doc/column');
  36. var WorksheetReader = /*#__PURE__*/function (_EventEmitter) {
  37. _inherits(WorksheetReader, _EventEmitter);
  38. var _super = _createSuper(WorksheetReader);
  39. function WorksheetReader(_ref) {
  40. var _this3;
  41. var workbook = _ref.workbook,
  42. id = _ref.id,
  43. iterator = _ref.iterator,
  44. options = _ref.options;
  45. _classCallCheck(this, WorksheetReader);
  46. _this3 = _super.call(this);
  47. _this3.workbook = workbook;
  48. _this3.id = id;
  49. _this3.iterator = iterator;
  50. _this3.options = options || {}; // and a name
  51. _this3.name = "Sheet".concat(_this3.id); // column definitions
  52. _this3._columns = null;
  53. _this3._keys = {}; // keep a record of dimensions
  54. _this3._dimensions = new Dimensions();
  55. return _this3;
  56. } // destroy - not a valid operation for a streaming writer
  57. // even though some streamers might be able to, it's a bad idea.
  58. _createClass(WorksheetReader, [{
  59. key: "destroy",
  60. value: function destroy() {
  61. throw new Error('Invalid Operation: destroy');
  62. } // return the current dimensions of the writer
  63. }, {
  64. key: "getColumn",
  65. // get a single column by col number. If it doesn't exist, it and any gaps before it
  66. // are created.
  67. value: function getColumn(c) {
  68. if (typeof c === 'string') {
  69. // if it matches a key'd column, return that
  70. var col = this._keys[c];
  71. if (col) {
  72. return col;
  73. } // otherise, assume letter
  74. c = colCache.l2n(c);
  75. }
  76. if (!this._columns) {
  77. this._columns = [];
  78. }
  79. if (c > this._columns.length) {
  80. var n = this._columns.length + 1;
  81. while (n <= c) {
  82. this._columns.push(new Column(this, n++));
  83. }
  84. }
  85. return this._columns[c - 1];
  86. }
  87. }, {
  88. key: "getColumnKey",
  89. value: function getColumnKey(key) {
  90. return this._keys[key];
  91. }
  92. }, {
  93. key: "setColumnKey",
  94. value: function setColumnKey(key, value) {
  95. this._keys[key] = value;
  96. }
  97. }, {
  98. key: "deleteColumnKey",
  99. value: function deleteColumnKey(key) {
  100. delete this._keys[key];
  101. }
  102. }, {
  103. key: "eachColumnKey",
  104. value: function eachColumnKey(f) {
  105. _.each(this._keys, f);
  106. }
  107. }, {
  108. key: "read",
  109. value: function () {
  110. var _read = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
  111. var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, events, _iterator4, _step4, _step4$value, eventType, value;
  112. return regeneratorRuntime.wrap(function _callee$(_context) {
  113. while (1) {
  114. switch (_context.prev = _context.next) {
  115. case 0:
  116. _context.prev = 0;
  117. _iteratorNormalCompletion = true;
  118. _didIteratorError = false;
  119. _context.prev = 3;
  120. _iterator = _asyncIterator(this.parse());
  121. case 5:
  122. _context.next = 7;
  123. return _iterator.next();
  124. case 7:
  125. _step = _context.sent;
  126. _iteratorNormalCompletion = _step.done;
  127. _context.next = 11;
  128. return _step.value;
  129. case 11:
  130. _value = _context.sent;
  131. if (_iteratorNormalCompletion) {
  132. _context.next = 19;
  133. break;
  134. }
  135. events = _value;
  136. _iterator4 = _createForOfIteratorHelper(events);
  137. try {
  138. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  139. _step4$value = _step4.value, eventType = _step4$value.eventType, value = _step4$value.value;
  140. this.emit(eventType, value);
  141. }
  142. } catch (err) {
  143. _iterator4.e(err);
  144. } finally {
  145. _iterator4.f();
  146. }
  147. case 16:
  148. _iteratorNormalCompletion = true;
  149. _context.next = 5;
  150. break;
  151. case 19:
  152. _context.next = 25;
  153. break;
  154. case 21:
  155. _context.prev = 21;
  156. _context.t0 = _context["catch"](3);
  157. _didIteratorError = true;
  158. _iteratorError = _context.t0;
  159. case 25:
  160. _context.prev = 25;
  161. _context.prev = 26;
  162. if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
  163. _context.next = 30;
  164. break;
  165. }
  166. _context.next = 30;
  167. return _iterator.return();
  168. case 30:
  169. _context.prev = 30;
  170. if (!_didIteratorError) {
  171. _context.next = 33;
  172. break;
  173. }
  174. throw _iteratorError;
  175. case 33:
  176. return _context.finish(30);
  177. case 34:
  178. return _context.finish(25);
  179. case 35:
  180. this.emit('finished');
  181. _context.next = 41;
  182. break;
  183. case 38:
  184. _context.prev = 38;
  185. _context.t1 = _context["catch"](0);
  186. this.emit('error', _context.t1);
  187. case 41:
  188. case "end":
  189. return _context.stop();
  190. }
  191. }
  192. }, _callee, this, [[0, 38], [3, 21, 25, 35], [26,, 30, 34]]);
  193. }));
  194. function read() {
  195. return _read.apply(this, arguments);
  196. }
  197. return read;
  198. }()
  199. }, {
  200. key: Symbol.asyncIterator,
  201. value: function value() {
  202. var _this = this;
  203. return _wrapAsyncGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
  204. var _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _value2, events, _iterator5, _step5, _step5$value, eventType, value;
  205. return regeneratorRuntime.wrap(function _callee2$(_context2) {
  206. while (1) {
  207. switch (_context2.prev = _context2.next) {
  208. case 0:
  209. _iteratorNormalCompletion2 = true;
  210. _didIteratorError2 = false;
  211. _context2.prev = 2;
  212. _iterator2 = _asyncIterator(_this.parse());
  213. case 4:
  214. _context2.next = 6;
  215. return _awaitAsyncGenerator(_iterator2.next());
  216. case 6:
  217. _step2 = _context2.sent;
  218. _iteratorNormalCompletion2 = _step2.done;
  219. _context2.next = 10;
  220. return _awaitAsyncGenerator(_step2.value);
  221. case 10:
  222. _value2 = _context2.sent;
  223. if (_iteratorNormalCompletion2) {
  224. _context2.next = 34;
  225. break;
  226. }
  227. events = _value2;
  228. _iterator5 = _createForOfIteratorHelper(events);
  229. _context2.prev = 14;
  230. _iterator5.s();
  231. case 16:
  232. if ((_step5 = _iterator5.n()).done) {
  233. _context2.next = 23;
  234. break;
  235. }
  236. _step5$value = _step5.value, eventType = _step5$value.eventType, value = _step5$value.value;
  237. if (!(eventType === 'row')) {
  238. _context2.next = 21;
  239. break;
  240. }
  241. _context2.next = 21;
  242. return value;
  243. case 21:
  244. _context2.next = 16;
  245. break;
  246. case 23:
  247. _context2.next = 28;
  248. break;
  249. case 25:
  250. _context2.prev = 25;
  251. _context2.t0 = _context2["catch"](14);
  252. _iterator5.e(_context2.t0);
  253. case 28:
  254. _context2.prev = 28;
  255. _iterator5.f();
  256. return _context2.finish(28);
  257. case 31:
  258. _iteratorNormalCompletion2 = true;
  259. _context2.next = 4;
  260. break;
  261. case 34:
  262. _context2.next = 40;
  263. break;
  264. case 36:
  265. _context2.prev = 36;
  266. _context2.t1 = _context2["catch"](2);
  267. _didIteratorError2 = true;
  268. _iteratorError2 = _context2.t1;
  269. case 40:
  270. _context2.prev = 40;
  271. _context2.prev = 41;
  272. if (!(!_iteratorNormalCompletion2 && _iterator2.return != null)) {
  273. _context2.next = 45;
  274. break;
  275. }
  276. _context2.next = 45;
  277. return _awaitAsyncGenerator(_iterator2.return());
  278. case 45:
  279. _context2.prev = 45;
  280. if (!_didIteratorError2) {
  281. _context2.next = 48;
  282. break;
  283. }
  284. throw _iteratorError2;
  285. case 48:
  286. return _context2.finish(45);
  287. case 49:
  288. return _context2.finish(40);
  289. case 50:
  290. case "end":
  291. return _context2.stop();
  292. }
  293. }
  294. }, _callee2, null, [[2, 36, 40, 50], [14, 25, 28, 31], [41,, 45, 49]]);
  295. }))();
  296. }
  297. }, {
  298. key: "parse",
  299. value: function parse() {
  300. var _this2 = this;
  301. return _wrapAsyncGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
  302. var iterator, options, emitSheet, emitHyperlinks, hyperlinks, _this2$workbook, sharedStrings, styles, properties, inCols, inRows, inHyperlinks, cols, row, c, current, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, _value3, events, worksheetEvents, _iterator6, _step6, _step6$value, eventType, value, node, r, styleId, style, hyperlink, _node, address, cell, _style, cellValue, index, _hyperlink;
  303. return regeneratorRuntime.wrap(function _callee3$(_context3) {
  304. while (1) {
  305. switch (_context3.prev = _context3.next) {
  306. case 0:
  307. iterator = _this2.iterator, options = _this2.options;
  308. emitSheet = false;
  309. emitHyperlinks = false;
  310. hyperlinks = null;
  311. _context3.t0 = options.worksheets;
  312. _context3.next = _context3.t0 === 'emit' ? 7 : _context3.t0 === 'prep' ? 9 : 10;
  313. break;
  314. case 7:
  315. emitSheet = true;
  316. return _context3.abrupt("break", 11);
  317. case 9:
  318. return _context3.abrupt("break", 11);
  319. case 10:
  320. return _context3.abrupt("break", 11);
  321. case 11:
  322. _context3.t1 = options.hyperlinks;
  323. _context3.next = _context3.t1 === 'emit' ? 14 : _context3.t1 === 'cache' ? 16 : 18;
  324. break;
  325. case 14:
  326. emitHyperlinks = true;
  327. return _context3.abrupt("break", 19);
  328. case 16:
  329. _this2.hyperlinks = hyperlinks = {};
  330. return _context3.abrupt("break", 19);
  331. case 18:
  332. return _context3.abrupt("break", 19);
  333. case 19:
  334. if (!(!emitSheet && !emitHyperlinks && !hyperlinks)) {
  335. _context3.next = 21;
  336. break;
  337. }
  338. return _context3.abrupt("return");
  339. case 21:
  340. // references
  341. _this2$workbook = _this2.workbook, sharedStrings = _this2$workbook.sharedStrings, styles = _this2$workbook.styles, properties = _this2$workbook.properties; // xml position
  342. inCols = false;
  343. inRows = false;
  344. inHyperlinks = false; // parse state
  345. cols = null;
  346. row = null;
  347. c = null;
  348. current = null;
  349. _iteratorNormalCompletion3 = true;
  350. _didIteratorError3 = false;
  351. _context3.prev = 31;
  352. _iterator3 = _asyncIterator(parseSax(iterator));
  353. case 33:
  354. _context3.next = 35;
  355. return _awaitAsyncGenerator(_iterator3.next());
  356. case 35:
  357. _step3 = _context3.sent;
  358. _iteratorNormalCompletion3 = _step3.done;
  359. _context3.next = 39;
  360. return _awaitAsyncGenerator(_step3.value);
  361. case 39:
  362. _value3 = _context3.sent;
  363. if (_iteratorNormalCompletion3) {
  364. _context3.next = 153;
  365. break;
  366. }
  367. events = _value3;
  368. worksheetEvents = [];
  369. _iterator6 = _createForOfIteratorHelper(events);
  370. _context3.prev = 44;
  371. _iterator6.s();
  372. case 46:
  373. if ((_step6 = _iterator6.n()).done) {
  374. _context3.next = 139;
  375. break;
  376. }
  377. _step6$value = _step6.value, eventType = _step6$value.eventType, value = _step6$value.value;
  378. if (!(eventType === 'opentag')) {
  379. _context3.next = 82;
  380. break;
  381. }
  382. node = value;
  383. if (!emitSheet) {
  384. _context3.next = 71;
  385. break;
  386. }
  387. _context3.t2 = node.name;
  388. _context3.next = _context3.t2 === 'cols' ? 54 : _context3.t2 === 'sheetData' ? 57 : _context3.t2 === 'col' ? 59 : _context3.t2 === 'row' ? 61 : _context3.t2 === 'c' ? 63 : _context3.t2 === 'f' ? 65 : _context3.t2 === 'v' ? 67 : _context3.t2 === 'mergeCell' ? 69 : 70;
  389. break;
  390. case 54:
  391. inCols = true;
  392. cols = [];
  393. return _context3.abrupt("break", 71);
  394. case 57:
  395. inRows = true;
  396. return _context3.abrupt("break", 71);
  397. case 59:
  398. if (inCols) {
  399. cols.push({
  400. min: parseInt(node.attributes.min, 10),
  401. max: parseInt(node.attributes.max, 10),
  402. width: parseFloat(node.attributes.width),
  403. styleId: parseInt(node.attributes.style || '0', 10)
  404. });
  405. }
  406. return _context3.abrupt("break", 71);
  407. case 61:
  408. if (inRows) {
  409. r = parseInt(node.attributes.r, 10);
  410. row = new Row(_this2, r);
  411. if (node.attributes.ht) {
  412. row.height = parseFloat(node.attributes.ht);
  413. }
  414. if (node.attributes.s) {
  415. styleId = parseInt(node.attributes.s, 10);
  416. style = styles.getStyleModel(styleId);
  417. if (style) {
  418. row.style = style;
  419. }
  420. }
  421. }
  422. return _context3.abrupt("break", 71);
  423. case 63:
  424. if (row) {
  425. c = {
  426. ref: node.attributes.r,
  427. s: parseInt(node.attributes.s, 10),
  428. t: node.attributes.t
  429. };
  430. }
  431. return _context3.abrupt("break", 71);
  432. case 65:
  433. if (c) {
  434. current = c.f = {
  435. text: ''
  436. };
  437. }
  438. return _context3.abrupt("break", 71);
  439. case 67:
  440. if (c) {
  441. current = c.v = {
  442. text: ''
  443. };
  444. }
  445. return _context3.abrupt("break", 71);
  446. case 69:
  447. return _context3.abrupt("break", 71);
  448. case 70:
  449. return _context3.abrupt("break", 71);
  450. case 71:
  451. if (!(emitHyperlinks || hyperlinks)) {
  452. _context3.next = 80;
  453. break;
  454. }
  455. _context3.t3 = node.name;
  456. _context3.next = _context3.t3 === 'hyperlinks' ? 75 : _context3.t3 === 'hyperlink' ? 77 : 79;
  457. break;
  458. case 75:
  459. inHyperlinks = true;
  460. return _context3.abrupt("break", 80);
  461. case 77:
  462. if (inHyperlinks) {
  463. hyperlink = {
  464. ref: node.attributes.ref,
  465. rId: node.attributes['r:id']
  466. };
  467. if (emitHyperlinks) {
  468. worksheetEvents.push({
  469. eventType: 'hyperlink',
  470. value: hyperlink
  471. });
  472. } else {
  473. hyperlinks[hyperlink.ref] = hyperlink;
  474. }
  475. }
  476. return _context3.abrupt("break", 80);
  477. case 79:
  478. return _context3.abrupt("break", 80);
  479. case 80:
  480. _context3.next = 137;
  481. break;
  482. case 82:
  483. if (!(eventType === 'text')) {
  484. _context3.next = 86;
  485. break;
  486. }
  487. // only text data is for sheet values
  488. if (emitSheet) {
  489. if (current) {
  490. current.text += value;
  491. }
  492. }
  493. _context3.next = 137;
  494. break;
  495. case 86:
  496. if (!(eventType === 'closetag')) {
  497. _context3.next = 137;
  498. break;
  499. }
  500. _node = value;
  501. if (!emitSheet) {
  502. _context3.next = 130;
  503. break;
  504. }
  505. _context3.t4 = _node.name;
  506. _context3.next = _context3.t4 === 'cols' ? 92 : _context3.t4 === 'sheetData' ? 95 : _context3.t4 === 'row' ? 97 : _context3.t4 === 'c' ? 101 : 129;
  507. break;
  508. case 92:
  509. inCols = false;
  510. _this2._columns = Column.fromModel(cols);
  511. return _context3.abrupt("break", 130);
  512. case 95:
  513. inRows = false;
  514. return _context3.abrupt("break", 130);
  515. case 97:
  516. _this2._dimensions.expandRow(row);
  517. worksheetEvents.push({
  518. eventType: 'row',
  519. value: row
  520. });
  521. row = null;
  522. return _context3.abrupt("break", 130);
  523. case 101:
  524. if (!(row && c)) {
  525. _context3.next = 128;
  526. break;
  527. }
  528. address = colCache.decodeAddress(c.ref);
  529. cell = row.getCell(address.col);
  530. if (c.s) {
  531. _style = styles.getStyleModel(c.s);
  532. if (_style) {
  533. cell.style = _style;
  534. }
  535. }
  536. if (!c.f) {
  537. _context3.next = 111;
  538. break;
  539. }
  540. cellValue = {
  541. formula: c.f.text
  542. };
  543. if (c.v) {
  544. if (c.t === 'str') {
  545. cellValue.result = utils.xmlDecode(c.v.text);
  546. } else {
  547. cellValue.result = parseFloat(c.v.text);
  548. }
  549. }
  550. cell.value = cellValue;
  551. _context3.next = 126;
  552. break;
  553. case 111:
  554. if (!c.v) {
  555. _context3.next = 126;
  556. break;
  557. }
  558. _context3.t5 = c.t;
  559. _context3.next = _context3.t5 === 's' ? 115 : _context3.t5 === 'str' ? 118 : _context3.t5 === 'e' ? 120 : _context3.t5 === 'b' ? 122 : 124;
  560. break;
  561. case 115:
  562. index = parseInt(c.v.text, 10);
  563. if (sharedStrings) {
  564. cell.value = sharedStrings[index];
  565. } else {
  566. cell.value = {
  567. sharedString: index
  568. };
  569. }
  570. return _context3.abrupt("break", 126);
  571. case 118:
  572. cell.value = utils.xmlDecode(c.v.text);
  573. return _context3.abrupt("break", 126);
  574. case 120:
  575. cell.value = {
  576. error: c.v.text
  577. };
  578. return _context3.abrupt("break", 126);
  579. case 122:
  580. cell.value = parseInt(c.v.text, 10) !== 0;
  581. return _context3.abrupt("break", 126);
  582. case 124:
  583. if (utils.isDateFmt(cell.numFmt)) {
  584. cell.value = utils.excelToDate(parseFloat(c.v.text), properties.model && properties.model.date1904);
  585. } else {
  586. cell.value = parseFloat(c.v.text);
  587. }
  588. return _context3.abrupt("break", 126);
  589. case 126:
  590. if (hyperlinks) {
  591. _hyperlink = hyperlinks[c.ref];
  592. if (_hyperlink) {
  593. cell.text = cell.value;
  594. cell.value = undefined;
  595. cell.hyperlink = _hyperlink;
  596. }
  597. }
  598. c = null;
  599. case 128:
  600. return _context3.abrupt("break", 130);
  601. case 129:
  602. return _context3.abrupt("break", 130);
  603. case 130:
  604. if (!(emitHyperlinks || hyperlinks)) {
  605. _context3.next = 137;
  606. break;
  607. }
  608. _context3.t6 = _node.name;
  609. _context3.next = _context3.t6 === 'hyperlinks' ? 134 : 136;
  610. break;
  611. case 134:
  612. inHyperlinks = false;
  613. return _context3.abrupt("break", 137);
  614. case 136:
  615. return _context3.abrupt("break", 137);
  616. case 137:
  617. _context3.next = 46;
  618. break;
  619. case 139:
  620. _context3.next = 144;
  621. break;
  622. case 141:
  623. _context3.prev = 141;
  624. _context3.t7 = _context3["catch"](44);
  625. _iterator6.e(_context3.t7);
  626. case 144:
  627. _context3.prev = 144;
  628. _iterator6.f();
  629. return _context3.finish(144);
  630. case 147:
  631. if (!(worksheetEvents.length > 0)) {
  632. _context3.next = 150;
  633. break;
  634. }
  635. _context3.next = 150;
  636. return worksheetEvents;
  637. case 150:
  638. _iteratorNormalCompletion3 = true;
  639. _context3.next = 33;
  640. break;
  641. case 153:
  642. _context3.next = 159;
  643. break;
  644. case 155:
  645. _context3.prev = 155;
  646. _context3.t8 = _context3["catch"](31);
  647. _didIteratorError3 = true;
  648. _iteratorError3 = _context3.t8;
  649. case 159:
  650. _context3.prev = 159;
  651. _context3.prev = 160;
  652. if (!(!_iteratorNormalCompletion3 && _iterator3.return != null)) {
  653. _context3.next = 164;
  654. break;
  655. }
  656. _context3.next = 164;
  657. return _awaitAsyncGenerator(_iterator3.return());
  658. case 164:
  659. _context3.prev = 164;
  660. if (!_didIteratorError3) {
  661. _context3.next = 167;
  662. break;
  663. }
  664. throw _iteratorError3;
  665. case 167:
  666. return _context3.finish(164);
  667. case 168:
  668. return _context3.finish(159);
  669. case 169:
  670. case "end":
  671. return _context3.stop();
  672. }
  673. }
  674. }, _callee3, null, [[31, 155, 159, 169], [44, 141, 144, 147], [160,, 164, 168]]);
  675. }))();
  676. }
  677. }, {
  678. key: "dimensions",
  679. get: function get() {
  680. return this._dimensions;
  681. } // =========================================================================
  682. // Columns
  683. // get the current columns array.
  684. }, {
  685. key: "columns",
  686. get: function get() {
  687. return this._columns;
  688. }
  689. }]);
  690. return WorksheetReader;
  691. }(EventEmitter);
  692. module.exports = WorksheetReader;
  693. //# sourceMappingURL=worksheet-reader.js.map