javascript - Use js export excel, tens of thousands of data, what should I do? -
i've used following method, doesn't fit
export = (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><meta charset="utf-8"><!--[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}; // window.location.href = uri + base64(format(template, ctx)); document.getelementbyid("dlink").href = uri + base64(format(template, ctx)); document.getelementbyid("dlink").download = "finame"; document.getelementbyid("dlink").click(); }; })();
you might want create file on server , serve via ajax call or websocket.
the main problem client has parse data, , might quite slow/heavy depending on client.
also remember if table paginated need select every page manually parse table 1 big result set.
as of row limitations, according excel's specifications, excel 2007 , upwards should have 1,048,576 rows per workbook.
Comments
Post a Comment