Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
5 changes: 4 additions & 1 deletion lib/doc/workbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var CSV = require('./../csv/csv');
var Workbook = module.exports = function() {
this.created = new Date();
this.modified = this.created;
this.properties = {};
this._worksheets = [];
this.views = [];
this._definedNames = new DefinedNames();
Expand Down Expand Up @@ -140,6 +141,7 @@ Workbook.prototype = {
lastPrinted: this.lastPrinted,
created: this.created,
modified: this.modified,
properties: this.properties,
worksheets: this._worksheets.filter(Boolean).map(function(worksheet) { return worksheet.model; }),
definedNames: this._definedNames.model,
views: this.views,
Expand All @@ -151,7 +153,7 @@ Workbook.prototype = {
category: this.category,
description: this.description,
language: this.language,
revision: this.revision
revision: this.revision,
};
},
set model(value) {
Expand All @@ -173,6 +175,7 @@ Workbook.prototype = {
this.language = value.language;
this.revision = value.revision;

this.properties = value.properties;
this._worksheets = [];
value.worksheets.forEach(function(worksheetModel) {
var id = worksheetModel.id;
Expand Down
3 changes: 2 additions & 1 deletion lib/stream/xlsx/workbook-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ WorkbookWriter.prototype = {
var model = {
worksheets: this._worksheets.filter(Boolean),
definedNames: this._definedNames.model,
views: this.views
views: this.views,
properties: {}
};

return new Bluebird(function(resolve) {
Expand Down
58 changes: 58 additions & 0 deletions lib/xlsx/xform/book/workbook-properties-xform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (c) 2016 Guyon Roche
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
'use strict';

var utils = require('../../../utils/utils');
var BaseXform = require('../base-xform');

var WorksheetPropertiesXform = module.exports = function() {
};

utils.inherits(WorksheetPropertiesXform, BaseXform, {

render: function(xmlStream, model) {
xmlStream.leafNode('workbookPr', {
date1904: model.date1904,
defaultThemeVersion: 164011,
filterPrivacy: 1
});
},

parseOpen: function(node) {
if (node.name === 'workbookPr') {
this.model = {};

if (node.attributes.date1904 !== undefined) {
this.model.date1904 = parseInt(node.attributes.date1904);
};
return true;
} else {
return false;
}
},
parseText: function() {
},
parseClose: function() {
return false;
}
});
11 changes: 6 additions & 5 deletions lib/xlsx/xform/book/workbook-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ var ListXform = require('../list-xform');
var DefinedNameXform = require('./defined-name-xform');
var SheetXform = require('./sheet-xform');
var WorkbookViewXform = require('./workbook-view-xform');
var WorkbookPropertiesXform = require('./workbook-properties-xform');

var WorkbookXform = module.exports = function() {
this.map = {
fileVersion: WorkbookXform.STATIC_XFORMS.fileVersion,
workbookPr: WorkbookXform.STATIC_XFORMS.workbookPr,
workbookPr: new WorkbookPropertiesXform(),
bookViews: new ListXform({tag: 'bookViews', count: false, childXform: new WorkbookViewXform()}),
sheets: new ListXform({tag: 'sheets', count: false, childXform: new SheetXform()}),
definedNames: new ListXform({tag: 'definedNames', count: false, childXform: new DefinedNameXform()}),
Expand All @@ -56,7 +57,6 @@ utils.inherits(WorkbookXform, BaseXform, {
},
STATIC_XFORMS: {
fileVersion: new StaticXform({tag: 'fileVersion', $: {appName: 'xl', lastEdited: 5, lowestEdited: 5, rupBuild: 9303}}),
workbookPr: new StaticXform({tag: 'workbookPr', $: {defaultThemeVersion: 164011, filterPrivacy: 1}}),
calcPr: new StaticXform({tag: 'calcPr', $: {calcId: 171027}})
}
},{
Expand Down Expand Up @@ -88,7 +88,7 @@ utils.inherits(WorkbookXform, BaseXform, {
xmlStream.openNode('workbook', WorkbookXform.WORKBOOK_ATTRIBUTES);

this.map.fileVersion.render(xmlStream);
this.map.workbookPr.render(xmlStream);
this.map.workbookPr.render(xmlStream, model.properties);
this.map.bookViews.render(xmlStream, model.views);
this.map.sheets.render(xmlStream, model.sheets);
this.map.definedNames.render(xmlStream, model.definedNames);
Expand Down Expand Up @@ -129,12 +129,13 @@ utils.inherits(WorkbookXform, BaseXform, {
switch(name) {
case 'workbook':
this.model = {
sheets: this.map.sheets.model
sheets: this.map.sheets.model,
properties: this.map.workbookPr.model,
views: this.map.bookViews.model
};
if (this.map.definedNames.model) {
this.model.definedNames = this.map.definedNames.model;
}
this.model.views = this.map.bookViews.model;

return false;
default:
Expand Down
1 change: 1 addition & 0 deletions lib/xlsx/xlsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ XLSX.prototype = {
model.sheets = workbook.sheets;
model.definedNames = workbook.definedNames;
model.views = workbook.views;
model.properties = workbook.properties;
});
break;
case 'xl/_rels/workbook.xml.rels':
Expand Down
5 changes: 4 additions & 1 deletion spec/unit/xlsx/xform/book/data/book.1.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
],
"sheets": [
{"name": "Values", "id": 1, "rId": "rId1"}
]
],
"properties": {
"date1904": 1
}
}
2 changes: 1 addition & 1 deletion spec/unit/xlsx/xform/book/data/book.1.2.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x15" xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main">
<fileVersion appName="xl" lastEdited="5" lowestEdited="5" rupBuild="9303"/>
<workbookPr filterPrivacy="1" defaultThemeVersion="164011"/>
<workbookPr filterPrivacy="1" defaultThemeVersion="164011" date1904="1"/>
<bookViews>
<workbookView visibility="hidden" xWindow="0" yWindow="0" windowWidth="12000" windowHeight="24000"/>
</bookViews>
Expand Down
5 changes: 4 additions & 1 deletion spec/unit/xlsx/xform/book/data/book.1.3.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
],
"sheets": [
{"name": "Values", "id": 1, "rId": "rId1"}
]
],
"properties": {
"date1904": 1
}
}
27 changes: 27 additions & 0 deletions spec/unit/xlsx/xform/book/workbook-properties-xform.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

var WorkbookPropertiesXform = require('../../../../../lib/xlsx/xform/book/workbook-properties-xform');
var testXformHelper = require('./../test-xform-helper');

var expectations = [
{
title: 'default',
create: function() { return new WorkbookPropertiesXform(); },
preparedModel: {},
xml: '<workbookPr defaultThemeVersion="164011" filterPrivacy="1"></workbookPr>',
parsedModel: {},
tests: ['render', 'renderIn']
},
{
title: 'date1904',
create: function() { return new WorkbookPropertiesXform(); },
preparedModel: { date1904: 1},
xml: '<workbookPr date1904="1" defaultThemeVersion="164011" filterPrivacy="1"></workbookPr>',
parsedModel: { date1904: 1},
tests: ['render', 'renderIn', 'parse']
}
];

describe('WorkbookPropertiesXform', function() {
testXformHelper(expectations);
});