Skip to content

Commit

Permalink
eslinting
Browse files Browse the repository at this point in the history
  • Loading branch information
guyonroche committed May 12, 2017
1 parent ccdebc9 commit 22ba773
Show file tree
Hide file tree
Showing 35 changed files with 185 additions and 186 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
dist
out
test
spec/manual/public/
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"func-names": ["off", "never"],
"linebreak-style": ["off"],
"no-var": ["off"],
"dot-notation": ["off"],
"one-var": ["off"],
"no-mixed-operators": ["error", {"allowSamePrecedence": true}],
"one-var-declaration-per-line": ["off"],
"no-prototype-builtins": ["off"],
"arrow-parens": ["off"],
Expand Down
59 changes: 57 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ To be clear, all contributions added to this library will be included in the lib
# Backlog

<ul>
<li>Still working my way through PRs and Issues and improving the tests.</li>
<li>Conditional Formatting.</li>
<li>There are still more print-settings to add; Fixed rows/cols, etc.</li>
<li>XLSX Streaming Reader.</li>
Expand Down Expand Up @@ -1070,7 +1069,63 @@ expect(worksheet.getColumn(3).collapsed).to.be.false;

## Images

TBD
Adding images to a worksheet is a two-step process.
First, the image is added to the workbook via the addImage() function which will also return an imageId value.
Then, using the imageId, the image can be added to the worksheet either as a tiled background or covering a cell range.

Note: As of this version, adjusting or transforming the image is not supported.

### Add Image to Workbook

The Workbook.addImage function supports adding images by filename or by Buffer.
Note that in both cases, the extension must be specified.
Valid extension values include 'jpeg', 'png', 'gif'.

```javascript
// add image to workbook by filename
var imageId1 = workbook.addImage({
filename: 'path/to/image.jpg',
extension: 'jpeg',
});

// add image to workbook by buffer
var imageId2 = workbook.addImage({
buffer: fs.readFileSync('path/to.image.png'),
extension: 'png',
});
```

### Add image background to worksheet

Using the image id from Workbook.addImage, the background to a worksheet can be set using the addBackgroundImage function

```javascript
// set background
worksheet.addBackgroundImage(imageId1);
```

### Add image over a range

Using the image id from Workbook.addImage, an image can be embedded within the worksheet to cover a range.
The coordinates calculated from the range will cover from the top-left of the first cell to the bottom right of the second.

```javascript
// insert an image over B2:D6
worksheet.addImage(imageId2, 'B2:D6');
```

Using a structure instead of a range string, it is possible to partially cover cells.

Note that the coordinate system used for this is zero based, so the top-left of A1 will be { col: 0, row: 0 }.
Fractions of cells can be specified by using floating point numbers, e.g. the midpoint of A1 is { col: 0.5, row: 0.5 }.

```javascript
// insert an image over part of B2:D6
worksheet.addImage(imageId2, {
tl: { col: 1.5, row: 1.5 },
br: { col: 3.5, row: 5.5 }
});
```

## File I/O

Expand Down
2 changes: 1 addition & 1 deletion excel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* or https://github.com/guyonroche/exceljs/blob/master/LICENSE
*/

module.exports = require('./dist/es3');
module.exports = require('./dist/es5');
38 changes: 24 additions & 14 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-contrib-copy');

grunt.initConfig({
babel: {
Expand Down Expand Up @@ -45,20 +46,29 @@ module.exports = function(grunt) {
'./dist/exceljs.min.js': ['./dist/exceljs.js']
}
},
es3: {
// es3: {
// files: [
// {
// expand: true,
// cwd: './build/lib/',
// src: ['*.js', '**/*.js'],
// dest: 'dist/es3/',
// ext: '.js',
// },
// {
// './dist/es3/index.js': ['./build/lib/exceljs.nodejs.js'],
// }
// ],
// },
},

copy: {
dist: {
files: [
{
expand: true,
cwd: './build/lib/',
src: ['*.js', '**/*.js'],
dest: 'dist/es3/',
ext: '.js',
},
{
'./dist/es3/index.js': ['./build/lib/exceljs.nodejs.js'],
}
],
},
{ expand: true, src: ['**'], cwd: './build/lib', dest: './dist/es5' },
{ src: './build/lib/exceljs.nodejs.js', dest: './dist/es5/index.js'},
]
}
},

jasmine: {
Expand All @@ -71,6 +81,6 @@ module.exports = function(grunt) {
},
});

grunt.registerTask('build', ['babel', 'browserify', 'uglify']);
grunt.registerTask('build', ['babel', 'browserify', 'uglify', 'copy']);
grunt.registerTask('ug', ['uglify']);
};
2 changes: 1 addition & 1 deletion lib/csv/stream-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ StreamConverter.prototype.convertInwards = function(data) {
return data;
};
StreamConverter.prototype.convertOutwards = function(data) {
if (typeof data === 'string') {
if (typeof data === 'string') {
data = new Buffer(data, this.innerEncoding);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/doc/worksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ Worksheet.prototype = {
rowArguments.push(insert[i] || null);
});
var row = this.getRow(i + 1);
// eslint-disable-next-line prefer-spread
row.splice.apply(row, rowArguments);
}
} else {
Expand Down Expand Up @@ -468,7 +469,7 @@ Worksheet.prototype = {
if (Array.isArray(results[0])) {
getResult = (row, col) => results[row - top][col - left];
} else {
getResult = (row, col) => results[(row - top) * width + (col - left)];
getResult = (row, col) => results[((row - top) * width) + (col - left)];
}
} else {
getResult = () => undefined;
Expand Down
8 changes: 3 additions & 5 deletions lib/exceljs.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ var ExcelJS = {
// Object.assign mono-fill
var Enums = require('./doc/enums');

for (var i in Enums) {
if (Enums.hasOwnProperty(i)) {
ExcelJS[i] = Enums[i];
}
}
Object.keys(Enums).forEach(key => {
ExcelJS[key] = Enums[key];
});

module.exports = ExcelJS;
2 changes: 2 additions & 0 deletions lib/stream/xlsx/hyperlink-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ utils.inherits(HyperlinkReader, events.EventEmitter, {
case 'cache':
this.hyperlinks = hyperlinks = {};
break;
default:
break;
}
if (!emitHyperlinks && !hyperlinks) {
entry.autodrain();
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/col-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var colCache = module.exports = {
}
}
if (level >= 2) {
while (n <= 26 + 26 * 26) {
while (n <= 26 + (26 * 26)) {
v = n - (26 + 1);
l1 = v % 26;
l2 = Math.floor(v / 26);
Expand All @@ -41,7 +41,7 @@ var colCache = module.exports = {
}
if (level >= 3) {
while (n <= 16384) {
v = n - (26 * 26 + 26 + 1);
v = n - ((26 * 26) + 26 + 1);
l1 = v % 26;
l2 = Math.floor(v / 26) % 26;
l3 = Math.floor(v / (26 * 26));
Expand Down Expand Up @@ -146,7 +146,7 @@ var colCache = module.exports = {

// convert [sheetName!][$]col[$]row[[$]col[$]row] into address or range structures
decodeEx: function(value) {
var groups = value.match(/(?:(?:(?:'((?:[^']|'')*)')|([^'^ ^!]*))!)?(.*)/);
var groups = value.match(/(?:(?:(?:'((?:[^']|'')*)')|([^'^ !]*))!)?(.*)/);

var sheetName = groups[1] || groups[2]; // Qouted and unqouted groups
var reference = groups[3]; // Remaining address
Expand Down
11 changes: 5 additions & 6 deletions lib/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ var inherits = function(cls, superCtor, statics, prototype) {
}

if (statics) {
for (i in statics) {
if (statics.hasOwnProperty(i)) {
Object.defineProperty(cls, i, Object.getOwnPropertyDescriptor(statics, i));
}
}
Object.keys(statics).forEach(i => {
Object.defineProperty(cls, i, Object.getOwnPropertyDescriptor(statics, i));
});
}

var properties = {
Expand Down Expand Up @@ -65,7 +63,7 @@ var utils = module.exports = {
},
inherits: inherits,
dateToExcel: function(d, date1904) {
return 25569 + d.getTime() / (24 * 3600 * 1000) - (date1904 ? 1462 : 0);
return 25569 + (d.getTime() / (24 * 3600 * 1000)) - (date1904 ? 1462 : 0);
},
excelToDate: function(v, date1904) {
return new Date((v - 25569 + (date1904 ? 1462 : 0)) * 24 * 3600 * 1000);
Expand All @@ -82,6 +80,7 @@ var utils = module.exports = {
return path.path + '/_rels/' + path.name + '.rels';
},
xmlEncode: function(text) {
// eslint-disable-next-line no-control-regex
return text.replace(/[<>&'"\x7F\x00-\x08\x0A-\x0C\x0E-\x1F]/g, function (c) {
switch (c) {
case '<': return '&lt;';
Expand Down
23 changes: 3 additions & 20 deletions lib/xlsx/xform/drawing/blip-fill-xform.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
/**
* 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.
*
* Copyright (c) 2016-2017 Guyon Roche
* LICENCE: MIT - please refer to LICENCE file included with this module
* or https://github.com/guyonroche/exceljs/blob/master/LICENSE
*/

'use strict';
Expand Down
23 changes: 3 additions & 20 deletions lib/xlsx/xform/drawing/blip-xform.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
/**
* 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.
*
* Copyright (c) 2016-2017 Guyon Roche
* LICENCE: MIT - please refer to LICENCE file included with this module
* or https://github.com/guyonroche/exceljs/blob/master/LICENSE
*/

'use strict';
Expand Down
4 changes: 2 additions & 2 deletions lib/xlsx/xform/drawing/cell-position-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ utils.inherits(CellPositionXform, BaseXform, {
switch(name) {
case this.tag:
this.model = {
col: this.map['xdr:col'].model + this.map['xdr:colOff'].model / 640000,
row: this.map['xdr:row'].model + this.map['xdr:rowOff'].model / 180000
col: this.map['xdr:col'].model + (this.map['xdr:colOff'].model / 640000),
row: this.map['xdr:row'].model + (this.map['xdr:rowOff'].model / 180000)
};
return false;
default:
Expand Down
23 changes: 3 additions & 20 deletions lib/xlsx/xform/drawing/nv-pic-pr-xform.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
/**
* 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.
*
* Copyright (c) 2016-2017 Guyon Roche
* LICENCE: MIT - please refer to LICENCE file included with this module
* or https://github.com/guyonroche/exceljs/blob/master/LICENSE
*/

'use strict';
Expand Down
12 changes: 0 additions & 12 deletions lib/xlsx/xform/drawing/nv-pic-pr.xml

This file was deleted.

Loading

0 comments on commit 22ba773

Please sign in to comment.