vxe-table-plugin-export-xlsx-xhx 1.0.1 → 1.0.2
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.
- package/dist/index.common.js +243 -259
- package/dist/index.js +255 -269
- package/dist/index.min.js +1 -1
- package/package.json +36 -36
- package/dist/index.umd.js +0 -546
- package/dist/index.umd.min.js +0 -1
package/dist/index.umd.js
DELETED
@@ -1,546 +0,0 @@
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
2
|
-
(function (global, factory) {
|
3
|
-
if (typeof define === "function" && define.amd) {
|
4
|
-
define("vxe-table-plugin-export-xlsx", ["exports", "xe-utils", "exceljs"], factory);
|
5
|
-
} else if (typeof exports !== "undefined") {
|
6
|
-
factory(exports, require("xe-utils"), require("exceljs"));
|
7
|
-
} else {
|
8
|
-
var mod = {
|
9
|
-
exports: {}
|
10
|
-
};
|
11
|
-
factory(mod.exports, global.XEUtils, global.ExcelJS);
|
12
|
-
global.VXETablePluginExportXLSX = mod.exports.default;
|
13
|
-
}
|
14
|
-
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _xeUtils, ExcelJS) {
|
15
|
-
"use strict";
|
16
|
-
|
17
|
-
Object.defineProperty(_exports, "__esModule", {
|
18
|
-
value: true
|
19
|
-
});
|
20
|
-
_exports["default"] = _exports.VXETablePluginExportXLSX = void 0;
|
21
|
-
_xeUtils = _interopRequireDefault(_xeUtils);
|
22
|
-
ExcelJS = _interopRequireWildcard(ExcelJS);
|
23
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
24
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
25
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
26
|
-
var defaultHeaderBackgroundColor = 'f8f8f9';
|
27
|
-
var defaultCellFontColor = '606266';
|
28
|
-
var defaultCellBorderStyle = 'thin';
|
29
|
-
var defaultCellBorderColor = 'e8eaec';
|
30
|
-
function getCellLabel(column, cellValue) {
|
31
|
-
if (cellValue) {
|
32
|
-
switch (column.cellType) {
|
33
|
-
case 'string':
|
34
|
-
return _xeUtils["default"].toValueString(cellValue);
|
35
|
-
case 'number':
|
36
|
-
if (!isNaN(cellValue)) {
|
37
|
-
return Number(cellValue);
|
38
|
-
}
|
39
|
-
break;
|
40
|
-
default:
|
41
|
-
if (cellValue.length < 12 && !isNaN(cellValue)) {
|
42
|
-
return Number(cellValue);
|
43
|
-
}
|
44
|
-
break;
|
45
|
-
}
|
46
|
-
}
|
47
|
-
return cellValue;
|
48
|
-
}
|
49
|
-
function getFooterData(opts, footerData) {
|
50
|
-
var footerFilterMethod = opts.footerFilterMethod;
|
51
|
-
return footerFilterMethod ? footerData.filter(function (items, index) {
|
52
|
-
return footerFilterMethod({
|
53
|
-
items: items,
|
54
|
-
$rowIndex: index
|
55
|
-
});
|
56
|
-
}) : footerData;
|
57
|
-
}
|
58
|
-
function getFooterCellValue($table, opts, rows, column) {
|
59
|
-
var cellValue = getCellLabel(column, rows[$table.getVMColumnIndex(column)]);
|
60
|
-
return cellValue;
|
61
|
-
}
|
62
|
-
function getValidColumn(column) {
|
63
|
-
var childNodes = column.childNodes;
|
64
|
-
var isColGroup = childNodes && childNodes.length;
|
65
|
-
if (isColGroup) {
|
66
|
-
return getValidColumn(childNodes[0]);
|
67
|
-
}
|
68
|
-
return column;
|
69
|
-
}
|
70
|
-
function setExcelRowHeight(excelRow, height) {
|
71
|
-
if (height) {
|
72
|
-
excelRow.height = _xeUtils["default"].floor(height * 0.75, 12);
|
73
|
-
}
|
74
|
-
}
|
75
|
-
function setExcelCellStyle(excelCell, align) {
|
76
|
-
excelCell.protection = {
|
77
|
-
locked: false
|
78
|
-
};
|
79
|
-
excelCell.alignment = {
|
80
|
-
vertical: 'middle',
|
81
|
-
horizontal: align || 'left'
|
82
|
-
};
|
83
|
-
}
|
84
|
-
function getDefaultBorderStyle() {
|
85
|
-
return {
|
86
|
-
top: {
|
87
|
-
style: defaultCellBorderStyle,
|
88
|
-
color: {
|
89
|
-
argb: defaultCellBorderColor
|
90
|
-
}
|
91
|
-
},
|
92
|
-
left: {
|
93
|
-
style: defaultCellBorderStyle,
|
94
|
-
color: {
|
95
|
-
argb: defaultCellBorderColor
|
96
|
-
}
|
97
|
-
},
|
98
|
-
bottom: {
|
99
|
-
style: defaultCellBorderStyle,
|
100
|
-
color: {
|
101
|
-
argb: defaultCellBorderColor
|
102
|
-
}
|
103
|
-
},
|
104
|
-
right: {
|
105
|
-
style: defaultCellBorderStyle,
|
106
|
-
color: {
|
107
|
-
argb: defaultCellBorderColor
|
108
|
-
}
|
109
|
-
}
|
110
|
-
};
|
111
|
-
}
|
112
|
-
function exportXLSX(params) {
|
113
|
-
var msgKey = 'xlsx';
|
114
|
-
var $table = params.$table,
|
115
|
-
options = params.options,
|
116
|
-
columns = params.columns,
|
117
|
-
colgroups = params.colgroups,
|
118
|
-
datas = params.datas;
|
119
|
-
var $vxe = $table.$vxe,
|
120
|
-
rowHeight = $table.rowHeight,
|
121
|
-
allHeaderAlign = $table.headerAlign,
|
122
|
-
allAlign = $table.align,
|
123
|
-
allFooterAlign = $table.footerAlign;
|
124
|
-
var modal = $vxe.modal,
|
125
|
-
t = $vxe.t;
|
126
|
-
var message = options.message,
|
127
|
-
sheetName = options.sheetName,
|
128
|
-
isHeader = options.isHeader,
|
129
|
-
isFooter = options.isFooter,
|
130
|
-
isMerge = options.isMerge,
|
131
|
-
isColgroup = options.isColgroup,
|
132
|
-
original = options.original,
|
133
|
-
useStyle = options.useStyle,
|
134
|
-
sheetMethod = options.sheetMethod;
|
135
|
-
var showMsg = message !== false;
|
136
|
-
var mergeCells = $table.getMergeCells();
|
137
|
-
var colList = [];
|
138
|
-
var footList = [];
|
139
|
-
var sheetCols = [];
|
140
|
-
var sheetMerges = [];
|
141
|
-
var beforeRowCount = 0;
|
142
|
-
var colHead = {};
|
143
|
-
columns.forEach(function (column) {
|
144
|
-
var id = column.id,
|
145
|
-
property = column.property,
|
146
|
-
renderWidth = column.renderWidth;
|
147
|
-
colHead[id] = original ? property : column.getTitle();
|
148
|
-
sheetCols.push({
|
149
|
-
key: id,
|
150
|
-
width: _xeUtils["default"].ceil(renderWidth / 8, 1)
|
151
|
-
});
|
152
|
-
});
|
153
|
-
// 处理表头
|
154
|
-
if (isHeader) {
|
155
|
-
// 处理分组
|
156
|
-
if (isColgroup && !original && colgroups) {
|
157
|
-
colgroups.forEach(function (cols, rIndex) {
|
158
|
-
var groupHead = {};
|
159
|
-
columns.forEach(function (column) {
|
160
|
-
groupHead[column.id] = null;
|
161
|
-
});
|
162
|
-
cols.forEach(function (column) {
|
163
|
-
var _colSpan = column._colSpan,
|
164
|
-
_rowSpan = column._rowSpan;
|
165
|
-
var validColumn = getValidColumn(column);
|
166
|
-
var columnIndex = columns.indexOf(validColumn);
|
167
|
-
groupHead[validColumn.id] = original ? validColumn.property : column.getTitle();
|
168
|
-
if (_colSpan > 1 || _rowSpan > 1) {
|
169
|
-
sheetMerges.push({
|
170
|
-
s: {
|
171
|
-
r: rIndex,
|
172
|
-
c: columnIndex
|
173
|
-
},
|
174
|
-
e: {
|
175
|
-
r: rIndex + _rowSpan - 1,
|
176
|
-
c: columnIndex + _colSpan - 1
|
177
|
-
}
|
178
|
-
});
|
179
|
-
}
|
180
|
-
});
|
181
|
-
colList.push(groupHead);
|
182
|
-
});
|
183
|
-
} else {
|
184
|
-
colList.push(colHead);
|
185
|
-
}
|
186
|
-
beforeRowCount += colList.length;
|
187
|
-
}
|
188
|
-
// 处理合并
|
189
|
-
if (isMerge && !original) {
|
190
|
-
mergeCells.forEach(function (mergeItem) {
|
191
|
-
var mergeRowIndex = mergeItem.row,
|
192
|
-
mergeRowspan = mergeItem.rowspan,
|
193
|
-
mergeColIndex = mergeItem.col,
|
194
|
-
mergeColspan = mergeItem.colspan;
|
195
|
-
sheetMerges.push({
|
196
|
-
s: {
|
197
|
-
r: mergeRowIndex + beforeRowCount,
|
198
|
-
c: mergeColIndex
|
199
|
-
},
|
200
|
-
e: {
|
201
|
-
r: mergeRowIndex + beforeRowCount + mergeRowspan - 1,
|
202
|
-
c: mergeColIndex + mergeColspan - 1
|
203
|
-
}
|
204
|
-
});
|
205
|
-
});
|
206
|
-
}
|
207
|
-
var rowList = datas.map(function (item) {
|
208
|
-
var rest = {};
|
209
|
-
columns.forEach(function (column) {
|
210
|
-
rest[column.id] = getCellLabel(column, item[column.id]);
|
211
|
-
});
|
212
|
-
return rest;
|
213
|
-
});
|
214
|
-
beforeRowCount += rowList.length;
|
215
|
-
// 处理表尾
|
216
|
-
if (isFooter) {
|
217
|
-
var _$table$getTableData = $table.getTableData(),
|
218
|
-
footerData = _$table$getTableData.footerData;
|
219
|
-
var footers = getFooterData(options, footerData);
|
220
|
-
var mergeFooterItems = $table.getMergeFooterItems();
|
221
|
-
// 处理合并
|
222
|
-
if (isMerge && !original) {
|
223
|
-
mergeFooterItems.forEach(function (mergeItem) {
|
224
|
-
var mergeRowIndex = mergeItem.row,
|
225
|
-
mergeRowspan = mergeItem.rowspan,
|
226
|
-
mergeColIndex = mergeItem.col,
|
227
|
-
mergeColspan = mergeItem.colspan;
|
228
|
-
sheetMerges.push({
|
229
|
-
s: {
|
230
|
-
r: mergeRowIndex + beforeRowCount,
|
231
|
-
c: mergeColIndex
|
232
|
-
},
|
233
|
-
e: {
|
234
|
-
r: mergeRowIndex + beforeRowCount + mergeRowspan - 1,
|
235
|
-
c: mergeColIndex + mergeColspan - 1
|
236
|
-
}
|
237
|
-
});
|
238
|
-
});
|
239
|
-
}
|
240
|
-
footers.forEach(function (rows) {
|
241
|
-
var item = {};
|
242
|
-
columns.forEach(function (column) {
|
243
|
-
item[column.id] = getFooterCellValue($table, options, rows, column);
|
244
|
-
});
|
245
|
-
footList.push(item);
|
246
|
-
});
|
247
|
-
}
|
248
|
-
var exportMethod = function exportMethod() {
|
249
|
-
var workbook = new ExcelJS.Workbook();
|
250
|
-
var sheet = workbook.addWorksheet(sheetName);
|
251
|
-
workbook.creator = 'vxe-table';
|
252
|
-
sheet.columns = sheetCols;
|
253
|
-
if (isHeader) {
|
254
|
-
sheet.addRows(colList).forEach(function (excelRow) {
|
255
|
-
if (useStyle) {
|
256
|
-
setExcelRowHeight(excelRow, rowHeight);
|
257
|
-
}
|
258
|
-
excelRow.eachCell(function (excelCell) {
|
259
|
-
var excelCol = sheet.getColumn(excelCell.col);
|
260
|
-
var column = $table.getColumnById(excelCol.key);
|
261
|
-
var headerAlign = column.headerAlign,
|
262
|
-
align = column.align;
|
263
|
-
setExcelCellStyle(excelCell, headerAlign || align || allHeaderAlign || allAlign);
|
264
|
-
if (useStyle) {
|
265
|
-
Object.assign(excelCell, {
|
266
|
-
font: {
|
267
|
-
bold: true,
|
268
|
-
color: {
|
269
|
-
argb: defaultCellFontColor
|
270
|
-
}
|
271
|
-
},
|
272
|
-
fill: {
|
273
|
-
type: 'pattern',
|
274
|
-
pattern: 'solid',
|
275
|
-
fgColor: {
|
276
|
-
argb: defaultHeaderBackgroundColor
|
277
|
-
}
|
278
|
-
},
|
279
|
-
border: getDefaultBorderStyle()
|
280
|
-
});
|
281
|
-
}
|
282
|
-
});
|
283
|
-
});
|
284
|
-
}
|
285
|
-
sheet.addRows(rowList).forEach(function (excelRow) {
|
286
|
-
if (useStyle) {
|
287
|
-
setExcelRowHeight(excelRow, rowHeight);
|
288
|
-
}
|
289
|
-
excelRow.eachCell(function (excelCell) {
|
290
|
-
var excelCol = sheet.getColumn(excelCell.col);
|
291
|
-
var column = $table.getColumnById(excelCol.key);
|
292
|
-
var align = column.align;
|
293
|
-
setExcelCellStyle(excelCell, align || allAlign);
|
294
|
-
if (useStyle) {
|
295
|
-
Object.assign(excelCell, {
|
296
|
-
font: {
|
297
|
-
color: {
|
298
|
-
argb: defaultCellFontColor
|
299
|
-
}
|
300
|
-
},
|
301
|
-
border: getDefaultBorderStyle()
|
302
|
-
});
|
303
|
-
}
|
304
|
-
});
|
305
|
-
});
|
306
|
-
if (isFooter) {
|
307
|
-
sheet.addRows(footList).forEach(function (excelRow) {
|
308
|
-
if (useStyle) {
|
309
|
-
setExcelRowHeight(excelRow, rowHeight);
|
310
|
-
}
|
311
|
-
excelRow.eachCell(function (excelCell) {
|
312
|
-
var excelCol = sheet.getColumn(excelCell.col);
|
313
|
-
var column = $table.getColumnById(excelCol.key);
|
314
|
-
var footerAlign = column.footerAlign,
|
315
|
-
align = column.align;
|
316
|
-
setExcelCellStyle(excelCell, footerAlign || align || allFooterAlign || allAlign);
|
317
|
-
if (useStyle) {
|
318
|
-
Object.assign(excelCell, {
|
319
|
-
font: {
|
320
|
-
color: {
|
321
|
-
argb: defaultCellFontColor
|
322
|
-
}
|
323
|
-
},
|
324
|
-
border: getDefaultBorderStyle()
|
325
|
-
});
|
326
|
-
}
|
327
|
-
});
|
328
|
-
});
|
329
|
-
}
|
330
|
-
if (useStyle && sheetMethod) {
|
331
|
-
var sParams = {
|
332
|
-
options: options,
|
333
|
-
workbook: workbook,
|
334
|
-
worksheet: sheet,
|
335
|
-
columns: columns,
|
336
|
-
colgroups: colgroups,
|
337
|
-
datas: datas,
|
338
|
-
$table: $table
|
339
|
-
};
|
340
|
-
sheetMethod(sParams);
|
341
|
-
}
|
342
|
-
sheetMerges.forEach(function (_ref) {
|
343
|
-
var s = _ref.s,
|
344
|
-
e = _ref.e;
|
345
|
-
sheet.mergeCells(s.r + 1, s.c + 1, e.r + 1, e.c + 1);
|
346
|
-
});
|
347
|
-
workbook.xlsx.writeBuffer().then(function (buffer) {
|
348
|
-
var blob = new Blob([buffer], {
|
349
|
-
type: 'application/octet-stream'
|
350
|
-
});
|
351
|
-
// 导出 xlsx
|
352
|
-
downloadFile(params, blob, options);
|
353
|
-
if (showMsg && modal) {
|
354
|
-
modal.close(msgKey);
|
355
|
-
modal.message({
|
356
|
-
content: t('vxe.table.expSuccess'),
|
357
|
-
status: 'success'
|
358
|
-
});
|
359
|
-
}
|
360
|
-
});
|
361
|
-
};
|
362
|
-
if (showMsg && modal) {
|
363
|
-
modal.message({
|
364
|
-
id: msgKey,
|
365
|
-
content: t('vxe.table.expLoading'),
|
366
|
-
status: 'loading',
|
367
|
-
duration: -1
|
368
|
-
});
|
369
|
-
setTimeout(exportMethod, 1500);
|
370
|
-
} else {
|
371
|
-
exportMethod();
|
372
|
-
}
|
373
|
-
}
|
374
|
-
function downloadFile(params, blob, options) {
|
375
|
-
var $table = params.$table;
|
376
|
-
var $vxe = $table.$vxe;
|
377
|
-
var modal = $vxe.modal,
|
378
|
-
t = $vxe.t;
|
379
|
-
var message = options.message,
|
380
|
-
filename = options.filename,
|
381
|
-
type = options.type;
|
382
|
-
var showMsg = message !== false;
|
383
|
-
if (window.Blob) {
|
384
|
-
if (navigator.msSaveBlob) {
|
385
|
-
navigator.msSaveBlob(blob, "".concat(filename, ".").concat(type));
|
386
|
-
} else {
|
387
|
-
var linkElem = document.createElement('a');
|
388
|
-
linkElem.target = '_blank';
|
389
|
-
linkElem.download = "".concat(filename, ".").concat(type);
|
390
|
-
linkElem.href = URL.createObjectURL(blob);
|
391
|
-
document.body.appendChild(linkElem);
|
392
|
-
linkElem.click();
|
393
|
-
document.body.removeChild(linkElem);
|
394
|
-
}
|
395
|
-
} else {
|
396
|
-
if (showMsg && modal) {
|
397
|
-
modal.alert({
|
398
|
-
content: t('vxe.error.notExp'),
|
399
|
-
status: 'error'
|
400
|
-
});
|
401
|
-
}
|
402
|
-
}
|
403
|
-
}
|
404
|
-
function checkImportData(tableFields, fields) {
|
405
|
-
return fields.some(function (field) {
|
406
|
-
return tableFields.indexOf(field) > -1;
|
407
|
-
});
|
408
|
-
}
|
409
|
-
function importError(params) {
|
410
|
-
var $table = params.$table,
|
411
|
-
options = params.options;
|
412
|
-
var $vxe = $table.$vxe,
|
413
|
-
_importReject = $table._importReject;
|
414
|
-
var showMsg = options.message !== false;
|
415
|
-
var modal = $vxe.modal,
|
416
|
-
t = $vxe.t;
|
417
|
-
if (showMsg && modal) {
|
418
|
-
modal.message({
|
419
|
-
content: t('vxe.error.impFields'),
|
420
|
-
status: 'error'
|
421
|
-
});
|
422
|
-
}
|
423
|
-
if (_importReject) {
|
424
|
-
_importReject({
|
425
|
-
status: false
|
426
|
-
});
|
427
|
-
}
|
428
|
-
}
|
429
|
-
function importXLSX(params) {
|
430
|
-
var $table = params.$table,
|
431
|
-
columns = params.columns,
|
432
|
-
options = params.options,
|
433
|
-
file = params.file;
|
434
|
-
var $vxe = $table.$vxe,
|
435
|
-
_importResolve = $table._importResolve;
|
436
|
-
var modal = $vxe.modal,
|
437
|
-
t = $vxe.t;
|
438
|
-
var showMsg = options.message !== false;
|
439
|
-
var fileReader = new FileReader();
|
440
|
-
fileReader.onerror = function () {
|
441
|
-
importError(params);
|
442
|
-
};
|
443
|
-
fileReader.onload = function (evnt) {
|
444
|
-
var tableFields = [];
|
445
|
-
columns.forEach(function (column) {
|
446
|
-
var field = column.property;
|
447
|
-
if (field) {
|
448
|
-
tableFields.push(field);
|
449
|
-
}
|
450
|
-
});
|
451
|
-
var workbook = new ExcelJS.Workbook();
|
452
|
-
var readerTarget = evnt.target;
|
453
|
-
if (readerTarget) {
|
454
|
-
workbook.xlsx.load(readerTarget.result).then(function (wb) {
|
455
|
-
var firstSheet = wb.worksheets[0];
|
456
|
-
if (firstSheet) {
|
457
|
-
var sheetValues = firstSheet.getSheetValues();
|
458
|
-
var fieldIndex = _xeUtils["default"].findIndexOf(sheetValues, function (list) {
|
459
|
-
return list && list.length > 0;
|
460
|
-
});
|
461
|
-
var fields = sheetValues[fieldIndex];
|
462
|
-
var status = checkImportData(tableFields, fields);
|
463
|
-
if (status) {
|
464
|
-
var records = sheetValues.slice(fieldIndex).map(function (list) {
|
465
|
-
var item = {};
|
466
|
-
list.forEach(function (cellValue, cIndex) {
|
467
|
-
item[fields[cIndex]] = cellValue;
|
468
|
-
});
|
469
|
-
var record = {};
|
470
|
-
tableFields.forEach(function (field) {
|
471
|
-
record[field] = _xeUtils["default"].isUndefined(item[field]) ? null : item[field];
|
472
|
-
});
|
473
|
-
return record;
|
474
|
-
});
|
475
|
-
$table.createData(records).then(function (data) {
|
476
|
-
var loadRest;
|
477
|
-
if (options.mode === 'insert') {
|
478
|
-
loadRest = $table.insertAt(data, -1);
|
479
|
-
} else {
|
480
|
-
loadRest = $table.reloadData(data);
|
481
|
-
}
|
482
|
-
return loadRest.then(function () {
|
483
|
-
if (_importResolve) {
|
484
|
-
_importResolve({
|
485
|
-
status: true
|
486
|
-
});
|
487
|
-
}
|
488
|
-
});
|
489
|
-
});
|
490
|
-
if (showMsg && modal) {
|
491
|
-
modal.message({
|
492
|
-
content: t('vxe.table.impSuccess', [records.length]),
|
493
|
-
status: 'success'
|
494
|
-
});
|
495
|
-
}
|
496
|
-
} else {
|
497
|
-
importError(params);
|
498
|
-
}
|
499
|
-
} else {
|
500
|
-
importError(params);
|
501
|
-
}
|
502
|
-
});
|
503
|
-
} else {
|
504
|
-
importError(params);
|
505
|
-
}
|
506
|
-
};
|
507
|
-
fileReader.readAsArrayBuffer(file);
|
508
|
-
}
|
509
|
-
function handleImportEvent(params) {
|
510
|
-
if (params.options.type === 'xlsx') {
|
511
|
-
importXLSX(params);
|
512
|
-
return false;
|
513
|
-
}
|
514
|
-
}
|
515
|
-
function handleExportEvent(params) {
|
516
|
-
if (params.options.type === 'xlsx') {
|
517
|
-
exportXLSX(params);
|
518
|
-
return false;
|
519
|
-
}
|
520
|
-
}
|
521
|
-
/**
|
522
|
-
* 基于 vxe-table 表格的增强插件,支持导出 xlsx 格式
|
523
|
-
*/
|
524
|
-
var VXETablePluginExportXLSX = {
|
525
|
-
install: function install(vxetable) {
|
526
|
-
var interceptor = vxetable.interceptor;
|
527
|
-
vxetable.setup({
|
528
|
-
"export": {
|
529
|
-
types: {
|
530
|
-
xlsx: 0
|
531
|
-
}
|
532
|
-
}
|
533
|
-
});
|
534
|
-
interceptor.mixin({
|
535
|
-
'event.import': handleImportEvent,
|
536
|
-
'event.export': handleExportEvent
|
537
|
-
});
|
538
|
-
}
|
539
|
-
};
|
540
|
-
_exports.VXETablePluginExportXLSX = VXETablePluginExportXLSX;
|
541
|
-
if (typeof window !== 'undefined' && window.VXETable && window.VXETable.use) {
|
542
|
-
window.VXETable.use(VXETablePluginExportXLSX);
|
543
|
-
}
|
544
|
-
var _default = VXETablePluginExportXLSX;
|
545
|
-
_exports["default"] = _default;
|
546
|
-
});
|
package/dist/index.umd.min.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}!function(e,t){"function"==typeof define&&define.amd?define("vxe-table-plugin-export-xlsx",["exports","xe-utils","exceljs"],t):"undefined"!=typeof exports?t(exports,require("xe-utils"),require("exceljs")):(t((t={exports:{}}).exports,e.XEUtils,e.ExcelJS),e.VXETablePluginExportXLSX=t.exports.default)}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(e,M,$){"use strict";function l(e){var t,o;return"function"!=typeof WeakMap?null:(t=new WeakMap,o=new WeakMap,(l=function(e){return e?o:t})(e))}Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.VXETablePluginExportXLSX=void 0,M=(c=M)&&c.__esModule?c:{default:c},$=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!==_typeof(e)&&"function"!=typeof e)return{default:e};t=l(t);if(t&&t.has(e))return t.get(e);var o,n={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(o in e){var a;"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&((a=r?Object.getOwnPropertyDescriptor(e,o):null)&&(a.get||a.set)?Object.defineProperty(n,o,a):n[o]=e[o])}n.default=e,t&&t.set(e,n);return n}($);var B="f8f8f9",P="606266",t="thin",o="e8eaec";function V(e,t){if(t)switch(e.cellType){case"string":return M.default.toValueString(t);case"number":if(isNaN(t))break;return Number(t);default:if(t.length<12&&!isNaN(t))return Number(t)}return t}function N(e,t){t&&(e.height=M.default.floor(.75*t,12))}function R(e,t){e.protection={locked:!1},e.alignment={vertical:"middle",horizontal:t||"left"}}function A(){return{top:{style:t,color:{argb:o}},left:{style:t,color:{argb:o}},bottom:{style:t,color:{argb:o}},right:{style:t,color:{argb:o}}}}function n(i){function e(){var e=new $.Workbook,n=e.addWorksheet(h);e.creator="vxe-table",n.columns=O,b&&n.addRows(S).forEach(function(e){w&&N(e,l),e.eachCell(function(e){var t=n.getColumn(e.col),t=r.getColumnById(t.key),o=t.headerAlign,t=t.align;R(e,o||t||u||f),w&&Object.assign(e,{font:{bold:!0,color:{argb:P}},fill:{type:"pattern",pattern:"solid",fgColor:{argb:B}},border:A()})})}),n.addRows(X).forEach(function(e){w&&N(e,l),e.eachCell(function(e){var t=n.getColumn(e.col);R(e,r.getColumnById(t.key).align||f),w&&Object.assign(e,{font:{color:{argb:P}},border:A()})})}),m&&n.addRows(C).forEach(function(e){w&&N(e,l),e.eachCell(function(e){var t=n.getColumn(e.col),t=r.getColumnById(t.key),o=t.footerAlign,t=t.align;R(e,o||t||d||f),w&&Object.assign(e,{font:{color:{argb:P}},border:A()})})}),w&&E&&E({options:c,workbook:e,worksheet:n,columns:s,colgroups:t,datas:a,$table:r}),j.forEach(function(e){var t=e.s,e=e.e;n.mergeCells(t.r+1,t.c+1,e.r+1,e.c+1)}),e.xlsx.writeBuffer().then(function(e){var t,e=new Blob([e],{type:"application/octet-stream"}),o=c,n=(r=(r=i).$table.$vxe).modal,r=r.t,a=o.message,l=o.filename,o=o.type,a=!1!==a;window.Blob?navigator.msSaveBlob?navigator.msSaveBlob(e,"".concat(l,".").concat(o)):((t=document.createElement("a")).target="_blank",t.download="".concat(l,".").concat(o),t.href=URL.createObjectURL(e),document.body.appendChild(t),t.click(),document.body.removeChild(t)):a&&n&&n.alert({content:r("vxe.error.notExp"),status:"error"}),k&&p&&(p.close("xlsx"),p.message({content:g("vxe.table.expSuccess"),status:"success"}))})}var o,r=i.$table,c=i.options,s=i.columns,t=i.colgroups,a=i.datas,n=r.$vxe,l=r.rowHeight,u=r.headerAlign,f=r.align,d=r.footerAlign,p=n.modal,g=n.t,n=c.message,h=c.sheetName,b=c.isHeader,m=c.isFooter,y=c.isMerge,x=c.isColgroup,v=c.original,w=c.useStyle,E=c.sheetMethod,k=!1!==n,n=r.getMergeCells(),S=[],C=[],O=[],j=[],_=0,T={},X=(s.forEach(function(e){var t=e.id,o=e.property,n=e.renderWidth;T[t]=v?o:e.getTitle(),O.push({key:t,width:M.default.ceil(n/8,1)})}),b&&(x&&!v&&t?t.forEach(function(e,a){var l={};s.forEach(function(e){l[e.id]=null}),e.forEach(function(e){var t=e._colSpan,o=e._rowSpan,n=function e(t){var o=t.childNodes;return o&&o.length?e(o[0]):t}(e),r=s.indexOf(n);l[n.id]=v?n.property:e.getTitle(),(1<t||1<o)&&j.push({s:{r:a,c:r},e:{r:a+o-1,c:r+t-1}})}),S.push(l)}):S.push(T),_+=S.length),y&&!v&&n.forEach(function(e){var t=e.row,o=e.rowspan,n=e.col,e=e.colspan;j.push({s:{r:t+_,c:n},e:{r:t+_+o-1,c:n+e-1}})}),a.map(function(t){var o={};return s.forEach(function(e){o[e.id]=V(e,t[e.id])}),o}));_+=X.length,m&&(x=r.getTableData().footerData,n=x,x=(o=c.footerFilterMethod)?n.filter(function(e,t){return o({items:e,$rowIndex:t})}):n,n=r.getMergeFooterItems(),y&&!v&&n.forEach(function(e){var t=e.row,o=e.rowspan,n=e.col,e=e.colspan;j.push({s:{r:t+_,c:n},e:{r:t+_+o-1,c:n+e-1}})}),x.forEach(function(t){var o={};s.forEach(function(e){o[e.id]=V(e,t[r.getVMColumnIndex(e)])}),C.push(o)}));k&&p?(p.message({id:"xlsx",content:g("vxe.table.expLoading"),status:"loading",duration:-1}),setTimeout(e,1500)):e()}function d(e){var t=e.$table,e=e.options,o=t.$vxe,t=t._importReject,e=!1!==e.message,n=o.modal,o=o.t;e&&n&&n.message({content:o("vxe.error.impFields"),status:"error"}),t&&t({status:!1})}function r(a){var l=a.$table,o=a.columns,i=a.options,e=a.file,t=l.$vxe,c=l._importResolve,s=t.modal,u=t.t,f=!1!==i.message,t=new FileReader;t.onerror=function(){d(a)},t.onload=function(e){var r=[],t=(o.forEach(function(e){e=e.property;e&&r.push(e)}),new $.Workbook),e=e.target;e?t.xlsx.load(e.result).then(function(e){var t,n,o,e=e.worksheets[0];e&&(e=e.getSheetValues(),t=M.default.findIndexOf(e,function(e){return e&&0<e.length}),n=e[t],o=r,n.some(function(e){return-1<o.indexOf(e)}))?(e=e.slice(t).map(function(e){var o={},t=(e.forEach(function(e,t){o[n[t]]=e}),{});return r.forEach(function(e){t[e]=M.default.isUndefined(o[e])?null:o[e]}),t}),l.createData(e).then(function(e){e="insert"===i.mode?l.insertAt(e,-1):l.reloadData(e);return e.then(function(){c&&c({status:!0})})}),f&&s&&s.message({content:u("vxe.table.impSuccess",[e.length]),status:"success"})):d(a)}):d(a)},t.readAsArrayBuffer(e)}function a(e){if("xlsx"===e.options.type)return r(e),!1}function i(e){if("xlsx"===e.options.type)return n(e),!1}var c={install:function(e){var t=e.interceptor;e.setup({export:{types:{xlsx:0}}}),t.mixin({"event.import":a,"event.export":i})}};e.VXETablePluginExportXLSX=c,"undefined"!=typeof window&&window.VXETable&&window.VXETable.use&&window.VXETable.use(c);e.default=c});
|