Skip to content

Commit

Permalink
merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
guyonroche committed May 14, 2019
2 parents d92676b + ea2ac44 commit 7f55eca
Show file tree
Hide file tree
Showing 259 changed files with 13,848 additions and 9,257 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ To be clear, all contributions added to this library will be included in the lib

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

// or, for node.js version 8+
const Excel = require('exceljs/nodejs');
```

## Create a Workbook
Expand Down Expand Up @@ -893,6 +896,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 +1034,6 @@ ws.getCell('A2').fill = {

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

#### Gradient Fills

Expand All @@ -1067,7 +1069,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
37 changes: 17 additions & 20 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 All @@ -64,20 +64,17 @@ module.exports = function(grunt) {

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

jasmine: {
dev: {
src: ['./dist/exceljs.js'],
options: {
specs: './build/web/exceljs.spec.js'
}
}
specs: './build/web/exceljs.spec.js',
},
},
},
});

Expand Down
2 changes: 1 addition & 1 deletion 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 PromishLib = require('../utils/promish');

function setValue(key, value, overwrite) {
if (overwrite === undefined) {
Expand Down
122 changes: 60 additions & 62 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 PromishLib = require('../utils/promish');
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)
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);
}
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) {
write(stream, options) {
return new PromishLib.Promish((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 = options.dateFormat;
const dateUTC = options.dateUTC;
const map =
options.map ||
(value => {
if (value) {
if (value.text || value.hyperlink) {
return value.hyperlink || value.text || '';
Expand All @@ -122,7 +123,7 @@ CSV.prototype = {
if (dateFormat) {
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;
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 7f55eca

Please sign in to comment.