Skip to content

Commit

Permalink
Merge pull request #53 from pulavska/pulavska-patch-2
Browse files Browse the repository at this point in the history
Pulavska patch 2
  • Loading branch information
stephenliberty committed Oct 2, 2015
2 parents ef049b7 + 956664a commit fd59696
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 90 deletions.
14 changes: 13 additions & 1 deletion Excel/StyleSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,21 @@ define(['underscore', './util'], function (_, util) {
while(a--) {
xf.setAttribute(attributes[a], styleInstructions[attributes[a]]);
}
if(styleInstructions.fillId) {
if (styleInstructions.fillId) {
xf.setAttribute('applyFill', '1');
}
if (styleInstructions.fontId) {
xf.setAttribute('applyFont', '1');
}
if (styleInstructions.borderId) {
xf.setAttribute('applyBorder', '1');
}
if (styleInstructions.alignment) {
xf.setAttribute('applyAlignment', '1');
}
if (styleInstructions.numFmtId) {
xf.setAttribute('applyNumberFormat', '1');
}
return xf;
},

Expand Down
43 changes: 42 additions & 1 deletion Excel/Worksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ define(['underscore', './util', './RelationshipManager'], function (_, util, Rel
this._tables = [];
this._drawings = [];
this._rowInstructions = {};
this._freezePane = {};
this.initialize(config);
};
_.extend(Worksheet.prototype, {
Expand Down Expand Up @@ -51,6 +52,7 @@ define(['underscore', './util', './RelationshipManager'], function (_, util, Rel
_footers: this._footers,
_tables: this._tables,
_rowInstructions: this._rowInstructions,
_freezePane: this._freezePane,
name: this.name,
id: this.id
};
Expand Down Expand Up @@ -327,6 +329,8 @@ define(['underscore', './util', './RelationshipManager'], function (_, util, Rel
}
if(metadata.style) {
cell.setAttribute('s', metadata.style);
} else if (this._rowInstructions[row] && this._rowInstructions[row].style !== undefined) {
cell.setAttribute('s', this._rowInstructions[row].style);
}
cell.setAttribute('r', util.positionToLetterRef(c + 1, row + 1));
rowNode.appendChild(cell);
Expand Down Expand Up @@ -359,7 +363,12 @@ define(['underscore', './util', './RelationshipManager'], function (_, util, Rel
['ref', util.positionToLetterRef(1, 1)]
]));
}


//added freeze pane
if (this._freezePane.cell) {
worksheet.appendChild(this.exportPane(doc));
}

if(this.columns.length) {
worksheet.appendChild(this.exportColumns(doc));
}
Expand Down Expand Up @@ -444,6 +453,28 @@ define(['underscore', './util', './RelationshipManager'], function (_, util, Rel
return cols;
},

/**
* Added frozen pane
* @param {XML Node} doc
* @returns {XML Node}
*/
exportPane: function (doc) {
var sheetViews = doc.createElement('sheetViews'),
sheetView = doc.createElement('sheetView'),
pane = doc.createElement('pane');

sheetView.setAttribute('workbookViewId', 0);
pane.setAttribute('xSplit', this._freezePane.xSplit);
pane.setAttribute('ySplit', this._freezePane.ySplit);
pane.setAttribute('topLeftCell', this._freezePane.cell);
pane.setAttribute('activePane', 'bottomRight');
pane.setAttribute('state', 'frozen');

sheetView.appendChild(pane);
sheetViews.appendChild(sheetView);
return sheetViews;
},

/**
* Sets the page settings on a worksheet node.
*
Expand Down Expand Up @@ -501,6 +532,16 @@ define(['underscore', './util', './RelationshipManager'], function (_, util, Rel
this.mergedCells.push([cell1, cell2]);
},

/**
* Added froze pane
* @param column - column number: 0, 1, 2 ...
* @param row - row number: 0, 1, 2 ...
* @param cell - 'A1'
*/
freezePane: function(column, row, cell) {
this._freezePane = {xSplit: column, ySplit: row, cell: cell};
},

/**
* Expects an array containing an object full of column format definitions.
* http://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.column.aspx
Expand Down
Loading

0 comments on commit fd59696

Please sign in to comment.