Removed cached formula values

This commit is contained in:
Ryan Fairchild
2015-04-20 14:34:14 -04:00
parent cb730e4ca8
commit cd95198134
+22 -14
View File
@@ -76,7 +76,7 @@ module.exports = (function() {
sheetData.findall("row").forEach(function(row) {
row.attrib.r = currentRow = self.getCurrentRow(row, totalRowsInserted);
rows.push(row);
var cells = [],
cellsInserted = 0,
newTableRows = [];
@@ -85,10 +85,18 @@ module.exports = (function() {
var appendCell = true;
cell.attrib.r = self.getCurrentCell(cell, currentRow, cellsInserted);
//Here we are forcing the values in formulas to be recalculated
var formulas = cell.findall('f');
if (formulas && formulas.length > 0) {
cell.findall('v').forEach(function(v){
cell.remove(0,v);
});
}
// If c[@t="s"] (string column), look up /c/v@text as integer in
// `this.sharedStrings`
if(cell.attrib.t === "s") {
// Look for a shared string that may contain placeholders
var cellValue = cell.find("v"),
stringIndex = parseInt(cellValue.text, 10),
@@ -141,7 +149,7 @@ module.exports = (function() {
if(appendCell) {
cells.push(cell);
}
}); // cells loop
// We may have inserted columns, so re-build the children of the row
@@ -151,7 +159,7 @@ module.exports = (function() {
if(cellsInserted !== 0) {
self.updateRowSpan(row, cellsInserted);
}
// Add newly inserted rows
if(newTableRows.length > 0) {
newTableRows.forEach(function(row) {
@@ -160,7 +168,7 @@ module.exports = (function() {
});
self.pushDown(self.workbook, sheet.root, namedTables, currentRow, newTableRows.length);
}
}); // rows loop
// We may have inserted rows, so re-build the children of the sheetData
@@ -194,7 +202,7 @@ module.exports = (function() {
var root = etree.parse(self.archive.file(self.sharedStringsPath).asText()).getroot(),
children = root.getchildren();
root.delSlice(0, children.length);
self.sharedStrings.forEach(function(string) {
@@ -254,7 +262,7 @@ module.exports = (function() {
// Get a list of sheet ids, names and filenames
Workbook.prototype.loadSheets = function(prefix, workbook, workbookRels) {
var self = this;
var sheets = [];
workbook.findall("sheets/sheet").forEach(function(sheet) {
@@ -421,7 +429,7 @@ module.exports = (function() {
}
});
};
// Return a list of tokens that may exist in the string.
// Keys are: `placeholder` (the full placeholder, including the `${}`
// delineators), `name` (the name part of the token), `key` (the object key
@@ -430,7 +438,7 @@ module.exports = (function() {
Workbook.prototype.extractPlaceholders = function(string) {
// Yes, that's right. It's a bunch of brackets and question marks and stuff.
var re = /\${(?:(.+?):)?(.+?)(?:\.(.+?))?}/g;
var match = null, matches = [];
while((match = re.exec(string)) !== null) {
matches.push({
@@ -603,11 +611,11 @@ module.exports = (function() {
var newCellsInserted = -1, // we technically delete one before we start adding back
currentCell = cell.attrib.r;
// add a cell for each element in the list
substitution.forEach(function(element) {
++newCellsInserted;
if(newCellsInserted > 0) {
currentCell = self.nextCol(currentCell);
}
@@ -646,7 +654,7 @@ module.exports = (function() {
value = element[key];
if(idx === 0) { // insert in the row where the placeholders are
if(value instanceof Array) {
newCellsInserted = self.substituteArray(cells, cell, value);
} else {
@@ -654,7 +662,7 @@ module.exports = (function() {
}
} else { // insert new rows (or reuse rows just inserted)
// Do we have an existing row to use? If not, create one.
if((idx - 1) < newTableRows.length) {
newRow = newTableRows[idx - 1];
@@ -673,7 +681,7 @@ module.exports = (function() {
if(value instanceof Array) {
newCellsInsertedOnNewRow = self.substituteArray(newCells, newCell, value);
// Add each of the new cells created by substituteArray()
newCells.forEach(function(newCell) {
newRow.append(newCell);