javascript - "file format different from extension" when creating an xls file -
i trying create xlsx file, simple script:
myapp.factory('excel',function($window){ 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 {     tabletoexcel:function(worksheetname){         var table='ffgs',             ctx={worksheet:worksheetname,table:'<tr><td>test</td></tr><tr><td>this test</td></tr>'},             href=uri+base64(format(template,ctx));         return href;     } }; }); calling that:
$scope.genreport = function() {     var exporthref=excel.tabletoexcel('sheetname');     $timeout(function(){location.href=exporthref;},100);     } it works, anyway when opening on excel 2010 tells me file format different extension. confirming prompt opens anyways, don't want excel show me prompt.
i think problem in template variable...any ideas?
 
 
  
Comments
Post a Comment