Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
guyonroche authored May 16, 2019
2 parents c9edb84 + 9bf2eac commit 9824b98
Show file tree
Hide file tree
Showing 265 changed files with 14,568 additions and 9,745 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"quotes": ["error", "single"],
"semi": ["error", "always"],
"space-before-function-paren": ["error", "never"],
"strict": ["off"]
"strict": ["off"],
"class-methods-use-this": ["off"]
}
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ spec/integration/data/gold
/spec/manual/public/exceljs.js
/spec/manual/public/exceljs.min.js

package-lock.json
package-lock.json

# optional switch off tests
.disable-test-*
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ npm install exceljs
Merged <a href="https://github.com/exceljs/exceljs/pull/799">Add support for repeated columns on every page when printing. #799</a>.
Many thanks to <a href="https://github.com/FreakenK">Jasmin Auger</a> for this contribution.
</li>
<li>
Merged <a href="https://github.com/exceljs/exceljs/pull/815">Do not use a promise polyfill on modern setups #815</a>.
Many thanks to <a href="https://github.com/alubbe">Andreas Lubbe</a> for this contribution.
</li>
</ul>

# Contributions
Expand Down Expand Up @@ -139,8 +143,20 @@ To be clear, all contributions added to this library will be included in the lib

# Interface

## Importing

The default export is a transpiled ES5 version with a Promise polyfill - this offers the highest level of compatibility.

```javascript
var Excel = require('exceljs');
import Excel from 'exceljs';
```

However, if you use this library on a modern node.js version (>=8) or on the frontend using a bundler (or can focus on just evergreen browsers), we recommend to use these imports:

```javascript
const Excel = require('exceljs/modern.nodejs');
import Excel from 'exceljs/modern.browser';
```

## Create a Workbook
Expand Down Expand Up @@ -893,6 +909,7 @@ font.size = 20; // Cell A3 now has font size 20!
| family | Font family for fallback. An integer value. | 1 - Serif, 2 - Sans Serif, 3 - Mono, Others - unknown |
| scheme | Font scheme. | 'minor', 'major', 'none' |
| charset | Font charset. An integer value. | 1, 2, etc. |
| size | Font size. An integer value. | 9, 10, 12, 16, etc. |
| color | Colour description, an object containing an ARGB value. | { argb: 'FFFF0000'} |
| bold | Font **weight** | true, false |
| italic | Font *slope* | true, false |
Expand Down Expand Up @@ -1030,7 +1047,6 @@ ws.getCell('A2').fill = {

* none
* solid
* darkVertical
* darkGray
* mediumGray
* lightGray
Expand All @@ -1048,7 +1064,6 @@ ws.getCell('A2').fill = {
* lightUp
* lightGrid
* lightTrellis
* lightGrid

#### Gradient Fills

Expand All @@ -1067,7 +1082,7 @@ For example, Excel only supports angle gradients of 0, 45, 90 and 135.
Similarly the sequence of stops may also be limited by the UI with positions [0,1] or [0,0.5,1] as the only options.
Take care with this fill to be sure it is supported by the target XLSX viewers.

#### Rich Text
### Rich Text

Individual cells now support rich text or in-cell formatting.
Rich text values can control the font properties of any number of sub-strings within the text value.
Expand Down
30 changes: 15 additions & 15 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,41 @@ module.exports = function(grunt) {
grunt.initConfig({
babel: {
options: {
sourceMap: true
sourceMap: true,
},
dist: {
files: [
{
expand: true,
src: ['./lib/**/*.js', './spec/browser/*.js'],
dest: './build/'
}
]
}
dest: './build/',
},
],
},
},
browserify: {
bundle: {
src: ['./build/lib/exceljs.browser.js'],
dest: './dist/exceljs.js',
options: {
browserifyOptions: {
standalone: 'ExcelJS'
}
}
standalone: 'ExcelJS',
},
},
},
spec: {
src: ['./build/spec/browser/exceljs.spec.js'],
dest: './build/web/exceljs.spec.js'
dest: './build/web/exceljs.spec.js',
},
},
uglify: {
options: {
banner: '/*! ExcelJS <%= grunt.template.today("dd-mm-yyyy") %> */\n'
banner: '/*! ExcelJS <%= grunt.template.today("dd-mm-yyyy") %> */\n',
},
dist: {
files: {
'./dist/exceljs.min.js': ['./dist/exceljs.js']
}
'./dist/exceljs.min.js': ['./dist/exceljs.js'],
},
},
// es3: {
// files: [
Expand Down Expand Up @@ -76,9 +76,9 @@ module.exports = function(grunt) {
dev: {
src: ['./dist/exceljs.js'],
options: {
specs: './build/web/exceljs.spec.js'
}
}
specs: './build/web/exceljs.spec.js',
},
},
},
});

Expand Down
6 changes: 3 additions & 3 deletions lib/config/set-value.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var PromishLib = require('../utils/promish');
const PromiseLib = require('../utils/promise');

function setValue(key, value, overwrite) {
if (overwrite === undefined) {
Expand All @@ -9,8 +9,8 @@ function setValue(key, value, overwrite) {
}
switch (key.toLowerCase()) {
case 'promise':
if (!overwrite && PromishLib.Promish) return;
PromishLib.Promish = value;
if (!overwrite && PromiseLib.Promise) return;
PromiseLib.Promise = value;
break;
default:
break;
Expand Down
132 changes: 65 additions & 67 deletions lib/csv/csv.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
'use strict';

const fs = require('fs');
const csv = require('fast-csv');
const moment = require('moment');
const PromiseLib = require('../utils/promise');
const StreamBuf = require('../utils/stream-buf');

var fs = require('fs');
var csv = require('fast-csv');
var moment = require('moment');
var PromishLib = require('../utils/promish');
var StreamBuf = require('../utils/stream-buf');
const utils = require('../utils/utils');

var utils = require('../utils/utils');

var CSV = module.exports = function(workbook) {
const CSV = (module.exports = function(workbook) {
this.workbook = workbook;
this.worksheet = null;
};
});

/* eslint-disable quote-props */
var SpecialValues = {
'true': true,
'false': false,
const SpecialValues = {
true: true,
false: false,
'#N/A': { error: '#N/A' },
'#REF!': { error: '#REF!' },
'#NAME?': { error: '#NAME?' },
Expand All @@ -28,89 +27,91 @@ var SpecialValues = {
};
/* eslint-ensable quote-props */


CSV.prototype = {
readFile: function(filename, options) {
var self = this;
readFile(filename, options) {
const self = this;
options = options || {};
var stream;
return utils.fs.exists(filename)
.then(function(exists) {
let stream;
return utils.fs
.exists(filename)
.then(exists => {
if (!exists) {
throw new Error('File not found: ' + filename);
throw new Error(`File not found: ${filename}`);
}
stream = fs.createReadStream(filename);
return self.read(stream, options);
})
.then(function(worksheet) {
.then(worksheet => {
stream.close();
return worksheet;
});
},
read: function(stream, options) {
read(stream, options) {
options = options || {};
return new PromishLib.Promish((resolve, reject) => {
var csvStream = this.createInputStream(options)
return new PromiseLib.Promise((resolve, reject) => {
const csvStream = this.createInputStream(options)
.on('worksheet', resolve)
.on('error', reject);

stream.pipe(csvStream);
});
},
createInputStream: function(options) {
createInputStream(options) {
options = options || {};
var worksheet = this.workbook.addWorksheet(options.sheetName);
const worksheet = this.workbook.addWorksheet(options.sheetName);

var dateFormats = options.dateFormats || [
moment.ISO_8601,
'MM-DD-YYYY',
'YYYY-MM-DD'
];
var map = options.map || function(datum) {
const dateFormats = options.dateFormats || [moment.ISO_8601, 'MM-DD-YYYY', 'YYYY-MM-DD'];
const map =
options.map ||
function(datum) {
if (datum === '') {
return null;
}
if (!isNaN(datum)) {
return parseFloat(datum);
const datumNumber = Number(datum);
if (!Number.isNaN(datumNumber)) {
return datumNumber;
}
var dt = moment(datum, dateFormats, true);
const dt = moment(datum, dateFormats, true);
if (dt.isValid()) {
return new Date(dt.valueOf());
}
var special = SpecialValues[datum];
const special = SpecialValues[datum];
if (special !== undefined) {
return special;
}
return datum;
};

var csvStream = csv(options)
.on('data', function(data) {
const csvStream = csv(options)
.on('data', data => {
worksheet.addRow(data.map(map));
})
.on('end', function() {
.on('end', () => {
csvStream.emit('worksheet', worksheet);
});
return csvStream;
},

write: function(stream, options) {
return new PromishLib.Promish((resolve, reject) => {
write(stream, options) {
return new PromiseLib.Promise((resolve, reject) => {
options = options || {};
// var encoding = options.encoding || 'utf8';
// var separator = options.separator || ',';
// var quoteChar = options.quoteChar || '\'';
// const encoding = options.encoding || 'utf8';
// const separator = options.separator || ',';
// const quoteChar = options.quoteChar || '\'';

var worksheet = this.workbook.getWorksheet(options.sheetName || options.sheetId);
const worksheet = this.workbook.getWorksheet(options.sheetName || options.sheetId);

var csvStream = csv.createWriteStream(options);
stream.on('finish', () => { resolve(); });
const csvStream = csv.createWriteStream(options);
stream.on('finish', () => {
resolve();
});
csvStream.on('error', reject);
csvStream.pipe(stream);

var dateFormat = options.dateFormat;
var dateUTC = options.dateUTC;
var map = options.map || (value => {
const {dateFormat, dateUTC} = options;
const map =
options.map ||
(value => {
if (value) {
if (value.text || value.hyperlink) {
return value.hyperlink || value.text || '';
Expand All @@ -120,9 +121,9 @@ CSV.prototype = {
}
if (value instanceof Date) {
if (dateFormat) {
dateUTC ? moment.utc(value).format(dateFormat) : moment(value).format(dateFormat);
return dateUTC ? moment.utc(value).format(dateFormat) : moment(value).format(dateFormat);
}
return dateUTC ? moment.utc(value).format() : moment(value).format()
return dateUTC ? moment.utc(value).format() : moment(value).format();
}
if (value.error) {
return value.error;
Expand All @@ -134,16 +135,16 @@ CSV.prototype = {
return value;
});

var includeEmptyRows = (options.includeEmptyRows === undefined) || options.includeEmptyRows;
var lastRow = 1;
const includeEmptyRows = options.includeEmptyRows === undefined || options.includeEmptyRows;
let lastRow = 1;
if (worksheet) {
worksheet.eachRow(function(row, rowNumber) {
worksheet.eachRow((row, rowNumber) => {
if (includeEmptyRows) {
while (lastRow++ < rowNumber - 1) {
csvStream.write([]);
}
}
var values = row.values;
const {values} = row;
values.shift();
csvStream.write(values.map(map));
lastRow = rowNumber;
Expand All @@ -152,22 +153,19 @@ CSV.prototype = {
csvStream.end();
});
},
writeFile: function(filename, options) {
writeFile(filename, options) {
options = options || {};

var streamOptions = {
encoding: options.encoding || 'utf8'
const streamOptions = {
encoding: options.encoding || 'utf8',
};
var stream = fs.createWriteStream(filename, streamOptions);
const stream = fs.createWriteStream(filename, streamOptions);

return this.write(stream, options);
},
writeBuffer: function(options) {
var self = this;
var stream = new StreamBuf();
return self.write(stream, options)
.then(function() {
return stream.read();
});
}
writeBuffer(options) {
const self = this;
const stream = new StreamBuf();
return self.write(stream, options).then(() => stream.read());
},
};
Loading

0 comments on commit 9824b98

Please sign in to comment.