From 3266dd4a2f73e7b213e716fc5b7d002e2db98e0f Mon Sep 17 00:00:00 2001 From: tensent Date: Sat, 9 May 2020 12:21:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/static/common/js/require-xlsx.js | 59 + public/static/plugins/sheetjs/cpexcel.js | 1505 + public/static/plugins/sheetjs/jszip.js | 8999 +++++ public/static/plugins/sheetjs/shim.min.js | 2 + .../static/plugins/sheetjs/xlsx.core.min.js | 17 + .../plugins/sheetjs/xlsx.extendscript.js | 30544 ++++++++++++++++ .../static/plugins/sheetjs/xlsx.full.min.js | 23 + public/static/plugins/sheetjs/xlsx.js | 21388 +++++++++++ public/static/plugins/sheetjs/xlsx.min.js | 14 + .../static/plugins/sheetjs/xlsx.mini.min.js | 7 + runtime/sql/install.sql | 3 +- 11 files changed, 62560 insertions(+), 1 deletion(-) create mode 100644 public/static/common/js/require-xlsx.js create mode 100644 public/static/plugins/sheetjs/cpexcel.js create mode 100644 public/static/plugins/sheetjs/jszip.js create mode 100644 public/static/plugins/sheetjs/shim.min.js create mode 100644 public/static/plugins/sheetjs/xlsx.core.min.js create mode 100644 public/static/plugins/sheetjs/xlsx.extendscript.js create mode 100644 public/static/plugins/sheetjs/xlsx.full.min.js create mode 100644 public/static/plugins/sheetjs/xlsx.js create mode 100644 public/static/plugins/sheetjs/xlsx.min.js create mode 100644 public/static/plugins/sheetjs/xlsx.mini.min.js diff --git a/public/static/common/js/require-xlsx.js b/public/static/common/js/require-xlsx.js new file mode 100644 index 00000000..abfaec1e --- /dev/null +++ b/public/static/common/js/require-xlsx.js @@ -0,0 +1,59 @@ +require(['jquery', 'sheetjs'], function($, XLSX) { + + // var wopts = { bookType: 'csv', bookSST: false, type: 'binary' };//ods格式 + var wopts = { bookType: 'xlsx', bookSST: false, type: 'binary' };//这里的数据是用来定义导出的格式类型 + // var wopts = { bookType: 'ods', bookSST: false, type: 'binary' };//ods格式 + // var wopts = { bookType: 'xlsb', bookSST: false, type: 'binary' };//xlsb格式 + // var wopts = { bookType: 'fods', bookSST: false, type: 'binary' };//fods格式 + // var wopts = { bookType: 'biff2', bookSST: false, type: 'binary' };//xls格式 + + var xls = { + downloadExl: function (data, fileName) { + checkFileIn(); + var wb = { SheetNames: ['Sheet1'], Sheets: {}, Props: {} }; + wb.Sheets['Sheet1'] = XLSX.utils.json_to_sheet(data);//通过json_to_sheet转成单页(Sheet)数据 + this.saveAs(new Blob([this.s2ab(XLSX.write(wb, wopts))], { type: "application/octet-stream" }), fileName + '.' + (wopts.bookType=="biff2"?"xls":wopts.bookType)); + }, + + //如果使用 FileSaver.js 就不要同时使用以下函数 + saveAs: function(obj, fileName) { + //当然可以自定义简单的下载文件实现方式 + var tmpa = document.createElement("a"); + tmpa.download = fileName || "下载"; + //绑定a标签 + tmpa.href = URL.createObjectURL(obj); + tmpa.click(); //模拟点击实现下载 + setTimeout(function () { //延时释放 + URL.revokeObjectURL(obj); //用URL.revokeObjectURL()来释放这个object URL + }, 100); + }, + + s2ab: function(s) { + if (typeof ArrayBuffer !== 'undefined') { + var buf = new ArrayBuffer(s.length); + var view = new Uint8Array(buf); + for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; + return buf; + } else { + var buf = new Array(s.length); + for (var i = 0; i != s.length; ++i) buf[i] = s.charCodeAt(i) & 0xFF; + return buf; + } + } + }; + + checkFileIn = function(){ + if($("script[src='/static/js/js-xlsx/xlsx.full.min.js']").length > 0){ + return; + }else{ + var body = $("body"); + var script = $("