Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/stream/xlsx/hyperlink-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions lib/stream/xlsx/worksheet-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions lib/xlsx/xform/sheet/cell-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Binary file added spec/integration/data/formulas.xlsx
Binary file not shown.
53 changes: 53 additions & 0 deletions spec/integration/workbook-xlsx-reader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]');
});

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('[email protected]');
});

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:[email protected]');
expect(this.cell.hyperlink).to.equal('mailto:[email protected]');
});
});
});
});