1
0
mirror of synced 2025-12-09 14:59:35 +08:00
This commit is contained in:
xuliangzhan
2020-04-07 15:29:09 +08:00
parent 424686202e
commit 7ec98e9f4f
6 changed files with 8 additions and 9 deletions

View File

@@ -18,6 +18,7 @@ npm install xe-utils vxe-table vxe-table-plugin-export-xlsx xlsx
import Vue from 'vue'
import VXETable from 'vxe-table'
import VXETablePluginExportXLSX from 'vxe-table-plugin-export-xlsx'
import 'vxe-table/lib/index.css'
Vue.use(VXETable)
VXETable.use(VXETablePluginExportXLSX)

File diff suppressed because one or more lines are too long

3
dist/index.js vendored
View File

@@ -50,7 +50,6 @@
columns = params.columns,
datas = params.datas;
var sheetName = options.sheetName,
type = options.type,
isHeader = options.isHeader,
isFooter = options.isFooter,
original = options.original,
@@ -90,7 +89,7 @@
_xlsx["default"].utils.book_append_sheet(book, sheet, sheetName);
var wbout = _xlsx["default"].write(book, {
bookType: type,
bookType: 'xlsx',
bookSST: false,
type: 'binary'
});

2
dist/index.min.js vendored
View File

@@ -1 +1 @@
!function(e,t){if("function"==typeof define&&define.amd)define("vxe-table-plugin-export-xlsx",["exports","xe-utils","xlsx"],t);else if("undefined"!=typeof exports)t(exports,require("xe-utils"),require("xlsx"));else{var o={exports:{}};t(o.exports,e.XEUtils,e.XLSX),e.VXETablePluginExportXLSX=o.exports.default}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(e,h,y){"use strict";function t(e){return e&&e.__esModule?e:{default:e}}var w;function o(e){var i=e.$table,t=e.options,o=e.columns,n=e.datas,a=t.sheetName,r=t.type,s=t.isHeader,l=t.isFooter,u=t.original,f=t.message,c=t.footerFilterMethod,d={},p=[],v=n;if(s&&o.forEach(function(e){d[e.id]=h.default.toString(u?e.property:e.getTitle())}),l){var m=i.getTableData().footerData;(c?m.filter(c):m).forEach(function(a){var r={};o.forEach(function(e){var t,o,n;r[e.id]=(t=i,o=a,n=e,h.default.toString(o[t.$getColumnIndex(n)]))}),p.push(r)})}var x=y.default.utils.book_new(),g=y.default.utils.json_to_sheet((s?[d]:[]).concat(v).concat(p),{skipHeader:!0});y.default.utils.book_append_sheet(x,g,a);var b=y.default.write(x,{bookType:r,bookSST:!1,type:"binary"});!function(e,t){if(window.Blob){var o=t.filename,n=t.type;if(navigator.msSaveBlob)navigator.msSaveBlob(e,"".concat(o,".").concat(n));else{var a=document.createElement("a");a.target="_blank",a.download="".concat(o,".").concat(n),a.href=URL.createObjectURL(e),document.body.appendChild(a),a.click(),document.body.removeChild(a)}}else console.error(w.t("vxe.error.notExp"))}(new Blob([function(e){for(var t=new ArrayBuffer(e.length),o=new Uint8Array(t),n=0;n!==e.length;++n)o[n]=255&e.charCodeAt(n);return t}(b)],{type:"application/octet-stream"}),t),!1!==f&&w.modal.message({message:w.t("vxe.table.expSuccess"),status:"success"})}function d(e){return e.replace(/^"/,"").replace(/"$/,"")}function n(e){var l=e.columns,u=e.options,t=e.file,f=e.$table,c=f._importResolve,o=new FileReader;o.onload=function(e){var t,o,n=y.default.read(e.target.result,{type:"binary"}),a=function(e){var t=e.split("\n"),n=[],a=[];if(t.length){var o=t.slice(1);t[0].split(",").map(d),o.forEach(function(e){if(e){var o={};e.split(",").forEach(function(e,t){n[t]&&(o[n[t]]=d(e))}),a.push(o)}})}return{fields:n,rows:a}}(y.default.utils.sheet_to_csv(n.Sheets.Sheet1)),r=a.fields,i=a.rows,s=(t=r,o=[],l.forEach(function(e){var t=e.property;t&&o.push(t)}),o.every(function(e){return t.includes(e)}));s?(f.createData(i).then(function(e){"append"===u.mode?f.insertAt(e,-1):f.reloadData(e)}),!1!==u.message&&w.modal.message({message:h.default.template(w.t("vxe.table.impSuccess"),[i.length]),status:"success"})):!1!==u.message&&w.modal.message({message:w.t("vxe.error.impFields"),status:"error"}),c&&(c(s),f._importResolve=null)},o.readAsBinaryString(t)}function a(e){if("xlsx"===e.options.type)return n(e),!1}function r(e){if("xlsx"===e.options.type)return o(e),!1}Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.VXETablePluginExportXLSX=void 0,h=t(h),y=t(y);var i={install:function(e){var t=e.interceptor;w=e,Object.assign(e.types,{xlsx:1}),t.mixin({"event.import":a,"event.export":r})}};e.VXETablePluginExportXLSX=i,"undefined"!=typeof window&&window.VXETable&&window.VXETable.use(i);var s=i;e.default=s});
!function(e,t){if("function"==typeof define&&define.amd)define("vxe-table-plugin-export-xlsx",["exports","xe-utils","xlsx"],t);else if("undefined"!=typeof exports)t(exports,require("xe-utils"),require("xlsx"));else{var o={exports:{}};t(o.exports,e.XEUtils,e.XLSX),e.VXETablePluginExportXLSX=o.exports.default}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(e,b,h){"use strict";function t(e){return e&&e.__esModule?e:{default:e}}var y;function o(e){var i=e.$table,t=e.options,o=e.columns,n=e.datas,a=t.sheetName,r=t.isHeader,s=t.isFooter,l=t.original,u=t.message,f=t.footerFilterMethod,c={},d=[],p=n;if(r&&o.forEach(function(e){c[e.id]=b.default.toString(l?e.property:e.getTitle())}),s){var v=i.getTableData().footerData;(f?v.filter(f):v).forEach(function(a){var r={};o.forEach(function(e){var t,o,n;r[e.id]=(t=i,o=a,n=e,b.default.toString(o[t.$getColumnIndex(n)]))}),d.push(r)})}var x=h.default.utils.book_new(),m=h.default.utils.json_to_sheet((r?[c]:[]).concat(p).concat(d),{skipHeader:!0});h.default.utils.book_append_sheet(x,m,a);var g=h.default.write(x,{bookType:"xlsx",bookSST:!1,type:"binary"});!function(e,t){if(window.Blob){var o=t.filename,n=t.type;if(navigator.msSaveBlob)navigator.msSaveBlob(e,"".concat(o,".").concat(n));else{var a=document.createElement("a");a.target="_blank",a.download="".concat(o,".").concat(n),a.href=URL.createObjectURL(e),document.body.appendChild(a),a.click(),document.body.removeChild(a)}}else console.error(y.t("vxe.error.notExp"))}(new Blob([function(e){for(var t=new ArrayBuffer(e.length),o=new Uint8Array(t),n=0;n!==e.length;++n)o[n]=255&e.charCodeAt(n);return t}(g)],{type:"application/octet-stream"}),t),!1!==u&&y.modal.message({message:y.t("vxe.table.expSuccess"),status:"success"})}function d(e){return e.replace(/^"/,"").replace(/"$/,"")}function n(e){var l=e.columns,u=e.options,t=e.file,f=e.$table,c=f._importResolve,o=new FileReader;o.onload=function(e){var t,o,n=h.default.read(e.target.result,{type:"binary"}),a=function(e){var t=e.split("\n"),n=[],a=[];if(t.length){var o=t.slice(1);t[0].split(",").map(d),o.forEach(function(e){if(e){var o={};e.split(",").forEach(function(e,t){n[t]&&(o[n[t]]=d(e))}),a.push(o)}})}return{fields:n,rows:a}}(h.default.utils.sheet_to_csv(n.Sheets.Sheet1)),r=a.fields,i=a.rows,s=(t=r,o=[],l.forEach(function(e){var t=e.property;t&&o.push(t)}),o.every(function(e){return t.includes(e)}));s?(f.createData(i).then(function(e){"append"===u.mode?f.insertAt(e,-1):f.reloadData(e)}),!1!==u.message&&y.modal.message({message:b.default.template(y.t("vxe.table.impSuccess"),[i.length]),status:"success"})):!1!==u.message&&y.modal.message({message:y.t("vxe.error.impFields"),status:"error"}),c&&(c(s),f._importResolve=null)},o.readAsBinaryString(t)}function a(e){if("xlsx"===e.options.type)return n(e),!1}function r(e){if("xlsx"===e.options.type)return o(e),!1}Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.VXETablePluginExportXLSX=void 0,b=t(b),h=t(h);var i={install:function(e){var t=e.interceptor;y=e,Object.assign(e.types,{xlsx:1}),t.mixin({"event.import":a,"event.export":r})}};e.VXETablePluginExportXLSX=i,"undefined"!=typeof window&&window.VXETable&&window.VXETable.use(i);var s=i;e.default=s});

View File

@@ -27,7 +27,7 @@ function toBuffer (wbout: any) {
function exportXLSX (params: InterceptorExportParams) {
const { $table, options, columns, datas } = params
const { sheetName, type, isHeader, isFooter, original, message, footerFilterMethod } = options
const { sheetName, isHeader, isFooter, original, message, footerFilterMethod } = options
const colHead: { [key: string]: any } = {}
const footList: { [key: string]: any }[] = []
const rowList = datas
@@ -51,7 +51,7 @@ function exportXLSX (params: InterceptorExportParams) {
const sheet = XLSX.utils.json_to_sheet((isHeader ? [colHead] : []).concat(rowList).concat(footList), { skipHeader: true })
// 转换数据
XLSX.utils.book_append_sheet(book, sheet, sheetName)
const wbout = XLSX.write(book, { bookType: type, bookSST: false, type: 'binary' })
const wbout = XLSX.write(book, { bookType: 'xlsx', bookSST: false, type: 'binary' })
const blob = new Blob([toBuffer(wbout)], { type: 'application/octet-stream' })
// 保存导出
downloadFile(blob, options)

View File

@@ -1,6 +1,6 @@
{
"name": "vxe-table-plugin-export-xlsx",
"version": "1.3.3",
"version": "1.3.4",
"description": "基于 vxe-table 表格的增强插件,支持导出 xlsx 格式",
"scripts": {
"lib": "gulp build"