导出到excel后无法设置文件名 [英] Unable to set the filename after export to excel

查看:275
本文介绍了导出到excel后无法设置文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,



我使用以下jquery导出到excel ..



但无法设置文件名...





I am using following jquery to export to excel..

But unable to set the filename...

<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><tr> <td> 
Name </td> <td> ID </td> <td> ..........................
................
</body></html>





来自以下jquery ..





from following jquery..

var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:"+defaults.type+"' xmlns='http://www.w3.org/TR/REC-html40'>";
excelFile += "<head>";
excelFile += "<!--[if gte mso 9]>";
excelFile += "<xml>";
excelFile += "<x:ExcelWorkbook>";
excelFile += "<x:ExcelWorksheets>";
excelFile += "<x:ExcelWorksheet>";
excelFile += "<x:Name>";
excelFile += "{worksheet}";
excelFile += "</x:Name>";
excelFile += "<x:WorksheetOptions>";
excelFile += "<x:DisplayGridlines/>";
excelFile += "</x:WorksheetOptions>";
excelFile += "</x:ExcelWorksheet>";
excelFile += "</x:ExcelWorksheets>";
excelFile += "</x:ExcelWorkbook>";
excelFile += "</xml>";
excelFile += "<![endif]-->";
excelFile += "</head>";
excelFile += "<body>";
excelFile += excel;
excelFile += "</body>";
excelFile += "</html>";

var base64data = "base64," + $.base64.encode(excelFile);
//alert('here');
window.open('data:application/vnd.ms-'+defaults.type+';filename=exportData.excel;' + base64data);

推荐答案

.base64.encode(excelFile);
// alert('here');
window.open('data:application / vnd.ms - '+ defaults.type +'; filename = exportData.excel;'+ base64data);
.base64.encode(excelFile); //alert('here'); window.open('data:application/vnd.ms-'+defaults.type+';filename=exportData.excel;' + base64data);






当你修改你的文件名属性时会发生什么最后一行:



Hi,

What happens when you modify the filename attribute on your last line to:

window.open('data:application/vnd.ms-'+defaults.type+';filename=exportData.xlsx;' + base64data);





希望有帮助



Hope it helps


看看此URL用于解决您的问题:



链接: http://stackoverflow.com/questions/24504828/downloading-file-custom-name-with-jquery [ ^ ]
have a look at this URL for solution to your question:

Link: http://stackoverflow.com/questions/24504828/downloading-file-custom-name-with-jquery[^]


这篇关于导出到excel后无法设置文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆