diff --git a/src/stable/js/tableexport.js b/src/stable/js/tableexport.js index bebcae2..5b6bd07 100644 --- a/src/stable/js/tableexport.js +++ b/src/stable/js/tableexport.js @@ -502,9 +502,12 @@ data = this.string2ArrayBuffer(wbout); } - saveAs(new Blob([data], - {type: mime + ";" + this.charset}), - name + extension, true); + var blob = new Blob([data], {type: mime + ";" + this.charset}); + if (navigator.appVersion.toString().indexOf('.NET') > 0) { + window.navigator.msSaveOrOpenBlob(blob, name + extension); + } else { + saveAs(blob, name + extension, true); + } }, /** * Updates the plugin instance with new/updated options @@ -549,4 +552,4 @@ return exports.default = exports.TableExport = TableExport; } -)); \ No newline at end of file +)); diff --git a/src/stable/js/tableexport.min.js b/src/stable/js/tableexport.min.js index 69c30af..29f4585 100644 --- a/src/stable/js/tableexport.min.js +++ b/src/stable/js/tableexport.min.js @@ -3,4 +3,4 @@ * Copyright 2016 Travis Clarke * Licensed under the MIT license */ -!function(t,e){"function"==typeof define&&define.amd?define(["exports","jquery","blobjs","file-saverjs","xlsx-js"],e):"object"==typeof exports&&"string"!=typeof exports.nodeName?e(exports,require("jquery"),require("blobjs"),require("file-saverjs"),require("xlsx-js")):e(t,t.jQuery,t.Blob,t.saveAs,t.XLSX)}(this||window,function(t,e,n,o,i){"use strict";var r=function(t,n,o){var s=this;s.settings=o?n:e.extend({},r.prototype.defaults,n),s.selectors=t;var a,p,f,l=r.prototype.rowDel,u=s.settings.ignoreRows instanceof Array?s.settings.ignoreRows:[s.settings.ignoreRows],c=s.settings.ignoreCols instanceof Array?s.settings.ignoreCols:[s.settings.ignoreCols],x=s.settings.ignoreCSS instanceof Array?s.settings.ignoreCSS.join(", "):s.settings.ignoreCSS,y=s.settings.emptyCSS instanceof Array?s.settings.emptyCSS.join(", "):s.settings.emptyCSS;return s.settings.bootstrap?(a=r.prototype.bootstrap[0]+" ",p=r.prototype.bootstrap[1]+" ",f=r.prototype.bootstrap[2]+" "):(a=r.prototype.defaultButton+" ",p=f=""),s.selectors.each(function(){function t(t){return s.settings.trimWhitespace?t.trim():t}function n(t){var e=m.find("caption:not(.head)");e.length?e.append(t):m.prepend(''+t+"")}function d(t,e,o){var i="";n(i)}var m=e(this);o&&m.find("caption:not(.head)").remove();var g=m.find("tbody").find("tr"),g=s.settings.headings?g.add(m.find("thead>tr")):g,g=s.settings.footers?g.add(m.find("tfoot>tr")):g,b=s.settings.headings?m.find("thead>tr").length:0,h="id"===s.settings.fileName?m.attr("id")?m.attr("id"):r.prototype.defaultFileName:s.settings.fileName,v={xlsx:function(n,o){var i={},s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return[r.map(function(o,r){if(!~c.indexOf(o)&&!e(r).is(x)){if(e(r).is(y))return" ";if(r.hasAttribute("colspan")&&(i[n]=i[n]||{},i[n][o+1]=r.getAttribute("colspan")-1),r.hasAttribute("rowspan"))for(var s=1;s=o?p+i[n][s]:p:f++,f!==a);s++);return new Array(p).concat(e(r).text())}return t(e(r).text())}}).get()]}}).get(),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xlsx.mimeType,fileExtension:r.prototype.xlsx.fileExtension})),p=r.prototype.xlsx.buttonContent,f=r.prototype.xlsx.defaultClass;d(a,p,f)},xlsm:function(n,o){var i={},s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return[r.map(function(o,r){if(!~c.indexOf(o)&&!e(r).is(x)){if(e(r).is(y))return" ";if(r.hasAttribute("colspan")&&(i[n]=i[n]||{},i[n][o+1]=r.getAttribute("colspan")-1),r.hasAttribute("rowspan"))for(var s=1;s=o?p+i[n][s]:p:f++,f!==a);s++);return new Array(p).concat(e(r).text())}return t(e(r).text())}}).get()]}}).get(),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xls.mimeType,fileExtension:r.prototype.xls.fileExtension})),p=r.prototype.xls.buttonContent,f=r.prototype.xls.defaultClass;d(a,p,f)},xls:function(n,o){var i=r.prototype.xls.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(y)?" ":t(e(o).text())}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xls.mimeType,fileExtension:r.prototype.xls.fileExtension})),p=r.prototype.xls.buttonContent,f=r.prototype.xls.defaultClass;d(a,p,f)},csv:function(n,o){var i=r.prototype.csv.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(y)?" ":'"'+t(e(o).text().replace(/"/g,'""'))+'"'}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.csv.mimeType,fileExtension:r.prototype.csv.fileExtension})),p=r.prototype.csv.buttonContent,f=r.prototype.csv.defaultClass;d(a,p,f)},txt:function(n,o){var i=r.prototype.txt.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(y)?" ":t(e(o).text())}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.txt.mimeType,fileExtension:r.prototype.txt.fileExtension})),p=r.prototype.txt.buttonContent,f=r.prototype.txt.defaultClass;d(a,p,f)}};s.settings.formats.forEach(function(t){!(!i||"xls"!==t)&&(t="xlsm"),!i&&"xlsx"===t&&(t=null),t&&v[t](l,h)})}),e("button[data-fileblob]").off("click").on("click",function(){var t=e(this).data("fileblob"),n=t.data,o=t.fileName,i=t.mimeType,s=t.fileExtension;r.prototype.export2file(n,i,o,s)}),s};r.prototype={version:"3.3.9",defaults:{headings:!0,footers:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null,ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty",trimWhitespace:!1},charset:"charset=utf-8",defaultFileName:"myDownload",defaultButton:"button-default",bootstrap:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return r.prototype.entityMap[t]})},dateNum:function(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},n={s:{c:1e7,r:1e7},e:{c:0,r:0}},o=0;o!=t.length;++o)for(var r=0;r!=t[o].length;++r){n.s.r>o&&(n.s.r=o),n.s.c>r&&(n.s.c=r),n.e.r'+b+"")}function u(a,b,c){var d="";t(d)}var a=b(this);d&&a.find("caption:not(.head)").remove();var c=a.find("tbody").find("tr"),c=g.settings.headings?c.add(a.find("thead>tr")):c,c=g.settings.footers?c.add(a.find("tfoot>tr")):c,p=g.settings.headings?a.find("thead>tr").length:0,q="id"===g.settings.fileName?a.attr("id")?a.attr("id"):f.prototype.defaultFileName:g.settings.fileName,r={xlsx:function(a,d){var e={},g=c.map(function(a,c){if(!~i.indexOf(a-p)&&!b(c).is(k)){var d=b(c).find("th, td");return[d.map(function(c,d){if(!~j.indexOf(c)&&!b(d).is(k)){if(b(d).is(l))return" ";if(d.hasAttribute("colspan")&&(e[a]=e[a]||{},e[a][c+1]=d.getAttribute("colspan")-1),d.hasAttribute("rowspan"))for(var f=1;f=c?h+e[a][f]:h:i++,i!==g);f++);return new Array(h).concat(b(d).text())}return s(b(d).text())}}).get()]}}).get(),h=f.prototype.escapeHtml(JSON.stringify({data:g,fileName:d,mimeType:f.prototype.xlsx.mimeType,fileExtension:f.prototype.xlsx.fileExtension})),m=f.prototype.xlsx.buttonContent,n=f.prototype.xlsx.defaultClass;u(h,m,n)},xlsm:function(a,d){var e={},g=c.map(function(a,c){if(!~i.indexOf(a-p)&&!b(c).is(k)){var d=b(c).find("th, td");return[d.map(function(c,d){if(!~j.indexOf(c)&&!b(d).is(k)){if(b(d).is(l))return" ";if(d.hasAttribute("colspan")&&(e[a]=e[a]||{},e[a][c+1]=d.getAttribute("colspan")-1),d.hasAttribute("rowspan"))for(var f=1;f=c?h+e[a][f]:h:i++,i!==g);f++);return new Array(h).concat(b(d).text())}return s(b(d).text())}}).get()]}}).get(),h=f.prototype.escapeHtml(JSON.stringify({data:g,fileName:d,mimeType:f.prototype.xls.mimeType,fileExtension:f.prototype.xls.fileExtension})),m=f.prototype.xls.buttonContent,n=f.prototype.xls.defaultClass;u(h,m,n)},xls:function(a,d){var e=f.prototype.xls.separator,g=c.map(function(a,c){if(!~i.indexOf(a-p)&&!b(c).is(k)){var d=b(c).find("th, td");return d.map(function(a,c){if(!~j.indexOf(a)&&!b(c).is(k))return b(c).is(l)?" ":s(b(c).text())}).get().join(e)}}).get().join(a),h=f.prototype.escapeHtml(JSON.stringify({data:g,fileName:d,mimeType:f.prototype.xls.mimeType,fileExtension:f.prototype.xls.fileExtension})),m=f.prototype.xls.buttonContent,n=f.prototype.xls.defaultClass;u(h,m,n)},csv:function(a,d){var e=f.prototype.csv.separator,g=c.map(function(a,c){if(!~i.indexOf(a-p)&&!b(c).is(k)){var d=b(c).find("th, td");return d.map(function(a,c){if(!~j.indexOf(a)&&!b(c).is(k))return b(c).is(l)?" ":'"'+s(b(c).text().replace(/"/g,'""'))+'"'}).get().join(e)}}).get().join(a),h=f.prototype.escapeHtml(JSON.stringify({data:g,fileName:d,mimeType:f.prototype.csv.mimeType,fileExtension:f.prototype.csv.fileExtension})),m=f.prototype.csv.buttonContent,n=f.prototype.csv.defaultClass;u(h,m,n)},txt:function(a,d){var e=f.prototype.txt.separator,g=c.map(function(a,c){if(!~i.indexOf(a-p)&&!b(c).is(k)){var d=b(c).find("th, td");return d.map(function(a,c){if(!~j.indexOf(a)&&!b(c).is(k))return b(c).is(l)?" ":s(b(c).text())}).get().join(e)}}).get().join(a),h=f.prototype.escapeHtml(JSON.stringify({data:g,fileName:d,mimeType:f.prototype.txt.mimeType,fileExtension:f.prototype.txt.fileExtension})),m=f.prototype.txt.buttonContent,n=f.prototype.txt.defaultClass;u(h,m,n)}};g.settings.formats.forEach(function(a){!(!e||"xls"!==a)&&(a="xlsm"),!e&&"xlsx"===a&&(a=null),a&&r[a](h,q)})}),b("button[data-fileblob]").off("click").on("click",function(){var a=b(this).data("fileblob"),c=a.data,d=a.fileName,e=a.mimeType,g=a.fileExtension;f.prototype.export2file(c,e,d,g)}),g};f.prototype={version:"3.3.9",defaults:{headings:!0,footers:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null,ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty",trimWhitespace:!1},charset:"charset=utf-8",defaultFileName:"myDownload",defaultButton:"button-default",bootstrap:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},escapeHtml:function(a){return String(a).replace(/[&<>'\/]/g,function(a){return f.prototype.entityMap[a]})},dateNum:function(a,b){b&&(a+=1462);var c=Date.parse(a);return(c-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(a){for(var b={},c={s:{c:1e7,r:1e7},e:{c:0,r:0}},d=0;d!=a.length;++d)for(var f=0;f!=a[d].length;++f){c.s.r>d&&(c.s.r=d),c.s.c>f&&(c.s.c=f),c.e.r0?window.navigator.msSaveOrOpenBlob(l,f+g):d(l,f+g,!0)},update:function(a){return new f(this.selectors,b.extend({},this.settings,a),!0)},reset:function(){return new f(this.selectors,this.settings,!0)},remove:function(){this.selectors.each(function(){b(this).find("caption:not(.head)").remove()})}},b.fn.tableExport=function(a,b){return new f(this,a,b)};for(var g in f.prototype)b.fn.tableExport[g]=f.prototype[g];return a.default=a.TableExport=f}); \ No newline at end of file