no message
Former-commit-id: c75f3d068ebe0888902bef7150193764a7e26d9d Former-commit-id: 5b11f1da7c89e9dc39db63f3b518e36d1fcc8ae9 Former-commit-id: baf21a12c3f3ee08f4bdee2e7eb1916e7da78cb5
This commit is contained in:
@@ -62,15 +62,15 @@ const csv = {
|
|||||||
oWin.document.charset = 'utf-8';
|
oWin.document.charset = 'utf-8';
|
||||||
oWin.document.write(text);
|
oWin.document.write(text);
|
||||||
oWin.document.close();
|
oWin.document.close();
|
||||||
oWin.document.execCommand('SaveAs', filename);
|
oWin.document.execCommand('SaveAs', filename + '.csv');
|
||||||
oWin.close();
|
oWin.close();
|
||||||
} else if (has('ie') === 10 || this._isIE11() || this._isEdge()) {
|
} else if (has('ie') === 10 || this._isIE11() || this._isEdge()) {
|
||||||
const BOM = '\uFEFF';
|
const BOM = '\uFEFF';
|
||||||
const csvData = new Blob([BOM + text], { type: 'text/csv' });
|
const csvData = new Blob([BOM + text], { type: 'text/csv' });
|
||||||
navigator.msSaveBlob(csvData, filename);
|
navigator.msSaveBlob(csvData, filename + '.csv');
|
||||||
} else {
|
} else {
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.download = filename;
|
link.download = filename + '.csv';
|
||||||
link.href = this._getDownloadUrl(text);
|
link.href = this._getDownloadUrl(text);
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
|
|||||||
@@ -150,6 +150,6 @@ export function export_json_to_excel(th, jsonData, defaultTitle) {
|
|||||||
wb.Sheets[ws_name] = ws;
|
wb.Sheets[ws_name] = ws;
|
||||||
|
|
||||||
var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
|
var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
|
||||||
var title = defaultTitle || 'excel-list'
|
var title = defaultTitle || 'table'
|
||||||
FileSaver.saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), title + ".xlsx")
|
FileSaver.saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), title + ".xlsx")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export default {
|
|||||||
const paramsDefault = {
|
const paramsDefault = {
|
||||||
columns: [],
|
columns: [],
|
||||||
data: [],
|
data: [],
|
||||||
|
title: 'table',
|
||||||
noHeader: false
|
noHeader: false
|
||||||
}
|
}
|
||||||
// 合并参数
|
// 合并参数
|
||||||
@@ -19,7 +20,7 @@ export default {
|
|||||||
// 生成数据
|
// 生成数据
|
||||||
const data = Csv(_params.columns, _params.data, params, _params.noHeader)
|
const data = Csv(_params.columns, _params.data, params, _params.noHeader)
|
||||||
// 下载数据
|
// 下载数据
|
||||||
ExportCsv.download('table.csv', data)
|
ExportCsv.download(_params.title, data)
|
||||||
// 完成
|
// 完成
|
||||||
resolve(data)
|
resolve(data)
|
||||||
})
|
})
|
||||||
@@ -30,7 +31,8 @@ export default {
|
|||||||
// 默认值
|
// 默认值
|
||||||
const paramsDefault = {
|
const paramsDefault = {
|
||||||
columns: [],
|
columns: [],
|
||||||
data: []
|
data: [],
|
||||||
|
title: 'table'
|
||||||
}
|
}
|
||||||
// 合并参数
|
// 合并参数
|
||||||
const _params = Object.assign({}, paramsDefault, params)
|
const _params = Object.assign({}, paramsDefault, params)
|
||||||
@@ -38,7 +40,7 @@ export default {
|
|||||||
const header = _params.columns.map(e => e.label)
|
const header = _params.columns.map(e => e.label)
|
||||||
const data = _params.data.map(row => _params.columns.map(col => row[col.prop]))
|
const data = _params.data.map(row => _params.columns.map(col => row[col.prop]))
|
||||||
// 导出 Excel
|
// 导出 Excel
|
||||||
Excel.export_json_to_excel(header, data, 'demo')
|
Excel.export_json_to_excel(header, data, _params.title)
|
||||||
// 完成
|
// 完成
|
||||||
resolve({
|
resolve({
|
||||||
header,
|
header,
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ this.$export.csv({
|
|||||||
| --- | --- | --- | --- | --- | --- |
|
| --- | --- | --- | --- | --- | --- |
|
||||||
| columns | 列 | 非 | Array | | 空数组 |
|
| columns | 列 | 非 | Array | | 空数组 |
|
||||||
| data | 行数据 | 非 | Array | | 空数组 |
|
| data | 行数据 | 非 | Array | | 空数组 |
|
||||||
|
| table | 文件名 | 非 | String | | table |
|
||||||
| noHeader | 不导出表头 | 非 | Boolean | | false |
|
| noHeader | 不导出表头 | 非 | Boolean | | false |
|
||||||
| separator | 数据分隔符 | 非 | String | | , |
|
| separator | 数据分隔符 | 非 | String | | , |
|
||||||
| quoted | 每项数据是否加引号 | 非 | Boolean | | false |
|
| quoted | 每项数据是否加引号 | 非 | Boolean | | false |
|
||||||
@@ -88,6 +89,7 @@ this.$export.excel({
|
|||||||
| --- | --- | --- | --- | --- | --- |
|
| --- | --- | --- | --- | --- | --- |
|
||||||
| columns | 列 | 非 | Array | | 空数组 |
|
| columns | 列 | 非 | Array | | 空数组 |
|
||||||
| data | 行数据 | 非 | Array | | 空数组 |
|
| data | 行数据 | 非 | Array | | 空数组 |
|
||||||
|
| table | 文件名 | 非 | String | | table |
|
||||||
|
|
||||||
示例
|
示例
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user