Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

I am using following jquery to export to excel..

But unable to set the filename...

HTML
<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>


from following jquery..

HTML
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);
Posted

Hi,

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

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


Hope it helps
 
Share this answer
 
Comments
PRAKASH_N 20-Jun-14 4:03am    
No...it is exporting it as download.xls(in chrome)..
It became browser dependent.. In mozialla it will generate a 16digit has code as a filename.... In IE,it will ask for the folder location to rename and save the file.....
have a look at this URL for solution to your question:

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900