Windows 10 will reach EOS (end of support) on October 14, 2025. For more information, see this article.

Mozilla 도움말 검색

고객 지원 사기를 피하세요. 저희는 여러분께 절대로 전화를 걸거나 문자를 보내거나 개인 정보를 공유하도록 요청하지 않습니다. "악용 사례 신고"옵션을 사용하여 의심스러운 활동을 신고해 주세요.

자세히 살펴보기

export excel with js with wrong file extension ".part"

  • 6 답장
  • 6 이 문제를 만남
  • 21 보기
  • 최종 답변자: mileskunta

more options

I used code : document.location = 'data:application/vnd.ms-excel;base64,'+Base64.encode('the xml to generate the excel file');

to export excel from grid,

name of the file downloaded is xxxx.xls.part

if I change the extension to .xls, the file can be opened correctly.

what should I do to get the right file extension when download?

I used code : document.location = 'data:application/vnd.ms-excel;base64,'+Base64.encode('the xml to generate the excel file'); to export excel from grid, name of the file downloaded is xxxx.xls.part if I change the extension to .xls, the file can be opened correctly. what should I do to get the right file extension when download?

글쓴이 mileskunta 수정일시

선택된 해결법

".part" will be resolved once use FF20+.

You can set your file name as below document.getElementById("Your div id").download = 'NameYouWant.xls';

문맥에 따라 이 답변을 읽어주세요 👍 1

모든 댓글 (6)

more options

In which version have you checked.Try mozilla 20 and above. I faced the same issue it got solved when i used Mozilla 20 version

more options

Suren2327,

we are using FF17, there are two problems, one is it has the extension ".part", another problem is that we cannot set the file's name, it will be an random string by default.

more options

선택된 해결법

".part" will be resolved once use FF20+.

You can set your file name as below document.getElementById("Your div id").download = 'NameYouWant.xls';

more options

Hi Suren2327,

have tried ,the extension is correct now, but about the file name, I am not downloading from a dom element, I actually created a String of hrml and download this html as an xml.

more options

Great Suren2327,

I have tried your way, it works well, Thank you for giving me such a good solution.

more options

here reference the solution in stack over flow: the url is:http://stackoverflow.com/questions/17126453/html-table-to-excel-javascript see the first answer.

You can use download attribute supported by modern browsera for a anchor element. First modify your HTML by adding an invisible anchor:

<a id="dlink" style="display:none;"></a>

<input type="button" onclick="tableToExcel('tablename', 'name', 'myfile.xls')" value="Export to Excel">

Notice also that the call to function tableToExcel now has 3rd parameter - where you specify file name.

Now use this modified code of your original function:


var tableToExcel = (function () {

       var uri = 'data:application/vnd.ms-excel;base64,'
       , template = '{table}
' , 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 }
           document.getElementById("dlink").href = uri + base64(format(template, ctx));
           document.getElementById("dlink").download = filename;
           document.getElementById("dlink").click();
       }
   })()


Notice last 3 code lines: Instead of assigning URL to window - they assign it to the new anchor, then use new download attribute to force download as the given file name and then simple call click() method of the anchor.

Give it a try.