1

Im exporting a html table to excel and its works fine, but I want the user to be able to choose name for the file they are downloading.

Here is how I export it:

 function exportToExcel() {
 window.open('data:application/vnd.ms-excel,' +
 encodeURIComponent($('#exportToExcelDiv').html()));
 e.preventDefault();
 }

And here is the link that uses that function:

<a href="#" title="Save"><img src="../../Images/glyphicons_446_floppy_save.png"
 alt="save" onclick="exportToExcel()"></a>

Is there a way to do this? Its okay not to use javascript. (I'm doing a webapplication in MVC4).

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Dave
  • 127
  • 4
  • 12
  • you can set the default filename. but the pop up ask user to choose where/what name to save is depend on the browser setting on the user's pc, something like "Ask where to save each file before downloading" in chrome setting. – wayne Mar 25 '14 at 08:56
  • possible duplicate of [Export HTML table to Excel JavaScript function add select file name](http://stackoverflow.com/questions/11084232/export-html-table-to-excel-javascript-function-add-select-file-name) – ystan- Mar 25 '14 at 09:06

1 Answers1

0

When sending the file to the browser, add a Content-Disposition header. In there, you can specify the file name.

Related questions:

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820