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
12 changes: 10 additions & 2 deletions lib/xlsx/xform/core/content-types-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,25 @@ utils.inherits(ContentTypesXform, BaseXform, {

xmlStream.leafNode('Override', {PartName: '/xl/workbook.xml', ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml'});

var hasSharedStrings = false;
model.worksheets.forEach(function(worksheet) {
var name = '/xl/worksheets/sheet' + worksheet.id + '.xml';
xmlStream.leafNode('Override', {PartName: name, ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml'});

if (hasSharedStrings === false && worksheet.useSharedStrings === true) {
hasSharedStrings = true;
}
});

xmlStream.leafNode('Override', {PartName: '/xl/theme/theme1.xml',
ContentType: 'application/vnd.openxmlformats-officedocument.theme+xml'});
xmlStream.leafNode('Override', {PartName: '/xl/styles.xml',
ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml'});
xmlStream.leafNode('Override', {PartName: '/xl/sharedStrings.xml',
ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml'});

if (hasSharedStrings) {
xmlStream.leafNode('Override', {PartName: '/xl/sharedStrings.xml',
ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml'});
}

model.drawings && model.drawings.forEach(function(drawing) {
xmlStream.leafNode('Override', {PartName: '/xl/drawings/' + drawing.name + '.xml',
Expand Down
22 changes: 18 additions & 4 deletions spec/unit/xlsx/xform/core/content-types-xform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,32 @@ var testXformHelper = require('./../test-xform-helper');

var expectations = [
{
title: 'Three Sheets',
title: 'Three Sheets with shared strings',
create: function() { return new ContentTypesXform(); },
preparedModel: { worksheets: [{id: 1}, {id: 2}, {id: 3}, ], media: [], drawings: [] },
preparedModel: { worksheets: [{id: 1, useSharedStrings: true}, {id: 2, useSharedStrings: false}, {id: 3}, ], media: [], drawings: [] },
xml: fs.readFileSync(__dirname + '/data/content-types.01.xml').toString().replace(/\r\n/g, '\n'),
tests: ['render']
},
{
title: 'Images',
title: 'Images with shared strings',
create: function() { return new ContentTypesXform(); },
preparedModel: { worksheets: [{id: 1}, {id: 2}], media: [{type: 'image', extension: 'png'}, {type: 'image', extension: 'jpg'}], drawings: [] },
preparedModel: { worksheets: [{id: 1, useSharedStrings: false}, {id: 2, useSharedStrings: true}], media: [{type: 'image', extension: 'png'}, {type: 'image', extension: 'jpg'}], drawings: [] },
xml: fs.readFileSync(__dirname + '/data/content-types.02.xml').toString().replace(/\r\n/g, '\n'),
tests: ['render']
},
{
title: 'Three Sheets without shared strings',
create: function() { return new ContentTypesXform(); },
preparedModel: { worksheets: [{id: 1}, {id: 2}, {id: 3}, ], media: [], drawings: [] },
xml: fs.readFileSync(__dirname + '/data/content-types.03.xml').toString().replace(/\r\n/g, '\n'),
tests: ['render']
},
{
title: 'Images without shared strings',
create: function() { return new ContentTypesXform(); },
preparedModel: { worksheets: [{id: 1}, {id: 2, useSharedStrings: false}], media: [{type: 'image', extension: 'png'}, {type: 'image', extension: 'jpg'}], drawings: [] },
xml: fs.readFileSync(__dirname + '/data/content-types.04.xml').toString().replace(/\r\n/g, '\n'),
tests: ['render']
}
];

Expand Down
13 changes: 13 additions & 0 deletions spec/unit/xlsx/xform/core/data/content-types.03.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="xml" ContentType="application/xml"/>
<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>
<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>
<Override PartName="/xl/worksheets/sheet2.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>
<Override PartName="/xl/worksheets/sheet3.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>
<Override PartName="/xl/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>
<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
</Types>
14 changes: 14 additions & 0 deletions spec/unit/xlsx/xform/core/data/content-types.04.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="png" ContentType="image/png"/>
<Default Extension="jpg" ContentType="image/jpg"/>
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="xml" ContentType="application/xml"/>
<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>
<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>
<Override PartName="/xl/worksheets/sheet2.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>
<Override PartName="/xl/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>
<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
</Types>