django-vue3-admin-web/node_modules/js-table2excel/dist/index.js
2025-10-20 21:21:14 +08:00

7 lines
3.1 KiB
JavaScript

/*!
* js-table2excel v1.1.2
* Released under the MIT License.
* repository: https://github.com/hxj9102/table2excel.git
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Table2Excel=t()}(this,(function(){"use strict";var e=function(e,o){var i;"ie"==((i=window.navigator.userAgent).indexOf("MSIE")>=0?"ie":i.indexOf("Firefox")>=0?"Firefox":i.indexOf("Chrome")>=0?"Chrome":i.indexOf("Opera")>=0?"Opera":i.indexOf("Safari")>=0?"Safari":void 0)?t(e):n(e,o)},t=function(e,t){var n=e,o=new ActiveXObject("Excel.Application"),i=o.Workbooks.Add(),c=i.Worksheets(1),a=document.body.createTextRange();a.moveToElementText(n),a.select,a.execCommand("Copy"),c.Paste(),o.Visible=!0;try{o.Application.GetSaveAsFilename("Excel.xls","Excel Spreadsheets (*.xls), *.xls")}catch(e){print("Nested catch caught "+e)}finally{i.SaveAs(fname),i.Close(savechanges=!1),o.Quit(),o=null,window.setInterval("Cleanup();",1),window.setInterval("Cleanup();",1)}},n=function(e,t){var n,o="data:application/vnd.ms-excel;base64,"+function(e){return window.btoa(unescape(encodeURIComponent(e)))}((n={worksheet:t,table:e},'<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta charset="UTF-8">\x3c!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--\x3e</head><body><table>{table}</table></body></html>'.replace(/{(\w+)}/g,(function(e,t){return n[t]}))));if(navigator.userAgent.indexOf("Firefox")>-1)window.location.href=o;else{var i,c=document.createElement("a");c.href=o,c.download=t||"",window.MouseEvent?i=new MouseEvent("click"):(i=document.createEvent("MouseEvents")).initMouseEvent("click",!0,!1,window,0,0,0,0,0,!1,!1,!1,!1,0,null),c.dispatchEvent(i)}};return function(){for(var t={image:function(e,t){return t=Object.assign({width:40,height:60},t),'<td style="width: '.concat(t.width,"px; height: ").concat(t.height,'px; text-align: center; vertical-align: middle"><img src="').concat(e,'" width=').concat(.99*t.width," height=").concat(.99*t.height," /></td>")},text:function(e){return'<td style="text-align: center">'.concat(e,"</td>")}},n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];var c=function(e){return 1===e.length?e[0]:{column:e[0]||[],data:e[1]||[],excelName:e[2]||"",captionName:e[3]}}(o),a=c.column,r=c.data,l=c.excelName,s=c.captionName,d=s?'<caption style="font-weight:bold">'.concat(s,"</caption>"):"",h=a.reduce((function(e,t){return e+="<th>".concat(t.title,"</th>")}),"");h="<thead><tr>".concat(h,"</tr></thead>");var x=r.reduce((function(e,n){var o=a.reduce((function(e,o){var i={};return"image"===o.type&&(n.size?(i.width=n.size[0],i.height=n.size[1]):(o.width&&(i.width=o.width),o.height&&(i.height=o.height))),e+=t[o.type||"text"](n[o.key],i)}),"");return e+="<tr>".concat(o,"</tr>")}),"");x="<tbody>".concat(x,"</tbody>"),e(d+h+x,l)}}));