html - Export data to specific location javascript -
i want export table html excel file using function
var tabletoexcel = (function () { var uri = 'data:application/vnd.ms-excel;base64,'; var 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>'; var base64 = function (s) { return window.btoa(unescape(encodeuricomponent(s))) } var format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) } return function (table, name) { if (!table.nodetype) table = document.getelementbyid(table) var ctx = { worksheet: name || 'worksheet', table: table.innerhtml } var url = uri + base64(format(template, ctx)); window.location.href = url; } })() the default filename seems download.xls, can set different 1 using function wrapps download (i adjusted first function, returns url instead of opening in browser).
function download(table, name) { var link = document.createelement('a'); link.download = "lol.xls"; link.href = tabletoexcel(table, name); link.click(); } however downloads immidiatly when calling function (e.g. clicking on button). i'd click on button - chose filename , more important location - , download excel-file.
is there way change download location? there way download prompt (name + location)?
regards
as pointed out in question already: user specified download location
it not possible force 'save as' dialog, user has specify in browser-options, if wants chose download location or if default 1 should used
Comments
Post a Comment