Skip to content

Sheet add state for hidden or show #577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/doc/worksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ var Worksheet = module.exports = function(options) {
// and a name
this.name = options.name || 'Sheet' + this.id;

// add a state
this.state = options.state || 'show';

// rows allows access organised by row. Sparse array of arrays indexed by row-1, col
// Note: _rows is zero based. Must subtract 1 to go from cell.row to index
this._rows = [];
Expand All @@ -46,7 +49,7 @@ var Worksheet = module.exports = function(options) {

// record of all row and column pageBreaks
this.rowBreaks = [];

this._workbook = options.workbook;

// for tabColor, default row height, outline levels, etc
Expand All @@ -56,7 +59,7 @@ var Worksheet = module.exports = function(options) {
outlineLevelCol: 0,
outlineLevelRow: 0
}, options.properties);

// for all things printing
this.pageSetup = Object.assign({}, {
margins: {left: 0.7, right: 0.7, top: 0.75, bottom: 0.75, header: 0.3, footer: 0.3 },
Expand Down Expand Up @@ -207,7 +210,7 @@ Worksheet.prototype = {
}
});
}

// splice column definitions
var nExpand = inserts.length - count;
var nKeep = start + count;
Expand Down Expand Up @@ -313,7 +316,7 @@ Worksheet.prototype = {
self.addRow(row);
});
},

spliceRows: function(start, count) {
// same problem as row.splice, except worse.
var inserts = Array.prototype.slice.call(arguments, 2);
Expand Down Expand Up @@ -436,7 +439,7 @@ Worksheet.prototype = {
delete this._merges[master.address];
}
},

get hasMerges() {
return _.some(this._merges, function() {
// TODO: this doesn't look right
Expand Down Expand Up @@ -559,6 +562,7 @@ Worksheet.prototype = {
name: this.name,
dataValidations: this.dataValidations.model,
properties: this.properties,
state: this.state,
pageSetup: this.pageSetup,
rowBreaks: this.rowBreaks,
views: this.views,
Expand Down
1 change: 1 addition & 0 deletions lib/stream/xlsx/workbook-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ WorkbookWriter.prototype = {
workbook: this,
useSharedStrings: useSharedStrings,
properties: options.properties,
state: options.state,
pageSetup: options.pageSetup,
views: options.views,
autoFilter: options.autoFilter
Expand Down
3 changes: 3 additions & 0 deletions lib/stream/xlsx/worksheet-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ var WorksheetWriter = module.exports = function(options) {
// and a name
this.name = options.name || 'Sheet' + this.id;

// add a state
this.state = options.state || 'show';

// rows are stored here while they need to be worked on.
// when they are committed, they will be deleted.
this._rows = [];
Expand Down
4 changes: 2 additions & 2 deletions lib/xlsx/workbook.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<workbookView xWindow="480" yWindow="60" windowWidth="18195" windowHeight="8505"/>
</bookViews>
<sheets>
<% worksheets.forEach(function(worksheet) { %><sheet name="<%=worksheet.name%>" sheetId="<%=worksheet.id%>" r:id="<%=worksheet.rId%>"/>
<% worksheets.forEach(function(worksheet) { %><sheet name="<%=worksheet.name%>" state="<%=worksheet.state%>" sheetId="<%=worksheet.id%>" r:id="<%=worksheet.rId%>"/>
<% }); %>
</sheets>
<%=definedNames.xml%>
<calcPr calcId="145621"/>
</workbook>
</workbook>
6 changes: 4 additions & 2 deletions lib/xlsx/xform/book/sheet-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ var WorksheetXform = module.exports = function() {
};

utils.inherits(WorksheetXform, BaseXform, {

render: function(xmlStream, model) {
xmlStream.leafNode('sheet', {
sheetId: model.id,
name: model.name,
state: model.state,
'r:id': model.rId
});
},

parseOpen: function(node) {
if (node.name === 'sheet') {
this.model = {
name: utils.xmlDecode(node.attributes.name),
id: parseInt(node.attributes.sheetId, 10),
state: node.attributes.state,
rId: node.attributes['r:id']
};
return true;
Expand Down
1 change: 1 addition & 0 deletions lib/xlsx/xform/book/workbook-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ utils.inherits(WorkbookXform, BaseXform, {
if (worksheet) {
worksheet.name = sheet.name;
worksheet.id = sheet.id;
worksheet.state = sheet.state;
worksheets[index++] = worksheet;
}
});
Expand Down