excel - Javascript - Download XLSX Content from Servlet -
i have servlet url provides content in "application/vnd.ms-excel" format on clicking export button.here doubt is, getting content servr in "application/vnd.ms-excel" format, how map server response workbook template?
referred below stackoveflow link explains download html table xlsx file.
html table xlsx:-
var tabletoexcel = (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.getelementbyid(table) var ctx = { worksheet: name || 'worksheet', table: table.innerhtml } document.getelementbyid("dlink").href = uri + base64(format(template, ctx)); document.getelementbyid("dlink").download = filename; document.getelementbyid("dlink").click(); } })()
i hope question clear, in advance.
" how map server response workbook template"
you don't browser you. depending on browser , it's configuration download file or show pop asking if needs saved or opened.
look @ extjs 4 downloading file through ajax call
you need set
standardsubmit: true
something this:
var form = ext.create('ext.form.panel', { // wolud form standardsubmit: true, // important part url: '../generatefileservlet' }); form.submit({ params: { filename: myfile } });
notice doing form submit , not ajax request.
Comments
Post a Comment