I am invincible!

This commit is contained in:
Martin Aspeli
2013-09-14 22:34:26 +01:00
parent 3f940aee7d
commit 55c635b310
+47 -26
View File
@@ -98,10 +98,16 @@ module.exports = (function() {
}
if(placeholder.full && placeholder.type === "table" && substitution instanceof Array) {
totalRowsInserted += self.substituteTable(
rows, row, newTableRows, totalRowsInserted,
var newCellsInserted = self.substituteTable(
row, newTableRows,
cells, cell, substitution, placeholder.key
);
// Did we insert new columns (array values)?
if(newCellsInserted !== 0) {
appendCell = false; // don't double-insert cells
totalCellsInserted += newCellsInserted;
}
} else if(placeholder.full && placeholder.type === "normal" && substitution instanceof Array) {
appendCell = false; // don't double-insert cells
totalCellsInserted += self.substituteArray(
@@ -130,6 +136,12 @@ module.exports = (function() {
row.attrib.spans = rowSpan.join(":");
}
// Add newly inserted rows
newTableRows.forEach(function(row) {
rows.push(row);
++totalRowsInserted;
});
}); // rows loop
// We may have inserted rows, so re-build the children of the sheetData
@@ -146,7 +158,9 @@ module.exports = (function() {
var self = this;
self.writeSharedStrings();
return self.archive.generate({base64:false/*,compression:'DEFLATE'*/}); // XXX: Getting errors with compression DEFLATE
// XXX: Getting errors with compression DEFLATE
return self.archive.generate({base64:false /*,compression:'DEFLATE'*/});
};
// Helpers
@@ -414,11 +428,9 @@ module.exports = (function() {
// Perform a table substitution. May update `newTableRows` and change `cell`.
// Returns total number of new rows inserted.
Workbook.prototype.substituteTable = function(
rows, row, newTableRows, totalRowsInserted,
cells, cell, substitution, key
) {
Workbook.prototype.substituteTable = function(row, newTableRows, cells, cell, substitution, key) {
var self = this,
newCellsInserted = 0, // on the original row
newRowsInserted = 0;
// if no elements, blank the cell, but don't delete it
@@ -428,22 +440,27 @@ module.exports = (function() {
} else {
substitution.forEach(function(substitutionElement, idx) {
var newRow, newCell,
newCells = [],
value = substitutionElement[key];
if(idx === 0) {
newCell = cell;
} else {
if(idx === 0) { // insert in the row where the placeholders are
if(value instanceof Array) {
newCellsInserted = self.substituteArray(cells, cell, value);
} else {
self.insertCellValue(cell, value);
}
} 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];
} else {
newRow = self.cloneElement(row, false);
++newRowsInserted;
++totalRowsInserted;
newRow.attrib.r = self.getCurrentRow(row, totalRowsInserted);
rows.push(newRow);
newRow.attrib.r = self.getCurrentRow(row, newRowsInserted);
newTableRows.push(newRow);
}
@@ -454,25 +471,29 @@ module.exports = (function() {
col: self.splitRef(newCell.attrib.r).col
});
// Add cell to new row
newRow.append(newCell);
if(value instanceof Array) {
self.substituteArray(newCells, newCell, value);
// Add each of the new cells created by substituteArray()
newCells.forEach(function(newCell) {
newRow.append(newCell);
});
// TODO: Update spans attribute
} else {
self.insertCellValue(newCell, value);
// Add the cell that previously held the placeholder
newRow.append(newCell);
}
}
if(value instanceof Array) {
// TODO: Deal with lists as values.
// TODO: Update spans attribute on inserted row
self.insertCellValue(newCell, value);
} else {
self.insertCellValue(newCell, value);
}
});
// TODO: Update table definitions
}
return newRowsInserted;
return newCellsInserted;
};
Workbook.prototype.cloneElement = function(element, deep) {