diff --git a/lib/stream/xlsx/hyperlink-reader.js b/lib/stream/xlsx/hyperlink-reader.js index 58ea60627..91156ba0f 100644 --- a/lib/stream/xlsx/hyperlink-reader.js +++ b/lib/stream/xlsx/hyperlink-reader.js @@ -78,7 +78,7 @@ utils.inherits(HyperlinkReader, events.EventEmitter, { }); // create a down-stream flow-control to regulate the stream - var flowControl = this.workbook.flowControl.createChild(); + var flowControl = this._workbook.flowControl.createChild(); flowControl.pipe(parser, {sync: true}); entry.pipe(flowControl); } diff --git a/lib/stream/xlsx/worksheet-reader.js b/lib/stream/xlsx/worksheet-reader.js index 6f60e5489..c6aa9e053 100644 --- a/lib/stream/xlsx/worksheet-reader.js +++ b/lib/stream/xlsx/worksheet-reader.js @@ -310,6 +310,14 @@ utils.inherits(WorksheetReader, events.EventEmitter, { break; } } + if (hyperlinks) { + var hyperlink = hyperlinks[c.ref]; + if (hyperlink) { + cell.text = cell.value; + cell.value = undefined; + cell.hyperlink = hyperlink; + } + } c = null; } break; diff --git a/lib/xlsx/xform/sheet/cell-xform.js b/lib/xlsx/xform/sheet/cell-xform.js index 2fb075333..b1defe9b9 100644 --- a/lib/xlsx/xform/sheet/cell-xform.js +++ b/lib/xlsx/xform/sheet/cell-xform.js @@ -427,9 +427,14 @@ utils.inherits(CellXform, BaseXform, { // look for hyperlink var hyperlink = options.hyperlinkMap[model.address]; if (hyperlink) { + if (model.type === Enums.ValueType.Formula) { + model.text = model.result; + model.result = undefined; + } else { + model.text = model.value; + model.value = undefined; + } model.type = Enums.ValueType.Hyperlink; - model.text = model.value; - model.value = undefined; model.hyperlink = hyperlink; } } diff --git a/spec/integration/data/formulas.xlsx b/spec/integration/data/formulas.xlsx new file mode 100644 index 000000000..b5c4225b8 Binary files /dev/null and b/spec/integration/data/formulas.xlsx differ diff --git a/spec/integration/workbook-xlsx-reader.spec.js b/spec/integration/workbook-xlsx-reader.spec.js index 89378dabb..1909f2f42 100644 --- a/spec/integration/workbook-xlsx-reader.spec.js +++ b/spec/integration/workbook-xlsx-reader.spec.js @@ -63,4 +63,57 @@ describe('WorkbookReader', function() { }); }); }); + + describe('with a spreadsheet that contains formulas', function() { + before(function() { + var testContext = this; + var workbook = new Excel.Workbook(); + return workbook.xlsx.read(fs.createReadStream('./spec/integration/data/formulas.xlsx')) + .then(function() { + testContext.worksheet = workbook.getWorksheet(); + }); + }); + + describe('with a cell that contains a regular formula', function() { + beforeEach(function() { + this.cell = this.worksheet.getCell('A2'); + }); + + it('should be classified as a formula cell', function() { + expect(this.cell.type).to.equal(Excel.ValueType.Formula); + expect(this.cell.isFormula).to.be.true; + }); + + it('should have text corresponding to the evaluated formula result', function() { + expect(this.cell.text).to.equal('someone@example.com'); + }); + + it('should have the formula source', function() { + expect(this.cell.model.formula).to.equal('_xlfn.CONCAT("someone","@example.com")'); + }); + }); + + describe('with a cell that contains a hyperlinked formula', function() { + beforeEach(function() { + this.cell = this.worksheet.getCell('A1'); + }); + + it('should be classified as a formula cell', function() { + expect(this.cell.type).to.equal(Excel.ValueType.Hyperlink); + }); + + it('should have text corresponding to the evaluated formula result', function() { + expect(this.cell.value.text).to.equal('someone@example.com'); + }); + + it('should have the formula source', function() { + expect(this.cell.model.formula).to.equal('_xlfn.CONCAT("someone","@example.com")'); + }); + + it('should contain the linked url', function() { + expect(this.cell.value.hyperlink).to.equal('mailto:someone@example.com'); + expect(this.cell.hyperlink).to.equal('mailto:someone@example.com'); + }); + }); + }); });