Skip to content

Instantly share code, notes, and snippets.

@Efreak
Created May 19, 2016 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Efreak/45f66ae10425dca896972e3feca6398b to your computer and use it in GitHub Desktop.
Save Efreak/45f66ae10425dca896972e3feca6398b to your computer and use it in GitHub Desktop.
var table = jQuery(".account_table").length ? "account_table" : "wallet_history_table"
jQuery('.wht_total > .wth_payment').remove()
c=jQuery('td');for(i=0;i<c.length;i++){c[i].innerHTML=c[i].innerText}
((function () {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<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><!--[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]--></head><body><table>{table}</table></body></html>'
, base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
return function (table, name, filename) {
if (!table.nodeType) table = document.querySelector(table)
var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
var dlink = document.createElement('a'); dlink.href = uri + base64(format(template, ctx));
dlink.download = filename;
dlink.click();
}
})())("."+table, table, table+'.xls')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment