Skip to content

Commit

Permalink
Merge pull request #7 from EyeSeeTea/development
Browse files Browse the repository at this point in the history
Release 3.7.0 (Bulk Load)
  • Loading branch information
adrianq authored Nov 20, 2020
2 parents f939332 + e8bb957 commit 46dc5bd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/Cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,14 @@ class Cell {
formula() {
return new ArgHandler('Cell.formula')
.case(() => {
// TODO in future: Return translated formula.
if (this._formulaType === "shared" && !this._formulaRef) return "SHARED";
const sharedFormula = this.sheet().sharedFormulas(this._sharedFormulaId);

if (this._formulaType === "shared" && !_.isNil(sharedFormula)) {
return sharedFormula.formula;
} else if (this._formulaType === "shared" && !this._formulaRef) {
return "SHARED";
}

return this._formula;
})
.case('nil', () => {
Expand Down Expand Up @@ -566,8 +572,12 @@ class Cell {
this._formulaType = fNode.attributes.t || "normal";
this._formulaRef = fNode.attributes.ref;
this._formula = fNode.children[0];
this._sharedFormulaId = String(fNode.attributes.si);

if (this._formulaType === "shared" && !_.isNil(this._sharedFormulaId) && !_.isNil(this._formula)) {
this.sheet().sharedFormulas(this._sharedFormulaId, { ref: this._formulaRef, formula: this._formula });
}

this._sharedFormulaId = fNode.attributes.si;
if (!_.isNil(this._sharedFormulaId)) {
// Update the sheet's max shared formula ID so we can set future IDs an index beyond this.
this.sheet().updateMaxSharedFormulaId(this._sharedFormulaId);
Expand Down
20 changes: 20 additions & 0 deletions lib/Sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,25 @@ class Sheet {
})
.handle(arguments);
}

/**
* Gets a value indicating whether the sheet is the active sheet in the workbook.
* @returns {boolean} True if active, false otherwise.
*/ sharedFormulas() {
return new ArgHandler("Sheet.sharedFormulas")
.case(() => {
return this._sharedFormulas;
})
.case(["*"], (id) => {
return this._sharedFormulas[id];
})
.case(["string", "object"], (id, object) => {
this._sharedFormulas[id] = object;
return this;
})
.handle(arguments);
}

/**
* Set the active cell in the workbook.
* @param {string|Cell} cell - The cell or address of cell to activate.
Expand Down Expand Up @@ -1763,6 +1782,7 @@ class Sheet {
this._hyperlinks = {};
this._autoFilter = null;
this._drawings = {};
this._sharedFormulas = {};

// Create the relationships.
this._relationships = new Relationships(relationshipsNode);
Expand Down

0 comments on commit 46dc5bd

Please sign in to comment.