effective_datatables 4.17.4 → 4.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +21 -0
- data/app/assets/javascripts/dataTables/UPGRADE.md +17 -0
- data/app/assets/javascripts/dataTables/buttons/buttons.bootstrap4.js +73 -19
- data/app/assets/javascripts/dataTables/buttons/buttons.colVis.js +166 -120
- data/app/assets/javascripts/dataTables/buttons/buttons.html5.js +749 -667
- data/app/assets/javascripts/dataTables/buttons/buttons.print.js +96 -64
- data/app/assets/javascripts/dataTables/buttons/dataTables.buttons.js +1568 -909
- data/app/assets/javascripts/dataTables/dataTables.bootstrap4.js +172 -154
- data/app/assets/javascripts/dataTables/jquery.dataTables.js +3119 -2704
- data/app/assets/javascripts/dataTables/responsive/dataTables.responsive.js +707 -531
- data/app/assets/javascripts/dataTables/responsive/responsive.bootstrap4.js +61 -33
- data/app/assets/javascripts/dataTables/rowReorder/dataTables.rowReorder.js +961 -740
- data/app/assets/javascripts/dataTables/rowReorder/rowReorder.bootstrap4.js +50 -30
- data/app/assets/javascripts/effective_datatables/filters.js.coffee +88 -0
- data/app/assets/stylesheets/dataTables/buttons/buttons.bootstrap4.scss +178 -151
- data/app/assets/stylesheets/dataTables/dataTables.bootstrap4.scss +300 -81
- data/app/assets/stylesheets/dataTables/responsive/responsive.bootstrap4.scss +54 -71
- data/app/assets/stylesheets/dataTables/rowReorder/rowReorder.bootstrap4.scss +23 -4
- data/app/assets/stylesheets/effective_datatables/_overrides.bootstrap4.scss +81 -39
- data/app/views/effective/datatables/_filter_date_range.html.haml +37 -9
- data/app/views/effective/datatables/_filters.html.haml +1 -1
- data/lib/effective_datatables/version.rb +1 -1
- metadata +3 -2
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* HTML5 export buttons for Buttons and DataTables.
|
3
|
-
*
|
3
|
+
* © SpryMedia Ltd - datatables.net/license
|
4
4
|
*
|
5
5
|
* FileSaver.js (1.3.3) - MIT license
|
6
6
|
* Copyright © 2016 Eli Grey - http://eligrey.com
|
@@ -15,21 +15,37 @@
|
|
15
15
|
}
|
16
16
|
else if ( typeof exports === 'object' ) {
|
17
17
|
// CommonJS
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
if ( ! $ || ! $.fn.dataTable ) {
|
24
|
-
$ = require('datatables.net')(root, $).$;
|
18
|
+
var jq = require('jquery');
|
19
|
+
var cjsRequires = function (root, $) {
|
20
|
+
if ( ! $.fn.dataTable ) {
|
21
|
+
require('datatables.net')(root, $);
|
25
22
|
}
|
26
23
|
|
27
24
|
if ( ! $.fn.dataTable.Buttons ) {
|
28
25
|
require('datatables.net-buttons')(root, $);
|
29
26
|
}
|
30
|
-
|
31
|
-
return factory( $, root, root.document, jszip, pdfmake );
|
32
27
|
};
|
28
|
+
|
29
|
+
if (typeof window === 'undefined') {
|
30
|
+
module.exports = function (root, $, jszip, pdfmake) {
|
31
|
+
if ( ! root ) {
|
32
|
+
// CommonJS environments without a window global must pass a
|
33
|
+
// root. This will give an error otherwise
|
34
|
+
root = window;
|
35
|
+
}
|
36
|
+
|
37
|
+
if ( ! $ ) {
|
38
|
+
$ = jq( root );
|
39
|
+
}
|
40
|
+
|
41
|
+
cjsRequires( root, $ );
|
42
|
+
return factory( $, root, root.document, jszip, pdfmake );
|
43
|
+
};
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
cjsRequires( window, jq );
|
47
|
+
module.exports = factory( jq, window, window.document );
|
48
|
+
}
|
33
49
|
}
|
34
50
|
else {
|
35
51
|
// Browser
|
@@ -39,29 +55,33 @@
|
|
39
55
|
'use strict';
|
40
56
|
var DataTable = $.fn.dataTable;
|
41
57
|
|
58
|
+
|
59
|
+
|
42
60
|
// Allow the constructor to pass in JSZip and PDFMake from external requires.
|
43
61
|
// Otherwise, use globally defined variables, if they are available.
|
44
|
-
|
45
|
-
|
62
|
+
var useJszip;
|
63
|
+
var usePdfmake;
|
64
|
+
|
65
|
+
function _jsZip() {
|
66
|
+
return useJszip || window.JSZip;
|
46
67
|
}
|
47
|
-
function _pdfMake
|
48
|
-
return
|
68
|
+
function _pdfMake() {
|
69
|
+
return usePdfmake || window.pdfMake;
|
49
70
|
}
|
50
71
|
|
51
72
|
DataTable.Buttons.pdfMake = function (_) {
|
52
|
-
if (
|
73
|
+
if (!_) {
|
53
74
|
return _pdfMake();
|
54
75
|
}
|
55
|
-
|
56
|
-
}
|
76
|
+
usePdfmake = _;
|
77
|
+
};
|
57
78
|
|
58
79
|
DataTable.Buttons.jszip = function (_) {
|
59
|
-
if (
|
80
|
+
if (!_) {
|
60
81
|
return _jsZip();
|
61
82
|
}
|
62
|
-
|
63
|
-
}
|
64
|
-
|
83
|
+
useJszip = _;
|
84
|
+
};
|
65
85
|
|
66
86
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
67
87
|
* FileSaver.js dependency
|
@@ -69,50 +89,55 @@ DataTable.Buttons.jszip = function (_) {
|
|
69
89
|
|
70
90
|
/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
|
71
91
|
|
72
|
-
var _saveAs = (function(view) {
|
73
|
-
|
92
|
+
var _saveAs = (function (view) {
|
93
|
+
'use strict';
|
74
94
|
// IE <10 is explicitly unsupported
|
75
|
-
if (
|
95
|
+
if (
|
96
|
+
typeof view === 'undefined' ||
|
97
|
+
(typeof navigator !== 'undefined' && /MSIE [1-9]\./.test(navigator.userAgent))
|
98
|
+
) {
|
76
99
|
return;
|
77
100
|
}
|
78
|
-
var
|
79
|
-
|
80
|
-
|
81
|
-
, get_URL = function() {
|
101
|
+
var doc = view.document,
|
102
|
+
// only get URL when necessary in case Blob.js hasn't overridden it yet
|
103
|
+
get_URL = function () {
|
82
104
|
return view.URL || view.webkitURL || view;
|
83
|
-
}
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
var event = new MouseEvent(
|
105
|
+
},
|
106
|
+
save_link = doc.createElementNS('http://www.w3.org/1999/xhtml', 'a'),
|
107
|
+
can_use_save_link = 'download' in save_link,
|
108
|
+
click = function (node) {
|
109
|
+
var event = new MouseEvent('click');
|
88
110
|
node.dispatchEvent(event);
|
89
|
-
}
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
(view.setImmediate || view.setTimeout)(function() {
|
111
|
+
},
|
112
|
+
is_safari = /constructor/i.test(view.HTMLElement) || view.safari,
|
113
|
+
is_chrome_ios = /CriOS\/[\d]+/.test(navigator.userAgent),
|
114
|
+
throw_outside = function (ex) {
|
115
|
+
(view.setImmediate || view.setTimeout)(function () {
|
94
116
|
throw ex;
|
95
117
|
}, 0);
|
96
|
-
}
|
97
|
-
|
118
|
+
},
|
119
|
+
force_saveable_type = 'application/octet-stream',
|
98
120
|
// the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to
|
99
|
-
|
100
|
-
|
101
|
-
var revoker = function() {
|
102
|
-
if (typeof file ===
|
121
|
+
arbitrary_revoke_timeout = 1000 * 40, // in ms
|
122
|
+
revoke = function (file) {
|
123
|
+
var revoker = function () {
|
124
|
+
if (typeof file === 'string') {
|
125
|
+
// file is an object URL
|
103
126
|
get_URL().revokeObjectURL(file);
|
104
|
-
}
|
127
|
+
}
|
128
|
+
else {
|
129
|
+
// file is a File
|
105
130
|
file.remove();
|
106
131
|
}
|
107
132
|
};
|
108
133
|
setTimeout(revoker, arbitrary_revoke_timeout);
|
109
|
-
}
|
110
|
-
|
134
|
+
},
|
135
|
+
dispatch = function (filesaver, event_types, event) {
|
111
136
|
event_types = [].concat(event_types);
|
112
137
|
var i = event_types.length;
|
113
138
|
while (i--) {
|
114
|
-
var listener = filesaver[
|
115
|
-
if (typeof listener ===
|
139
|
+
var listener = filesaver['on' + event_types[i]];
|
140
|
+
if (typeof listener === 'function') {
|
116
141
|
try {
|
117
142
|
listener.call(filesaver, event || filesaver);
|
118
143
|
} catch (ex) {
|
@@ -120,38 +145,43 @@ var _saveAs = (function(view) {
|
|
120
145
|
}
|
121
146
|
}
|
122
147
|
}
|
123
|
-
}
|
124
|
-
|
148
|
+
},
|
149
|
+
auto_bom = function (blob) {
|
125
150
|
// prepend BOM for UTF-8 XML and text/* types (including HTML)
|
126
151
|
// note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
|
127
|
-
if (
|
128
|
-
|
152
|
+
if (
|
153
|
+
/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(
|
154
|
+
blob.type
|
155
|
+
)
|
156
|
+
) {
|
157
|
+
return new Blob([String.fromCharCode(0xfeff), blob], { type: blob.type });
|
129
158
|
}
|
130
159
|
return blob;
|
131
|
-
}
|
132
|
-
|
160
|
+
},
|
161
|
+
FileSaver = function (blob, name, no_auto_bom) {
|
133
162
|
if (!no_auto_bom) {
|
134
163
|
blob = auto_bom(blob);
|
135
164
|
}
|
136
165
|
// First try a.download, then web filesystem, then object URLs
|
137
|
-
var
|
138
|
-
|
139
|
-
|
140
|
-
,
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
}
|
166
|
+
var filesaver = this,
|
167
|
+
type = blob.type,
|
168
|
+
force = type === force_saveable_type,
|
169
|
+
object_url,
|
170
|
+
dispatch_all = function () {
|
171
|
+
dispatch(filesaver, 'writestart progress write writeend'.split(' '));
|
172
|
+
},
|
145
173
|
// on any filesys errors revert to saving with object URLs
|
146
|
-
|
174
|
+
fs_error = function () {
|
147
175
|
if ((is_chrome_ios || (force && is_safari)) && view.FileReader) {
|
148
176
|
// Safari doesn't allow downloading of blob urls
|
149
177
|
var reader = new FileReader();
|
150
|
-
reader.onloadend = function() {
|
151
|
-
var url = is_chrome_ios
|
178
|
+
reader.onloadend = function () {
|
179
|
+
var url = is_chrome_ios
|
180
|
+
? reader.result
|
181
|
+
: reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;');
|
152
182
|
var popup = view.open(url, '_blank');
|
153
|
-
if(!popup) view.location.href = url;
|
154
|
-
url=undefined; // release reference before dispatching
|
183
|
+
if (!popup) view.location.href = url;
|
184
|
+
url = undefined; // release reference before dispatching
|
155
185
|
filesaver.readyState = filesaver.DONE;
|
156
186
|
dispatch_all();
|
157
187
|
};
|
@@ -165,8 +195,9 @@ var _saveAs = (function(view) {
|
|
165
195
|
}
|
166
196
|
if (force) {
|
167
197
|
view.location.href = object_url;
|
168
|
-
}
|
169
|
-
|
198
|
+
}
|
199
|
+
else {
|
200
|
+
var opened = view.open(object_url, '_blank');
|
170
201
|
if (!opened) {
|
171
202
|
// Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html
|
172
203
|
view.location.href = object_url;
|
@@ -175,13 +206,12 @@ var _saveAs = (function(view) {
|
|
175
206
|
filesaver.readyState = filesaver.DONE;
|
176
207
|
dispatch_all();
|
177
208
|
revoke(object_url);
|
178
|
-
}
|
179
|
-
;
|
209
|
+
};
|
180
210
|
filesaver.readyState = filesaver.INIT;
|
181
211
|
|
182
212
|
if (can_use_save_link) {
|
183
213
|
object_url = get_URL().createObjectURL(blob);
|
184
|
-
setTimeout(function() {
|
214
|
+
setTimeout(function () {
|
185
215
|
save_link.href = object_url;
|
186
216
|
save_link.download = name;
|
187
217
|
click(save_link);
|
@@ -193,16 +223,15 @@ var _saveAs = (function(view) {
|
|
193
223
|
}
|
194
224
|
|
195
225
|
fs_error();
|
196
|
-
}
|
197
|
-
|
198
|
-
|
199
|
-
return new FileSaver(blob, name || blob.name ||
|
200
|
-
}
|
201
|
-
;
|
226
|
+
},
|
227
|
+
FS_proto = FileSaver.prototype,
|
228
|
+
saveAs = function (blob, name, no_auto_bom) {
|
229
|
+
return new FileSaver(blob, name || blob.name || 'download', no_auto_bom);
|
230
|
+
};
|
202
231
|
// IE 10+ (native saveAs)
|
203
|
-
if (typeof navigator !==
|
204
|
-
return function(blob, name, no_auto_bom) {
|
205
|
-
name = name || blob.name ||
|
232
|
+
if (typeof navigator !== 'undefined' && navigator.msSaveOrOpenBlob) {
|
233
|
+
return function (blob, name, no_auto_bom) {
|
234
|
+
name = name || blob.name || 'download';
|
206
235
|
|
207
236
|
if (!no_auto_bom) {
|
208
237
|
blob = auto_bom(blob);
|
@@ -211,33 +240,31 @@ var _saveAs = (function(view) {
|
|
211
240
|
};
|
212
241
|
}
|
213
242
|
|
214
|
-
FS_proto.abort = function(){};
|
243
|
+
FS_proto.abort = function () {};
|
215
244
|
FS_proto.readyState = FS_proto.INIT = 0;
|
216
245
|
FS_proto.WRITING = 1;
|
217
246
|
FS_proto.DONE = 2;
|
218
247
|
|
219
248
|
FS_proto.error =
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
249
|
+
FS_proto.onwritestart =
|
250
|
+
FS_proto.onprogress =
|
251
|
+
FS_proto.onwrite =
|
252
|
+
FS_proto.onabort =
|
253
|
+
FS_proto.onerror =
|
254
|
+
FS_proto.onwriteend =
|
255
|
+
null;
|
227
256
|
|
228
257
|
return saveAs;
|
229
|
-
}(
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
)
|
234
|
-
|
258
|
+
})(
|
259
|
+
(typeof self !== 'undefined' && self) ||
|
260
|
+
(typeof window !== 'undefined' && window) ||
|
261
|
+
this.content
|
262
|
+
);
|
235
263
|
|
236
264
|
// Expose file saver on the DataTables API. Can't attach to `DataTables.Buttons`
|
237
265
|
// since this file can be loaded before Button's core!
|
238
266
|
DataTable.fileSave = _saveAs;
|
239
267
|
|
240
|
-
|
241
268
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
242
269
|
* Local (private) functions
|
243
270
|
*/
|
@@ -247,11 +274,10 @@ DataTable.fileSave = _saveAs;
|
|
247
274
|
*
|
248
275
|
* @param {object} config Button configuration
|
249
276
|
*/
|
250
|
-
var _sheetname = function (
|
251
|
-
{
|
277
|
+
var _sheetname = function (config) {
|
252
278
|
var sheetName = 'Sheet1';
|
253
279
|
|
254
|
-
if (
|
280
|
+
if (config.sheetName) {
|
255
281
|
sheetName = config.sheetName.replace(/[\[\]\*\/\\\?\:]/g, '');
|
256
282
|
}
|
257
283
|
|
@@ -264,13 +290,8 @@ var _sheetname = function ( config )
|
|
264
290
|
* @param {object} config Button configuration
|
265
291
|
* @return {string} Newline character
|
266
292
|
*/
|
267
|
-
var _newLine = function (
|
268
|
-
|
269
|
-
return config.newline ?
|
270
|
-
config.newline :
|
271
|
-
navigator.userAgent.match(/Windows/) ?
|
272
|
-
'\r\n' :
|
273
|
-
'\n';
|
293
|
+
var _newLine = function (config) {
|
294
|
+
return config.newline ? config.newline : navigator.userAgent.match(/Windows/) ? '\r\n' : '\n';
|
274
295
|
};
|
275
296
|
|
276
297
|
/**
|
@@ -281,44 +302,41 @@ var _newLine = function ( config )
|
|
281
302
|
* @param {object} config Button configuration
|
282
303
|
* @return {object} The data to export
|
283
304
|
*/
|
284
|
-
var _exportData = function (
|
285
|
-
|
286
|
-
var
|
287
|
-
var data = dt.buttons.exportData( config.exportOptions );
|
305
|
+
var _exportData = function (dt, config) {
|
306
|
+
var newLine = _newLine(config);
|
307
|
+
var data = dt.buttons.exportData(config.exportOptions);
|
288
308
|
var boundary = config.fieldBoundary;
|
289
309
|
var separator = config.fieldSeparator;
|
290
|
-
var reBoundary = new RegExp(
|
291
|
-
var escapeChar = config.escapeChar !== undefined ?
|
292
|
-
|
293
|
-
'\\';
|
294
|
-
var join = function ( a ) {
|
310
|
+
var reBoundary = new RegExp(boundary, 'g');
|
311
|
+
var escapeChar = config.escapeChar !== undefined ? config.escapeChar : '\\';
|
312
|
+
var join = function (a) {
|
295
313
|
var s = '';
|
296
314
|
|
297
315
|
// If there is a field boundary, then we might need to escape it in
|
298
316
|
// the source data
|
299
|
-
for (
|
300
|
-
if (
|
317
|
+
for (var i = 0, ien = a.length; i < ien; i++) {
|
318
|
+
if (i > 0) {
|
301
319
|
s += separator;
|
302
320
|
}
|
303
321
|
|
304
|
-
s += boundary
|
305
|
-
boundary + ('' + a[i]).replace(
|
306
|
-
a[i];
|
322
|
+
s += boundary
|
323
|
+
? boundary + ('' + a[i]).replace(reBoundary, escapeChar + boundary) + boundary
|
324
|
+
: a[i];
|
307
325
|
}
|
308
326
|
|
309
327
|
return s;
|
310
328
|
};
|
311
329
|
|
312
|
-
var header = config.header ? join(
|
313
|
-
var footer = config.footer && data.footer ? newLine+join(
|
330
|
+
var header = config.header ? join(data.header) + newLine : '';
|
331
|
+
var footer = config.footer && data.footer ? newLine + join(data.footer) : '';
|
314
332
|
var body = [];
|
315
333
|
|
316
|
-
for (
|
317
|
-
body.push(
|
334
|
+
for (var i = 0, ien = data.body.length; i < ien; i++) {
|
335
|
+
body.push(join(data.body[i]));
|
318
336
|
}
|
319
337
|
|
320
338
|
return {
|
321
|
-
str: header + body.join(
|
339
|
+
str: header + body.join(newLine) + footer,
|
322
340
|
rows: body.length
|
323
341
|
};
|
324
342
|
};
|
@@ -329,18 +347,18 @@ var _exportData = function ( dt, config )
|
|
329
347
|
*
|
330
348
|
* @return {Boolean} `true` if old Safari
|
331
349
|
*/
|
332
|
-
var _isDuffSafari = function ()
|
333
|
-
|
334
|
-
|
350
|
+
var _isDuffSafari = function () {
|
351
|
+
var safari =
|
352
|
+
navigator.userAgent.indexOf('Safari') !== -1 &&
|
335
353
|
navigator.userAgent.indexOf('Chrome') === -1 &&
|
336
354
|
navigator.userAgent.indexOf('Opera') === -1;
|
337
355
|
|
338
|
-
if (
|
356
|
+
if (!safari) {
|
339
357
|
return false;
|
340
358
|
}
|
341
359
|
|
342
|
-
var version = navigator.userAgent.match(
|
343
|
-
if (
|
360
|
+
var version = navigator.userAgent.match(/AppleWebKit\/(\d+\.\d+)/);
|
361
|
+
if (version && version.length > 1 && version[1] * 1 < 603.1) {
|
344
362
|
return true;
|
345
363
|
}
|
346
364
|
|
@@ -352,14 +370,14 @@ var _isDuffSafari = function ()
|
|
352
370
|
* @param {int} n Column number
|
353
371
|
* @return {string} Column letter(s) name
|
354
372
|
*/
|
355
|
-
function createCellPos(
|
373
|
+
function createCellPos(n) {
|
356
374
|
var ordA = 'A'.charCodeAt(0);
|
357
375
|
var ordZ = 'Z'.charCodeAt(0);
|
358
376
|
var len = ordZ - ordA + 1;
|
359
|
-
var s =
|
377
|
+
var s = '';
|
360
378
|
|
361
|
-
while(
|
362
|
-
s = String.fromCharCode(n % len + ordA) + s;
|
379
|
+
while (n >= 0) {
|
380
|
+
s = String.fromCharCode((n % len) + ordA) + s;
|
363
381
|
n = Math.floor(n / len) - 1;
|
364
382
|
}
|
365
383
|
|
@@ -369,8 +387,7 @@ function createCellPos( n ){
|
|
369
387
|
try {
|
370
388
|
var _serialiser = new XMLSerializer();
|
371
389
|
var _ieExcel;
|
372
|
-
}
|
373
|
-
catch (t) {}
|
390
|
+
} catch (t) {}
|
374
391
|
|
375
392
|
/**
|
376
393
|
* Recursively add XML files from an object's structure to a ZIP file. This
|
@@ -380,24 +397,28 @@ catch (t) {}
|
|
380
397
|
* @param {JSZip} zip ZIP package
|
381
398
|
* @param {object} obj Object to add (recursive)
|
382
399
|
*/
|
383
|
-
function _addToZip(
|
384
|
-
if (
|
400
|
+
function _addToZip(zip, obj) {
|
401
|
+
if (_ieExcel === undefined) {
|
385
402
|
// Detect if we are dealing with IE's _awful_ serialiser by seeing if it
|
386
403
|
// drop attributes
|
387
|
-
_ieExcel =
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
404
|
+
_ieExcel =
|
405
|
+
_serialiser
|
406
|
+
.serializeToString(
|
407
|
+
new window.DOMParser().parseFromString(
|
408
|
+
excelStrings['xl/worksheets/sheet1.xml'],
|
409
|
+
'text/xml'
|
410
|
+
)
|
411
|
+
)
|
412
|
+
.indexOf('xmlns:r') === -1;
|
392
413
|
}
|
393
414
|
|
394
|
-
$.each(
|
395
|
-
if (
|
396
|
-
var newDir = zip.folder(
|
397
|
-
_addToZip(
|
415
|
+
$.each(obj, function (name, val) {
|
416
|
+
if ($.isPlainObject(val)) {
|
417
|
+
var newDir = zip.folder(name);
|
418
|
+
_addToZip(newDir, val);
|
398
419
|
}
|
399
420
|
else {
|
400
|
-
if (
|
421
|
+
if (_ieExcel) {
|
401
422
|
// IE's XML serialiser will drop some name space attributes from
|
402
423
|
// from the root node, so we need to save them. Do this by
|
403
424
|
// replacing the namespace nodes with a regular attribute that
|
@@ -407,47 +428,49 @@ function _addToZip( zip, obj ) {
|
|
407
428
|
var i, ien;
|
408
429
|
var attrs = [];
|
409
430
|
|
410
|
-
for (
|
431
|
+
for (i = worksheet.attributes.length - 1; i >= 0; i--) {
|
411
432
|
var attrName = worksheet.attributes[i].nodeName;
|
412
433
|
var attrValue = worksheet.attributes[i].nodeValue;
|
413
434
|
|
414
|
-
if (
|
415
|
-
attrs.push(
|
435
|
+
if (attrName.indexOf(':') !== -1) {
|
436
|
+
attrs.push({ name: attrName, value: attrValue });
|
416
437
|
|
417
|
-
worksheet.removeAttribute(
|
438
|
+
worksheet.removeAttribute(attrName);
|
418
439
|
}
|
419
440
|
}
|
420
441
|
|
421
|
-
for (
|
422
|
-
var attr = val.createAttribute(
|
442
|
+
for (i = 0, ien = attrs.length; i < ien; i++) {
|
443
|
+
var attr = val.createAttribute(
|
444
|
+
attrs[i].name.replace(':', '_dt_b_namespace_token_')
|
445
|
+
);
|
423
446
|
attr.value = attrs[i].value;
|
424
|
-
worksheet.setAttributeNode(
|
447
|
+
worksheet.setAttributeNode(attr);
|
425
448
|
}
|
426
449
|
}
|
427
450
|
|
428
451
|
var str = _serialiser.serializeToString(val);
|
429
452
|
|
430
453
|
// Fix IE's XML
|
431
|
-
if (
|
454
|
+
if (_ieExcel) {
|
432
455
|
// IE doesn't include the XML declaration
|
433
|
-
if (
|
434
|
-
str = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+str;
|
456
|
+
if (str.indexOf('<?xml') === -1) {
|
457
|
+
str = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + str;
|
435
458
|
}
|
436
459
|
|
437
460
|
// Return namespace attributes to being as such
|
438
|
-
str = str.replace(
|
461
|
+
str = str.replace(/_dt_b_namespace_token_/g, ':');
|
439
462
|
|
440
463
|
// Remove testing name space that IE puts into the space preserve attr
|
441
|
-
str = str.replace(
|
464
|
+
str = str.replace(/xmlns:NS[\d]+="" NS[\d]+:/g, '');
|
442
465
|
}
|
443
466
|
|
444
467
|
// Safari, IE and Edge will put empty name space attributes onto
|
445
468
|
// various elements making them useless. This strips them out
|
446
|
-
str = str.replace(
|
469
|
+
str = str.replace(/<([^<>]*?) xmlns=""([^<>]*?)>/g, '<$1 $2>');
|
447
470
|
|
448
|
-
zip.file(
|
471
|
+
zip.file(name, str);
|
449
472
|
}
|
450
|
-
}
|
473
|
+
});
|
451
474
|
}
|
452
475
|
|
453
476
|
/**
|
@@ -460,22 +483,22 @@ function _addToZip( zip, obj ) {
|
|
460
483
|
* (child nodes) and `text` (text content)
|
461
484
|
* @return {node} Created node
|
462
485
|
*/
|
463
|
-
function _createNode(
|
464
|
-
var tempNode = doc.createElement(
|
486
|
+
function _createNode(doc, nodeName, opts) {
|
487
|
+
var tempNode = doc.createElement(nodeName);
|
465
488
|
|
466
|
-
if (
|
467
|
-
if (
|
468
|
-
$(tempNode).attr(
|
489
|
+
if (opts) {
|
490
|
+
if (opts.attr) {
|
491
|
+
$(tempNode).attr(opts.attr);
|
469
492
|
}
|
470
493
|
|
471
|
-
if (
|
472
|
-
$.each(
|
473
|
-
tempNode.appendChild(
|
474
|
-
}
|
494
|
+
if (opts.children) {
|
495
|
+
$.each(opts.children, function (key, value) {
|
496
|
+
tempNode.appendChild(value);
|
497
|
+
});
|
475
498
|
}
|
476
499
|
|
477
|
-
if (
|
478
|
-
tempNode.appendChild(
|
500
|
+
if (opts.text !== null && opts.text !== undefined) {
|
501
|
+
tempNode.appendChild(doc.createTextNode(opts.text));
|
479
502
|
}
|
480
503
|
}
|
481
504
|
|
@@ -488,27 +511,25 @@ function _createNode( doc, nodeName, opts ) {
|
|
488
511
|
* @param {int} col Column index
|
489
512
|
* @return {int} Column width
|
490
513
|
*/
|
491
|
-
function _excelColWidth(
|
514
|
+
function _excelColWidth(data, col) {
|
492
515
|
var max = data.header[col].length;
|
493
516
|
var len, lineSplit, str;
|
494
517
|
|
495
|
-
if (
|
518
|
+
if (data.footer && data.footer[col].length > max) {
|
496
519
|
max = data.footer[col].length;
|
497
520
|
}
|
498
521
|
|
499
|
-
for (
|
522
|
+
for (var i = 0, ien = data.body.length; i < ien; i++) {
|
500
523
|
var point = data.body[i][col];
|
501
|
-
str = point !== null && point !== undefined ?
|
502
|
-
point.toString() :
|
503
|
-
'';
|
524
|
+
str = point !== null && point !== undefined ? point.toString() : '';
|
504
525
|
|
505
526
|
// If there is a newline character, workout the width of the column
|
506
527
|
// based on the longest line in the string
|
507
|
-
if (
|
528
|
+
if (str.indexOf('\n') !== -1) {
|
508
529
|
lineSplit = str.split('\n');
|
509
|
-
lineSplit.sort(
|
530
|
+
lineSplit.sort(function (a, b) {
|
510
531
|
return b.length - a.length;
|
511
|
-
}
|
532
|
+
});
|
512
533
|
|
513
534
|
len = lineSplit[0].length;
|
514
535
|
}
|
@@ -516,12 +537,12 @@ function _excelColWidth( data, col ) {
|
|
516
537
|
len = str.length;
|
517
538
|
}
|
518
539
|
|
519
|
-
if (
|
540
|
+
if (len > max) {
|
520
541
|
max = len;
|
521
542
|
}
|
522
543
|
|
523
544
|
// Max width rather than having potentially massive column widths
|
524
|
-
if (
|
545
|
+
if (max > 40) {
|
525
546
|
return 54; // 40 * 1.35
|
526
547
|
}
|
527
548
|
}
|
@@ -534,233 +555,234 @@ function _excelColWidth( data, col ) {
|
|
534
555
|
|
535
556
|
// Excel - Pre-defined strings to build a basic XLSX file
|
536
557
|
var excelStrings = {
|
537
|
-
|
538
|
-
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+
|
539
|
-
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'+
|
540
|
-
|
558
|
+
'_rels/.rels':
|
559
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
|
560
|
+
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
|
561
|
+
'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>' +
|
541
562
|
'</Relationships>',
|
542
563
|
|
543
|
-
|
544
|
-
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+
|
545
|
-
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'+
|
546
|
-
|
547
|
-
|
564
|
+
'xl/_rels/workbook.xml.rels':
|
565
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
|
566
|
+
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
|
567
|
+
'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>' +
|
568
|
+
'<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>' +
|
548
569
|
'</Relationships>',
|
549
570
|
|
550
|
-
|
551
|
-
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+
|
552
|
-
'<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">'+
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
571
|
+
'[Content_Types].xml':
|
572
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
|
573
|
+
'<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">' +
|
574
|
+
'<Default Extension="xml" ContentType="application/xml" />' +
|
575
|
+
'<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />' +
|
576
|
+
'<Default Extension="jpeg" ContentType="image/jpeg" />' +
|
577
|
+
'<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml" />' +
|
578
|
+
'<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" />' +
|
579
|
+
'<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml" />' +
|
559
580
|
'</Types>',
|
560
581
|
|
561
|
-
|
562
|
-
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+
|
563
|
-
'<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">'+
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
582
|
+
'xl/workbook.xml':
|
583
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
|
584
|
+
'<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">' +
|
585
|
+
'<fileVersion appName="xl" lastEdited="5" lowestEdited="5" rupBuild="24816"/>' +
|
586
|
+
'<workbookPr showInkAnnotation="0" autoCompressPictures="0"/>' +
|
587
|
+
'<bookViews>' +
|
588
|
+
'<workbookView xWindow="0" yWindow="0" windowWidth="25600" windowHeight="19020" tabRatio="500"/>' +
|
589
|
+
'</bookViews>' +
|
590
|
+
'<sheets>' +
|
591
|
+
'<sheet name="Sheet1" sheetId="1" r:id="rId1"/>' +
|
592
|
+
'</sheets>' +
|
593
|
+
'<definedNames/>' +
|
573
594
|
'</workbook>',
|
574
595
|
|
575
|
-
|
576
|
-
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+
|
577
|
-
'<worksheet 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="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac">'+
|
578
|
-
|
579
|
-
|
596
|
+
'xl/worksheets/sheet1.xml':
|
597
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
|
598
|
+
'<worksheet 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="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac">' +
|
599
|
+
'<sheetData/>' +
|
600
|
+
'<mergeCells count="0"/>' +
|
580
601
|
'</worksheet>',
|
581
602
|
|
582
|
-
|
583
|
-
'<?xml version="1.0" encoding="UTF-8"?>'+
|
584
|
-
'<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac">'+
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
603
|
+
'xl/styles.xml':
|
604
|
+
'<?xml version="1.0" encoding="UTF-8"?>' +
|
605
|
+
'<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac">' +
|
606
|
+
'<numFmts count="6">' +
|
607
|
+
'<numFmt numFmtId="164" formatCode="#,##0.00_- [$$-45C]"/>' +
|
608
|
+
'<numFmt numFmtId="165" formatCode=""£"#,##0.00"/>' +
|
609
|
+
'<numFmt numFmtId="166" formatCode="[$€-2] #,##0.00"/>' +
|
610
|
+
'<numFmt numFmtId="167" formatCode="0.0%"/>' +
|
611
|
+
'<numFmt numFmtId="168" formatCode="#,##0;(#,##0)"/>' +
|
612
|
+
'<numFmt numFmtId="169" formatCode="#,##0.00;(#,##0.00)"/>' +
|
613
|
+
'</numFmts>' +
|
614
|
+
'<fonts count="5" x14ac:knownFonts="1">' +
|
615
|
+
'<font>' +
|
616
|
+
'<sz val="11" />' +
|
617
|
+
'<name val="Calibri" />' +
|
618
|
+
'</font>' +
|
619
|
+
'<font>' +
|
620
|
+
'<sz val="11" />' +
|
621
|
+
'<name val="Calibri" />' +
|
622
|
+
'<color rgb="FFFFFFFF" />' +
|
623
|
+
'</font>' +
|
624
|
+
'<font>' +
|
625
|
+
'<sz val="11" />' +
|
626
|
+
'<name val="Calibri" />' +
|
627
|
+
'<b />' +
|
628
|
+
'</font>' +
|
629
|
+
'<font>' +
|
630
|
+
'<sz val="11" />' +
|
631
|
+
'<name val="Calibri" />' +
|
632
|
+
'<i />' +
|
633
|
+
'</font>' +
|
634
|
+
'<font>' +
|
635
|
+
'<sz val="11" />' +
|
636
|
+
'<name val="Calibri" />' +
|
637
|
+
'<u />' +
|
638
|
+
'</font>' +
|
639
|
+
'</fonts>' +
|
640
|
+
'<fills count="6">' +
|
641
|
+
'<fill>' +
|
642
|
+
'<patternFill patternType="none" />' +
|
643
|
+
'</fill>' +
|
644
|
+
'<fill>' + // Excel appears to use this as a dotted background regardless of values but
|
645
|
+
'<patternFill patternType="none" />' + // to be valid to the schema, use a patternFill
|
646
|
+
'</fill>' +
|
647
|
+
'<fill>' +
|
648
|
+
'<patternFill patternType="solid">' +
|
649
|
+
'<fgColor rgb="FFD9D9D9" />' +
|
650
|
+
'<bgColor indexed="64" />' +
|
651
|
+
'</patternFill>' +
|
652
|
+
'</fill>' +
|
653
|
+
'<fill>' +
|
654
|
+
'<patternFill patternType="solid">' +
|
655
|
+
'<fgColor rgb="FFD99795" />' +
|
656
|
+
'<bgColor indexed="64" />' +
|
657
|
+
'</patternFill>' +
|
658
|
+
'</fill>' +
|
659
|
+
'<fill>' +
|
660
|
+
'<patternFill patternType="solid">' +
|
661
|
+
'<fgColor rgb="ffc6efce" />' +
|
662
|
+
'<bgColor indexed="64" />' +
|
663
|
+
'</patternFill>' +
|
664
|
+
'</fill>' +
|
665
|
+
'<fill>' +
|
666
|
+
'<patternFill patternType="solid">' +
|
667
|
+
'<fgColor rgb="ffc6cfef" />' +
|
668
|
+
'<bgColor indexed="64" />' +
|
669
|
+
'</patternFill>' +
|
670
|
+
'</fill>' +
|
671
|
+
'</fills>' +
|
672
|
+
'<borders count="2">' +
|
673
|
+
'<border>' +
|
674
|
+
'<left />' +
|
675
|
+
'<right />' +
|
676
|
+
'<top />' +
|
677
|
+
'<bottom />' +
|
678
|
+
'<diagonal />' +
|
679
|
+
'</border>' +
|
680
|
+
'<border diagonalUp="false" diagonalDown="false">' +
|
681
|
+
'<left style="thin">' +
|
682
|
+
'<color auto="1" />' +
|
683
|
+
'</left>' +
|
684
|
+
'<right style="thin">' +
|
685
|
+
'<color auto="1" />' +
|
686
|
+
'</right>' +
|
687
|
+
'<top style="thin">' +
|
688
|
+
'<color auto="1" />' +
|
689
|
+
'</top>' +
|
690
|
+
'<bottom style="thin">' +
|
691
|
+
'<color auto="1" />' +
|
692
|
+
'</bottom>' +
|
693
|
+
'<diagonal />' +
|
694
|
+
'</border>' +
|
695
|
+
'</borders>' +
|
696
|
+
'<cellStyleXfs count="1">' +
|
697
|
+
'<xf numFmtId="0" fontId="0" fillId="0" borderId="0" />' +
|
698
|
+
'</cellStyleXfs>' +
|
699
|
+
'<cellXfs count="68">' +
|
700
|
+
'<xf numFmtId="0" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
701
|
+
'<xf numFmtId="0" fontId="1" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
702
|
+
'<xf numFmtId="0" fontId="2" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
703
|
+
'<xf numFmtId="0" fontId="3" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
704
|
+
'<xf numFmtId="0" fontId="4" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
705
|
+
'<xf numFmtId="0" fontId="0" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
706
|
+
'<xf numFmtId="0" fontId="1" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
707
|
+
'<xf numFmtId="0" fontId="2" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
708
|
+
'<xf numFmtId="0" fontId="3" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
709
|
+
'<xf numFmtId="0" fontId="4" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
710
|
+
'<xf numFmtId="0" fontId="0" fillId="3" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
711
|
+
'<xf numFmtId="0" fontId="1" fillId="3" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
712
|
+
'<xf numFmtId="0" fontId="2" fillId="3" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
713
|
+
'<xf numFmtId="0" fontId="3" fillId="3" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
714
|
+
'<xf numFmtId="0" fontId="4" fillId="3" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
715
|
+
'<xf numFmtId="0" fontId="0" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
716
|
+
'<xf numFmtId="0" fontId="1" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
717
|
+
'<xf numFmtId="0" fontId="2" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
718
|
+
'<xf numFmtId="0" fontId="3" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
719
|
+
'<xf numFmtId="0" fontId="4" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
720
|
+
'<xf numFmtId="0" fontId="0" fillId="5" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
721
|
+
'<xf numFmtId="0" fontId="1" fillId="5" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
722
|
+
'<xf numFmtId="0" fontId="2" fillId="5" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
723
|
+
'<xf numFmtId="0" fontId="3" fillId="5" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
724
|
+
'<xf numFmtId="0" fontId="4" fillId="5" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
725
|
+
'<xf numFmtId="0" fontId="0" fillId="0" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
726
|
+
'<xf numFmtId="0" fontId="1" fillId="0" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
727
|
+
'<xf numFmtId="0" fontId="2" fillId="0" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
728
|
+
'<xf numFmtId="0" fontId="3" fillId="0" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
729
|
+
'<xf numFmtId="0" fontId="4" fillId="0" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
730
|
+
'<xf numFmtId="0" fontId="0" fillId="2" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
731
|
+
'<xf numFmtId="0" fontId="1" fillId="2" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
732
|
+
'<xf numFmtId="0" fontId="2" fillId="2" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
733
|
+
'<xf numFmtId="0" fontId="3" fillId="2" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
734
|
+
'<xf numFmtId="0" fontId="4" fillId="2" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
735
|
+
'<xf numFmtId="0" fontId="0" fillId="3" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
736
|
+
'<xf numFmtId="0" fontId="1" fillId="3" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
737
|
+
'<xf numFmtId="0" fontId="2" fillId="3" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
738
|
+
'<xf numFmtId="0" fontId="3" fillId="3" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
739
|
+
'<xf numFmtId="0" fontId="4" fillId="3" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
740
|
+
'<xf numFmtId="0" fontId="0" fillId="4" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
741
|
+
'<xf numFmtId="0" fontId="1" fillId="4" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
742
|
+
'<xf numFmtId="0" fontId="2" fillId="4" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
743
|
+
'<xf numFmtId="0" fontId="3" fillId="4" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
744
|
+
'<xf numFmtId="0" fontId="4" fillId="4" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
745
|
+
'<xf numFmtId="0" fontId="0" fillId="5" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
746
|
+
'<xf numFmtId="0" fontId="1" fillId="5" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
747
|
+
'<xf numFmtId="0" fontId="2" fillId="5" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
748
|
+
'<xf numFmtId="0" fontId="3" fillId="5" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
749
|
+
'<xf numFmtId="0" fontId="4" fillId="5" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>' +
|
750
|
+
'<xf numFmtId="0" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyAlignment="1">' +
|
751
|
+
'<alignment horizontal="left"/>' +
|
752
|
+
'</xf>' +
|
753
|
+
'<xf numFmtId="0" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyAlignment="1">' +
|
754
|
+
'<alignment horizontal="center"/>' +
|
755
|
+
'</xf>' +
|
756
|
+
'<xf numFmtId="0" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyAlignment="1">' +
|
757
|
+
'<alignment horizontal="right"/>' +
|
758
|
+
'</xf>' +
|
759
|
+
'<xf numFmtId="0" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyAlignment="1">' +
|
760
|
+
'<alignment horizontal="fill"/>' +
|
761
|
+
'</xf>' +
|
762
|
+
'<xf numFmtId="0" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyAlignment="1">' +
|
763
|
+
'<alignment textRotation="90"/>' +
|
764
|
+
'</xf>' +
|
765
|
+
'<xf numFmtId="0" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyAlignment="1">' +
|
766
|
+
'<alignment wrapText="1"/>' +
|
767
|
+
'</xf>' +
|
768
|
+
'<xf numFmtId="9" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>' +
|
769
|
+
'<xf numFmtId="164" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>' +
|
770
|
+
'<xf numFmtId="165" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>' +
|
771
|
+
'<xf numFmtId="166" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>' +
|
772
|
+
'<xf numFmtId="167" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>' +
|
773
|
+
'<xf numFmtId="168" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>' +
|
774
|
+
'<xf numFmtId="169" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>' +
|
775
|
+
'<xf numFmtId="3" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>' +
|
776
|
+
'<xf numFmtId="4" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>' +
|
777
|
+
'<xf numFmtId="1" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>' +
|
778
|
+
'<xf numFmtId="2" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>' +
|
779
|
+
'<xf numFmtId="14" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>' +
|
780
|
+
'</cellXfs>' +
|
781
|
+
'<cellStyles count="1">' +
|
782
|
+
'<cellStyle name="Normal" xfId="0" builtinId="0" />' +
|
783
|
+
'</cellStyles>' +
|
784
|
+
'<dxfs count="0" />' +
|
785
|
+
'<tableStyles count="0" defaultTableStyle="TableStyleMedium9" defaultPivotStyle="PivotStyleMedium4" />' +
|
764
786
|
'</styleSheet>'
|
765
787
|
};
|
766
788
|
// Note we could use 3 `for` loops for the styles, but when gzipped there is
|
@@ -771,21 +793,50 @@ var excelStrings = {
|
|
771
793
|
// Ref: section 3.8.30 - built in formatters in open spreadsheet
|
772
794
|
// https://www.ecma-international.org/news/TC45_current_work/Office%20Open%20XML%20Part%204%20-%20Markup%20Language%20Reference.pdf
|
773
795
|
var _excelSpecials = [
|
774
|
-
{
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
{
|
782
|
-
|
783
|
-
|
784
|
-
|
796
|
+
{
|
797
|
+
match: /^\-?\d+\.\d%$/,
|
798
|
+
style: 60,
|
799
|
+
fmt: function (d) {
|
800
|
+
return d / 100;
|
801
|
+
}
|
802
|
+
}, // Percent with d.p.
|
803
|
+
{
|
804
|
+
match: /^\-?\d+\.?\d*%$/,
|
805
|
+
style: 56,
|
806
|
+
fmt: function (d) {
|
807
|
+
return d / 100;
|
808
|
+
}
|
809
|
+
}, // Percent
|
810
|
+
{ match: /^\-?\$[\d,]+.?\d*$/, style: 57 }, // Dollars
|
811
|
+
{ match: /^\-?£[\d,]+.?\d*$/, style: 58 }, // Pounds
|
812
|
+
{ match: /^\-?€[\d,]+.?\d*$/, style: 59 }, // Euros
|
813
|
+
{ match: /^\-?\d+$/, style: 65 }, // Numbers without thousand separators
|
814
|
+
{ match: /^\-?\d+\.\d{2}$/, style: 66 }, // Numbers 2 d.p. without thousands separators
|
815
|
+
{
|
816
|
+
match: /^\([\d,]+\)$/,
|
817
|
+
style: 61,
|
818
|
+
fmt: function (d) {
|
819
|
+
return -1 * d.replace(/[\(\)]/g, '');
|
820
|
+
}
|
821
|
+
}, // Negative numbers indicated by brackets
|
822
|
+
{
|
823
|
+
match: /^\([\d,]+\.\d{2}\)$/,
|
824
|
+
style: 62,
|
825
|
+
fmt: function (d) {
|
826
|
+
return -1 * d.replace(/[\(\)]/g, '');
|
827
|
+
}
|
828
|
+
}, // Negative numbers indicated by brackets - 2d.p.
|
829
|
+
{ match: /^\-?[\d,]+$/, style: 63 }, // Numbers with thousand separators
|
830
|
+
{ match: /^\-?[\d,]+\.\d{2}$/, style: 64 },
|
831
|
+
{
|
832
|
+
match: /^[\d]{4}\-[01][\d]\-[0123][\d]$/,
|
833
|
+
style: 67,
|
834
|
+
fmt: function (d) {
|
835
|
+
return Math.round(25569 + Date.parse(d) / (86400 * 1000));
|
836
|
+
}
|
837
|
+
} //Date yyyy-mm-dd
|
785
838
|
];
|
786
839
|
|
787
|
-
|
788
|
-
|
789
840
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
790
841
|
* Buttons
|
791
842
|
*/
|
@@ -796,83 +847,87 @@ var _excelSpecials = [
|
|
796
847
|
DataTable.ext.buttons.copyHtml5 = {
|
797
848
|
className: 'buttons-copy buttons-html5',
|
798
849
|
|
799
|
-
text: function (
|
800
|
-
return dt.i18n(
|
850
|
+
text: function (dt) {
|
851
|
+
return dt.i18n('buttons.copy', 'Copy');
|
801
852
|
},
|
802
853
|
|
803
|
-
action: function (
|
804
|
-
this.processing(
|
854
|
+
action: function (e, dt, button, config) {
|
855
|
+
this.processing(true);
|
805
856
|
|
806
857
|
var that = this;
|
807
|
-
var exportData = _exportData(
|
808
|
-
var info = dt.buttons.exportInfo(
|
858
|
+
var exportData = _exportData(dt, config);
|
859
|
+
var info = dt.buttons.exportInfo(config);
|
809
860
|
var newline = _newLine(config);
|
810
861
|
var output = exportData.str;
|
811
|
-
var hiddenDiv = $('<div/>')
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
if ( info.title ) {
|
862
|
+
var hiddenDiv = $('<div/>').css({
|
863
|
+
height: 1,
|
864
|
+
width: 1,
|
865
|
+
overflow: 'hidden',
|
866
|
+
position: 'fixed',
|
867
|
+
top: 0,
|
868
|
+
left: 0
|
869
|
+
});
|
870
|
+
|
871
|
+
if (info.title) {
|
822
872
|
output = info.title + newline + newline + output;
|
823
873
|
}
|
824
874
|
|
825
|
-
if (
|
875
|
+
if (info.messageTop) {
|
826
876
|
output = info.messageTop + newline + newline + output;
|
827
877
|
}
|
828
878
|
|
829
|
-
if (
|
879
|
+
if (info.messageBottom) {
|
830
880
|
output = output + newline + newline + info.messageBottom;
|
831
881
|
}
|
832
882
|
|
833
|
-
if (
|
834
|
-
output = config.customize(
|
883
|
+
if (config.customize) {
|
884
|
+
output = config.customize(output, config, dt);
|
835
885
|
}
|
836
886
|
|
837
|
-
var textarea = $('<textarea readonly/>')
|
838
|
-
.val( output )
|
839
|
-
.appendTo( hiddenDiv );
|
887
|
+
var textarea = $('<textarea readonly/>').val(output).appendTo(hiddenDiv);
|
840
888
|
|
841
889
|
// For browsers that support the copy execCommand, try to use it
|
842
|
-
if (
|
843
|
-
hiddenDiv.appendTo(
|
890
|
+
if (document.queryCommandSupported('copy')) {
|
891
|
+
hiddenDiv.appendTo(dt.table().container());
|
844
892
|
textarea[0].focus();
|
845
893
|
textarea[0].select();
|
846
894
|
|
847
895
|
try {
|
848
|
-
var successful = document.execCommand(
|
896
|
+
var successful = document.execCommand('copy');
|
849
897
|
hiddenDiv.remove();
|
850
898
|
|
851
899
|
if (successful) {
|
852
900
|
dt.buttons.info(
|
853
|
-
dt.i18n(
|
854
|
-
dt.i18n(
|
855
|
-
|
856
|
-
|
857
|
-
|
901
|
+
dt.i18n('buttons.copyTitle', 'Copy to clipboard'),
|
902
|
+
dt.i18n(
|
903
|
+
'buttons.copySuccess',
|
904
|
+
{
|
905
|
+
1: 'Copied one row to clipboard',
|
906
|
+
_: 'Copied %d rows to clipboard'
|
907
|
+
},
|
908
|
+
exportData.rows
|
909
|
+
),
|
858
910
|
2000
|
859
911
|
);
|
860
912
|
|
861
|
-
this.processing(
|
913
|
+
this.processing(false);
|
862
914
|
return;
|
863
915
|
}
|
864
|
-
}
|
865
|
-
catch (t) {}
|
916
|
+
} catch (t) {}
|
866
917
|
}
|
867
918
|
|
868
919
|
// Otherwise we show the text box and instruct the user to use it
|
869
|
-
var message = $(
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
920
|
+
var message = $(
|
921
|
+
'<span>' +
|
922
|
+
dt.i18n(
|
923
|
+
'buttons.copyKeys',
|
924
|
+
'Press <i>ctrl</i> or <i>\u2318</i> + <i>C</i> to copy the table data<br>to your system clipboard.<br><br>' +
|
925
|
+
'To cancel, click this message or press escape.'
|
926
|
+
) +
|
927
|
+
'</span>'
|
928
|
+
).append(hiddenDiv);
|
929
|
+
|
930
|
+
dt.buttons.info(dt.i18n('buttons.copyTitle', 'Copy to clipboard'), message, 0);
|
876
931
|
|
877
932
|
// Select the text so when the user activates their system clipboard
|
878
933
|
// it will copy that text
|
@@ -882,23 +937,24 @@ DataTable.ext.buttons.copyHtml5 = {
|
|
882
937
|
// Event to hide the message when the user is done
|
883
938
|
var container = $(message).closest('.dt-button-info');
|
884
939
|
var close = function () {
|
885
|
-
container.off(
|
886
|
-
$(document).off(
|
887
|
-
dt.buttons.info(
|
940
|
+
container.off('click.buttons-copy');
|
941
|
+
$(document).off('.buttons-copy');
|
942
|
+
dt.buttons.info(false);
|
888
943
|
};
|
889
944
|
|
890
|
-
container.on(
|
945
|
+
container.on('click.buttons-copy', close);
|
891
946
|
$(document)
|
892
|
-
.on(
|
893
|
-
if (
|
947
|
+
.on('keydown.buttons-copy', function (e) {
|
948
|
+
if (e.keyCode === 27) {
|
949
|
+
// esc
|
894
950
|
close();
|
895
|
-
that.processing(
|
951
|
+
that.processing(false);
|
896
952
|
}
|
897
|
-
}
|
898
|
-
.on(
|
953
|
+
})
|
954
|
+
.on('copy.buttons-copy cut.buttons-copy', function () {
|
899
955
|
close();
|
900
|
-
that.processing(
|
901
|
-
}
|
956
|
+
that.processing(false);
|
957
|
+
});
|
902
958
|
},
|
903
959
|
|
904
960
|
exportOptions: {},
|
@@ -930,46 +986,42 @@ DataTable.ext.buttons.csvHtml5 = {
|
|
930
986
|
return window.FileReader !== undefined && window.Blob;
|
931
987
|
},
|
932
988
|
|
933
|
-
text: function (
|
934
|
-
return dt.i18n(
|
989
|
+
text: function (dt) {
|
990
|
+
return dt.i18n('buttons.csv', 'CSV');
|
935
991
|
},
|
936
992
|
|
937
|
-
action: function (
|
938
|
-
this.processing(
|
993
|
+
action: function (e, dt, button, config) {
|
994
|
+
this.processing(true);
|
939
995
|
|
940
996
|
// Set the text
|
941
|
-
var output = _exportData(
|
997
|
+
var output = _exportData(dt, config).str;
|
942
998
|
var info = dt.buttons.exportInfo(config);
|
943
999
|
var charset = config.charset;
|
944
1000
|
|
945
|
-
if (
|
946
|
-
output = config.customize(
|
1001
|
+
if (config.customize) {
|
1002
|
+
output = config.customize(output, config, dt);
|
947
1003
|
}
|
948
1004
|
|
949
|
-
if (
|
950
|
-
if (
|
1005
|
+
if (charset !== false) {
|
1006
|
+
if (!charset) {
|
951
1007
|
charset = document.characterSet || document.charset;
|
952
1008
|
}
|
953
1009
|
|
954
|
-
if (
|
955
|
-
charset = ';charset='+charset;
|
1010
|
+
if (charset) {
|
1011
|
+
charset = ';charset=' + charset;
|
956
1012
|
}
|
957
1013
|
}
|
958
1014
|
else {
|
959
1015
|
charset = '';
|
960
1016
|
}
|
961
1017
|
|
962
|
-
if (
|
963
|
-
output =
|
1018
|
+
if (config.bom) {
|
1019
|
+
output = String.fromCharCode(0xfeff) + output;
|
964
1020
|
}
|
965
1021
|
|
966
|
-
_saveAs(
|
967
|
-
new Blob( [output], {type: 'text/csv'+charset} ),
|
968
|
-
info.filename,
|
969
|
-
true
|
970
|
-
);
|
1022
|
+
_saveAs(new Blob([output], { type: 'text/csv' + charset }), info.filename, true);
|
971
1023
|
|
972
|
-
this.processing(
|
1024
|
+
this.processing(false);
|
973
1025
|
},
|
974
1026
|
|
975
1027
|
filename: '*',
|
@@ -998,61 +1050,65 @@ DataTable.ext.buttons.excelHtml5 = {
|
|
998
1050
|
className: 'buttons-excel buttons-html5',
|
999
1051
|
|
1000
1052
|
available: function () {
|
1001
|
-
return
|
1053
|
+
return (
|
1054
|
+
window.FileReader !== undefined &&
|
1055
|
+
_jsZip() !== undefined &&
|
1056
|
+
!_isDuffSafari() &&
|
1057
|
+
_serialiser
|
1058
|
+
);
|
1002
1059
|
},
|
1003
1060
|
|
1004
|
-
text: function (
|
1005
|
-
return dt.i18n(
|
1061
|
+
text: function (dt) {
|
1062
|
+
return dt.i18n('buttons.excel', 'Excel');
|
1006
1063
|
},
|
1007
1064
|
|
1008
|
-
action: function (
|
1009
|
-
this.processing(
|
1065
|
+
action: function (e, dt, button, config) {
|
1066
|
+
this.processing(true);
|
1010
1067
|
|
1011
1068
|
var that = this;
|
1012
1069
|
var rowPos = 0;
|
1013
1070
|
var dataStartRow, dataEndRow;
|
1014
|
-
var getXml = function (
|
1015
|
-
var str = excelStrings[
|
1071
|
+
var getXml = function (type) {
|
1072
|
+
var str = excelStrings[type];
|
1016
1073
|
|
1017
1074
|
//str = str.replace( /xmlns:/g, 'xmlns_' ).replace( /mc:/g, 'mc_' );
|
1018
1075
|
|
1019
|
-
return $.parseXML(
|
1076
|
+
return $.parseXML(str);
|
1020
1077
|
};
|
1021
1078
|
var rels = getXml('xl/worksheets/sheet1.xml');
|
1022
|
-
var relsGet = rels.getElementsByTagName(
|
1079
|
+
var relsGet = rels.getElementsByTagName('sheetData')[0];
|
1023
1080
|
|
1024
1081
|
var xlsx = {
|
1025
1082
|
_rels: {
|
1026
|
-
|
1083
|
+
'.rels': getXml('_rels/.rels')
|
1027
1084
|
},
|
1028
1085
|
xl: {
|
1029
1086
|
_rels: {
|
1030
|
-
|
1087
|
+
'workbook.xml.rels': getXml('xl/_rels/workbook.xml.rels')
|
1031
1088
|
},
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1089
|
+
'workbook.xml': getXml('xl/workbook.xml'),
|
1090
|
+
'styles.xml': getXml('xl/styles.xml'),
|
1091
|
+
worksheets: {
|
1092
|
+
'sheet1.xml': rels
|
1036
1093
|
}
|
1037
|
-
|
1038
1094
|
},
|
1039
|
-
|
1095
|
+
'[Content_Types].xml': getXml('[Content_Types].xml')
|
1040
1096
|
};
|
1041
1097
|
|
1042
|
-
var data = dt.buttons.exportData(
|
1098
|
+
var data = dt.buttons.exportData(config.exportOptions);
|
1043
1099
|
var currentRow, rowNode;
|
1044
|
-
var addRow = function (
|
1045
|
-
currentRow = rowPos+1;
|
1046
|
-
rowNode = _createNode(
|
1100
|
+
var addRow = function (row) {
|
1101
|
+
currentRow = rowPos + 1;
|
1102
|
+
rowNode = _createNode(rels, 'row', { attr: { r: currentRow } });
|
1047
1103
|
|
1048
|
-
for (
|
1104
|
+
for (var i = 0, ien = row.length; i < ien; i++) {
|
1049
1105
|
// Concat both the Cell Columns as a letter and the Row of the cell.
|
1050
1106
|
var cellId = createCellPos(i) + '' + currentRow;
|
1051
1107
|
var cell = null;
|
1052
1108
|
|
1053
1109
|
// For null, undefined of blank cell, continue so it doesn't create the _createNode
|
1054
|
-
if (
|
1055
|
-
if (
|
1110
|
+
if (row[i] === null || row[i] === undefined || row[i] === '') {
|
1111
|
+
if (config.createEmptyCells === true) {
|
1056
1112
|
row[i] = '';
|
1057
1113
|
}
|
1058
1114
|
else {
|
@@ -1061,215 +1117,235 @@ DataTable.ext.buttons.excelHtml5 = {
|
|
1061
1117
|
}
|
1062
1118
|
|
1063
1119
|
var originalContent = row[i];
|
1064
|
-
row[i] =
|
1120
|
+
row[i] = typeof row[i].trim === 'function' ? row[i].trim() : row[i];
|
1065
1121
|
|
1066
1122
|
// Special number formatting options
|
1067
|
-
for (
|
1123
|
+
for (var j = 0, jen = _excelSpecials.length; j < jen; j++) {
|
1068
1124
|
var special = _excelSpecials[j];
|
1069
1125
|
|
1070
1126
|
// TODO Need to provide the ability for the specials to say
|
1071
1127
|
// if they are returning a string, since at the moment it is
|
1072
1128
|
// assumed to be a number
|
1073
|
-
if (
|
1129
|
+
if (row[i].match && !row[i].match(/^0\d+/) && row[i].match(special.match)) {
|
1074
1130
|
var val = row[i].replace(/[^\d\.\-]/g, '');
|
1075
1131
|
|
1076
|
-
if (
|
1077
|
-
val = special.fmt(
|
1132
|
+
if (special.fmt) {
|
1133
|
+
val = special.fmt(val);
|
1078
1134
|
}
|
1079
1135
|
|
1080
|
-
cell = _createNode(
|
1136
|
+
cell = _createNode(rels, 'c', {
|
1081
1137
|
attr: {
|
1082
1138
|
r: cellId,
|
1083
1139
|
s: special.style
|
1084
1140
|
},
|
1085
|
-
children: [
|
1086
|
-
|
1087
|
-
]
|
1088
|
-
} );
|
1141
|
+
children: [_createNode(rels, 'v', { text: val })]
|
1142
|
+
});
|
1089
1143
|
|
1090
1144
|
break;
|
1091
1145
|
}
|
1092
1146
|
}
|
1093
1147
|
|
1094
|
-
if (
|
1095
|
-
if (
|
1096
|
-
row[i]
|
1097
|
-
row[i].match
|
1098
|
-
|
1148
|
+
if (!cell) {
|
1149
|
+
if (
|
1150
|
+
typeof row[i] === 'number' ||
|
1151
|
+
(row[i].match &&
|
1152
|
+
row[i].match(/^-?\d+(\.\d+)?([eE]\-?\d+)?$/) && // Includes exponential format
|
1153
|
+
!row[i].match(/^0\d+/))
|
1099
1154
|
) {
|
1100
1155
|
// Detect numbers - don't match numbers with leading zeros
|
1101
1156
|
// or a negative anywhere but the start
|
1102
|
-
cell = _createNode(
|
1157
|
+
cell = _createNode(rels, 'c', {
|
1103
1158
|
attr: {
|
1104
1159
|
t: 'n',
|
1105
1160
|
r: cellId
|
1106
1161
|
},
|
1107
|
-
children: [
|
1108
|
-
|
1109
|
-
]
|
1110
|
-
} );
|
1162
|
+
children: [_createNode(rels, 'v', { text: row[i] })]
|
1163
|
+
});
|
1111
1164
|
}
|
1112
1165
|
else {
|
1113
1166
|
// String output - replace non standard characters for text output
|
1114
|
-
var text = !
|
1115
|
-
originalContent
|
1116
|
-
originalContent.replace(/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F-\x9F]/g, '');
|
1167
|
+
var text = !originalContent.replace
|
1168
|
+
? originalContent
|
1169
|
+
: originalContent.replace(/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F-\x9F]/g, '');
|
1117
1170
|
|
1118
|
-
cell = _createNode(
|
1171
|
+
cell = _createNode(rels, 'c', {
|
1119
1172
|
attr: {
|
1120
1173
|
t: 'inlineStr',
|
1121
1174
|
r: cellId
|
1122
1175
|
},
|
1123
|
-
children:{
|
1124
|
-
row: _createNode(
|
1176
|
+
children: {
|
1177
|
+
row: _createNode(rels, 'is', {
|
1125
1178
|
children: {
|
1126
|
-
row: _createNode(
|
1179
|
+
row: _createNode(rels, 't', {
|
1127
1180
|
text: text,
|
1128
1181
|
attr: {
|
1129
1182
|
'xml:space': 'preserve'
|
1130
1183
|
}
|
1131
|
-
}
|
1184
|
+
})
|
1132
1185
|
}
|
1133
|
-
}
|
1186
|
+
})
|
1134
1187
|
}
|
1135
|
-
}
|
1188
|
+
});
|
1136
1189
|
}
|
1137
1190
|
}
|
1138
1191
|
|
1139
|
-
rowNode.appendChild(
|
1192
|
+
rowNode.appendChild(cell);
|
1140
1193
|
}
|
1141
1194
|
|
1142
1195
|
relsGet.appendChild(rowNode);
|
1143
1196
|
rowPos++;
|
1144
1197
|
};
|
1145
1198
|
|
1146
|
-
if (
|
1147
|
-
config.customizeData(
|
1199
|
+
if (config.customizeData) {
|
1200
|
+
config.customizeData(data);
|
1148
1201
|
}
|
1149
1202
|
|
1150
|
-
var mergeCells = function (
|
1203
|
+
var mergeCells = function (row, colspan) {
|
1151
1204
|
var mergeCells = $('mergeCells', rels);
|
1152
1205
|
|
1153
|
-
mergeCells[0].appendChild(
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1206
|
+
mergeCells[0].appendChild(
|
1207
|
+
_createNode(rels, 'mergeCell', {
|
1208
|
+
attr: {
|
1209
|
+
ref: 'A' + row + ':' + createCellPos(colspan) + row
|
1210
|
+
}
|
1211
|
+
})
|
1212
|
+
);
|
1213
|
+
mergeCells.attr('count', parseFloat(mergeCells.attr('count')) + 1);
|
1214
|
+
$('row:eq(' + (row - 1) + ') c', rels).attr('s', '51'); // centre
|
1160
1215
|
};
|
1161
1216
|
|
1162
1217
|
// Title and top messages
|
1163
|
-
var exportInfo = dt.buttons.exportInfo(
|
1164
|
-
if (
|
1165
|
-
addRow(
|
1166
|
-
mergeCells(
|
1218
|
+
var exportInfo = dt.buttons.exportInfo(config);
|
1219
|
+
if (exportInfo.title) {
|
1220
|
+
addRow([exportInfo.title], rowPos);
|
1221
|
+
mergeCells(rowPos, data.header.length - 1);
|
1167
1222
|
}
|
1168
1223
|
|
1169
|
-
if (
|
1170
|
-
addRow(
|
1171
|
-
mergeCells(
|
1224
|
+
if (exportInfo.messageTop) {
|
1225
|
+
addRow([exportInfo.messageTop], rowPos);
|
1226
|
+
mergeCells(rowPos, data.header.length - 1);
|
1172
1227
|
}
|
1173
1228
|
|
1174
|
-
|
1175
1229
|
// Table itself
|
1176
|
-
if (
|
1177
|
-
addRow(
|
1178
|
-
$('row:last c', rels).attr(
|
1230
|
+
if (config.header) {
|
1231
|
+
addRow(data.header, rowPos);
|
1232
|
+
$('row:last c', rels).attr('s', '2'); // bold
|
1179
1233
|
}
|
1180
1234
|
|
1181
1235
|
dataStartRow = rowPos;
|
1182
1236
|
|
1183
|
-
for (
|
1184
|
-
addRow(
|
1237
|
+
for (var n = 0, ie = data.body.length; n < ie; n++) {
|
1238
|
+
addRow(data.body[n], rowPos);
|
1185
1239
|
}
|
1186
1240
|
|
1187
1241
|
dataEndRow = rowPos;
|
1188
1242
|
|
1189
|
-
if (
|
1190
|
-
addRow(
|
1191
|
-
$('row:last c', rels).attr(
|
1243
|
+
if (config.footer && data.footer) {
|
1244
|
+
addRow(data.footer, rowPos);
|
1245
|
+
$('row:last c', rels).attr('s', '2'); // bold
|
1192
1246
|
}
|
1193
1247
|
|
1194
1248
|
// Below the table
|
1195
|
-
if (
|
1196
|
-
addRow(
|
1197
|
-
mergeCells(
|
1249
|
+
if (exportInfo.messageBottom) {
|
1250
|
+
addRow([exportInfo.messageBottom], rowPos);
|
1251
|
+
mergeCells(rowPos, data.header.length - 1);
|
1198
1252
|
}
|
1199
1253
|
|
1200
1254
|
// Set column widths
|
1201
|
-
var cols = _createNode(
|
1202
|
-
$('worksheet', rels).prepend(
|
1203
|
-
|
1204
|
-
for (
|
1205
|
-
cols.appendChild(
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1255
|
+
var cols = _createNode(rels, 'cols');
|
1256
|
+
$('worksheet', rels).prepend(cols);
|
1257
|
+
|
1258
|
+
for (var i = 0, ien = data.header.length; i < ien; i++) {
|
1259
|
+
cols.appendChild(
|
1260
|
+
_createNode(rels, 'col', {
|
1261
|
+
attr: {
|
1262
|
+
min: i + 1,
|
1263
|
+
max: i + 1,
|
1264
|
+
width: _excelColWidth(data, i),
|
1265
|
+
customWidth: 1
|
1266
|
+
}
|
1267
|
+
})
|
1268
|
+
);
|
1213
1269
|
}
|
1214
1270
|
|
1215
|
-
// Auto filter for columns
|
1216
|
-
$('mergeCells', rels).before( _createNode( rels, 'autoFilter', {
|
1217
|
-
attr: {
|
1218
|
-
ref: 'A'+dataStartRow+':'+createCellPos(data.header.length-1)+dataEndRow
|
1219
|
-
}
|
1220
|
-
} ) );
|
1221
|
-
|
1222
1271
|
// Workbook modifications
|
1223
1272
|
var workbook = xlsx.xl['workbook.xml'];
|
1224
1273
|
|
1225
|
-
$(
|
1274
|
+
$('sheets sheet', workbook).attr('name', _sheetname(config));
|
1226
1275
|
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1276
|
+
// Auto filter for columns
|
1277
|
+
if (config.autoFilter) {
|
1278
|
+
$('mergeCells', rels).before(
|
1279
|
+
_createNode(rels, 'autoFilter', {
|
1280
|
+
attr: {
|
1281
|
+
ref:
|
1282
|
+
'A' +
|
1283
|
+
dataStartRow +
|
1284
|
+
':' +
|
1285
|
+
createCellPos(data.header.length - 1) +
|
1286
|
+
dataEndRow
|
1287
|
+
}
|
1288
|
+
})
|
1289
|
+
);
|
1290
|
+
|
1291
|
+
$('definedNames', workbook).append(
|
1292
|
+
_createNode(workbook, 'definedName', {
|
1293
|
+
attr: {
|
1294
|
+
name: '_xlnm._FilterDatabase',
|
1295
|
+
localSheetId: '0',
|
1296
|
+
hidden: 1
|
1297
|
+
},
|
1298
|
+
text:
|
1299
|
+
_sheetname(config) +
|
1300
|
+
'!$A$' +
|
1301
|
+
dataStartRow +
|
1302
|
+
':' +
|
1303
|
+
createCellPos(data.header.length - 1) +
|
1304
|
+
dataEndRow
|
1305
|
+
})
|
1306
|
+
);
|
1236
1307
|
}
|
1237
1308
|
|
1238
1309
|
// Let the developer customise the document if they want to
|
1239
|
-
if (
|
1240
|
-
config.customize(
|
1310
|
+
if (config.customize) {
|
1311
|
+
config.customize(xlsx, config, dt);
|
1241
1312
|
}
|
1242
1313
|
|
1243
1314
|
// Excel doesn't like an empty mergeCells tag
|
1244
|
-
if (
|
1315
|
+
if ($('mergeCells', rels).children().length === 0) {
|
1245
1316
|
$('mergeCells', rels).remove();
|
1246
1317
|
}
|
1247
1318
|
|
1248
1319
|
var jszip = _jsZip();
|
1249
1320
|
var zip = new jszip();
|
1250
1321
|
var zipConfig = {
|
1322
|
+
compression: 'DEFLATE',
|
1251
1323
|
type: 'blob',
|
1252
1324
|
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
1253
1325
|
};
|
1254
1326
|
|
1255
|
-
_addToZip(
|
1327
|
+
_addToZip(zip, xlsx);
|
1328
|
+
|
1329
|
+
// Modern Excel has a 218 character limit on the file name + path of the file (why!?)
|
1330
|
+
// https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3
|
1331
|
+
// So we truncate to allow for this.
|
1332
|
+
var filename = exportInfo.filename;
|
1333
|
+
|
1334
|
+
if (filename > 175) {
|
1335
|
+
filename = filename.substr(0, 175);
|
1336
|
+
}
|
1256
1337
|
|
1257
|
-
if (
|
1338
|
+
if (zip.generateAsync) {
|
1258
1339
|
// JSZip 3+
|
1259
|
-
zip
|
1260
|
-
|
1261
|
-
.
|
1262
|
-
|
1263
|
-
that.processing( false );
|
1264
|
-
} );
|
1340
|
+
zip.generateAsync(zipConfig).then(function (blob) {
|
1341
|
+
_saveAs(blob, filename);
|
1342
|
+
that.processing(false);
|
1343
|
+
});
|
1265
1344
|
}
|
1266
1345
|
else {
|
1267
1346
|
// JSZip 2.5
|
1268
|
-
_saveAs(
|
1269
|
-
|
1270
|
-
exportInfo.filename
|
1271
|
-
);
|
1272
|
-
this.processing( false );
|
1347
|
+
_saveAs(zip.generate(zipConfig), filename);
|
1348
|
+
this.processing(false);
|
1273
1349
|
}
|
1274
1350
|
},
|
1275
1351
|
|
@@ -1306,46 +1382,52 @@ DataTable.ext.buttons.pdfHtml5 = {
|
|
1306
1382
|
return window.FileReader !== undefined && _pdfMake();
|
1307
1383
|
},
|
1308
1384
|
|
1309
|
-
text: function (
|
1310
|
-
return dt.i18n(
|
1385
|
+
text: function (dt) {
|
1386
|
+
return dt.i18n('buttons.pdf', 'PDF');
|
1311
1387
|
},
|
1312
1388
|
|
1313
|
-
action: function (
|
1314
|
-
this.processing(
|
1389
|
+
action: function (e, dt, button, config) {
|
1390
|
+
this.processing(true);
|
1315
1391
|
|
1316
1392
|
var that = this;
|
1317
|
-
var data = dt.buttons.exportData(
|
1318
|
-
var info = dt.buttons.exportInfo(
|
1393
|
+
var data = dt.buttons.exportData(config.exportOptions);
|
1394
|
+
var info = dt.buttons.exportInfo(config);
|
1319
1395
|
var rows = [];
|
1320
1396
|
|
1321
|
-
if (
|
1322
|
-
rows.push(
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1397
|
+
if (config.header) {
|
1398
|
+
rows.push(
|
1399
|
+
$.map(data.header, function (d) {
|
1400
|
+
return {
|
1401
|
+
text: typeof d === 'string' ? d : d + '',
|
1402
|
+
style: 'tableHeader'
|
1403
|
+
};
|
1404
|
+
})
|
1405
|
+
);
|
1328
1406
|
}
|
1329
1407
|
|
1330
|
-
for (
|
1331
|
-
rows.push(
|
1332
|
-
|
1333
|
-
d
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1408
|
+
for (var i = 0, ien = data.body.length; i < ien; i++) {
|
1409
|
+
rows.push(
|
1410
|
+
$.map(data.body[i], function (d) {
|
1411
|
+
if (d === null || d === undefined) {
|
1412
|
+
d = '';
|
1413
|
+
}
|
1414
|
+
return {
|
1415
|
+
text: typeof d === 'string' ? d : d + '',
|
1416
|
+
style: i % 2 ? 'tableBodyEven' : 'tableBodyOdd'
|
1417
|
+
};
|
1418
|
+
})
|
1419
|
+
);
|
1340
1420
|
}
|
1341
1421
|
|
1342
|
-
if (
|
1343
|
-
rows.push(
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1422
|
+
if (config.footer && data.footer) {
|
1423
|
+
rows.push(
|
1424
|
+
$.map(data.footer, function (d) {
|
1425
|
+
return {
|
1426
|
+
text: typeof d === 'string' ? d : d + '',
|
1427
|
+
style: 'tableFooter'
|
1428
|
+
};
|
1429
|
+
})
|
1430
|
+
);
|
1349
1431
|
}
|
1350
1432
|
|
1351
1433
|
var doc = {
|
@@ -1389,44 +1471,44 @@ DataTable.ext.buttons.pdfHtml5 = {
|
|
1389
1471
|
}
|
1390
1472
|
};
|
1391
1473
|
|
1392
|
-
if (
|
1393
|
-
doc.content.unshift(
|
1474
|
+
if (info.messageTop) {
|
1475
|
+
doc.content.unshift({
|
1394
1476
|
text: info.messageTop,
|
1395
1477
|
style: 'message',
|
1396
|
-
margin: [
|
1397
|
-
}
|
1478
|
+
margin: [0, 0, 0, 12]
|
1479
|
+
});
|
1398
1480
|
}
|
1399
1481
|
|
1400
|
-
if (
|
1401
|
-
doc.content.push(
|
1482
|
+
if (info.messageBottom) {
|
1483
|
+
doc.content.push({
|
1402
1484
|
text: info.messageBottom,
|
1403
1485
|
style: 'message',
|
1404
|
-
margin: [
|
1405
|
-
}
|
1486
|
+
margin: [0, 0, 0, 12]
|
1487
|
+
});
|
1406
1488
|
}
|
1407
1489
|
|
1408
|
-
if (
|
1409
|
-
doc.content.unshift(
|
1490
|
+
if (info.title) {
|
1491
|
+
doc.content.unshift({
|
1410
1492
|
text: info.title,
|
1411
1493
|
style: 'title',
|
1412
|
-
margin: [
|
1413
|
-
}
|
1494
|
+
margin: [0, 0, 0, 12]
|
1495
|
+
});
|
1414
1496
|
}
|
1415
1497
|
|
1416
|
-
if (
|
1417
|
-
config.customize(
|
1498
|
+
if (config.customize) {
|
1499
|
+
config.customize(doc, config, dt);
|
1418
1500
|
}
|
1419
1501
|
|
1420
|
-
var pdf = _pdfMake().createPdf(
|
1502
|
+
var pdf = _pdfMake().createPdf(doc);
|
1421
1503
|
|
1422
|
-
if (
|
1504
|
+
if (config.download === 'open' && !_isDuffSafari()) {
|
1423
1505
|
pdf.open();
|
1424
1506
|
}
|
1425
1507
|
else {
|
1426
|
-
pdf.download(
|
1508
|
+
pdf.download(info.filename);
|
1427
1509
|
}
|
1428
1510
|
|
1429
|
-
this.processing(
|
1511
|
+
this.processing(false);
|
1430
1512
|
},
|
1431
1513
|
|
1432
1514
|
title: '*',
|
@@ -1455,5 +1537,5 @@ DataTable.ext.buttons.pdfHtml5 = {
|
|
1455
1537
|
};
|
1456
1538
|
|
1457
1539
|
|
1458
|
-
return DataTable
|
1540
|
+
return DataTable;
|
1459
1541
|
}));
|