Skip to content

Commit

Permalink
Added ability to freeze pane.
Browse files Browse the repository at this point in the history
  • Loading branch information
pulavska committed Oct 2, 2015
1 parent af86af5 commit 956664a
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 9 deletions.
41 changes: 40 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 @@ -361,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 @@ -446,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 @@ -503,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
41 changes: 40 additions & 1 deletion dist/excel-builder.compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2996,6 +2996,7 @@ define('Excel/Worksheet',['underscore', './util', './RelationshipManager'], func
this._tables = [];
this._drawings = [];
this._rowInstructions = {};
this._freezePane = {};
this.initialize(config);
};
_.extend(Worksheet.prototype, {
Expand Down Expand Up @@ -3027,6 +3028,7 @@ define('Excel/Worksheet',['underscore', './util', './RelationshipManager'], func
_footers: this._footers,
_tables: this._tables,
_rowInstructions: this._rowInstructions,
_freezePane: this._freezePane,
name: this.name,
id: this.id
};
Expand Down Expand Up @@ -3337,7 +3339,12 @@ define('Excel/Worksheet',['underscore', './util', './RelationshipManager'], func
['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 @@ -3422,6 +3429,28 @@ define('Excel/Worksheet',['underscore', './util', './RelationshipManager'], func
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 @@ -3479,6 +3508,16 @@ define('Excel/Worksheet',['underscore', './util', './RelationshipManager'], func
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
6 changes: 3 additions & 3 deletions dist/excel-builder.compiled.min.js

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion dist/excel-builder.dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -3428,6 +3428,7 @@ define('Excel/Worksheet',['underscore', './util', './RelationshipManager'], func
this._tables = [];
this._drawings = [];
this._rowInstructions = {};
this._freezePane = {};
this.initialize(config);
};
_.extend(Worksheet.prototype, {
Expand Down Expand Up @@ -3459,6 +3460,7 @@ define('Excel/Worksheet',['underscore', './util', './RelationshipManager'], func
_footers: this._footers,
_tables: this._tables,
_rowInstructions: this._rowInstructions,
_freezePane: this._freezePane,
name: this.name,
id: this.id
};
Expand Down Expand Up @@ -3769,7 +3771,12 @@ define('Excel/Worksheet',['underscore', './util', './RelationshipManager'], func
['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 @@ -3854,6 +3861,28 @@ define('Excel/Worksheet',['underscore', './util', './RelationshipManager'], func
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 @@ -3911,6 +3940,16 @@ define('Excel/Worksheet',['underscore', './util', './RelationshipManager'], func
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
6 changes: 3 additions & 3 deletions dist/excel-builder.dist.min.js

Large diffs are not rendered by default.

0 comments on commit 956664a

Please sign in to comment.