1

I have only a HTML page and need to export a table as Excel document. There is no back-end. Must achieve this only with Javascript.

I am doing export process with this line of js;

window.open('data:application/vnd.ms-excel,' + encodeURIComponent($('#excelContainer').html()));

And HTML page has this meta tag;

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

But my table contains some Turkish special chars and Excel doesn't show them correctly.

I've done a research but all solutions works from back-end so need a little help.

Thanks!

gkonuralp
  • 463
  • 2
  • 11
  • 27

3 Answers3

2

Encoding data to base64 and export like this. This jquery plugin may help you https://github.com/carlo/jquery-base64/blob/master/jquery.base64.min.js

and you can change the code to window.open('data:application/vnd.ms-excel;base64,' + $.base64.encode(html);

Since am not into this field i got this answer from here.

Hope it helps

Community
  • 1
  • 1
Avinash Babu
  • 6,171
  • 3
  • 21
  • 26
  • Tried it. Returns "Error: INVALID_CHARACTER_ERR: DOM Exception 5" – gkonuralp Jul 23 '14 at 09:08
  • 1
    Update: Instead of jQuery plugin I used the Javascript function from [here](http://phpjs.org/functions/base64_encode/) and changed my code like this; window.open('data:application/vnd.ms-excel;base64,' + base64_encode($('#excelContainer').html())); Special chars still rendering wrong. But wrong chars were rendering like "ÄŸ". And now they like "_1". – gkonuralp Jul 23 '14 at 10:19
0

JQuery Base64 works for me too. Once a time jquery.base64.min.js is imported on page, command below works fine.

window.open('data:application/vnd.ms-excel;base64,' + jQuery.base64.encode(jQuery('#dvTableData').html()));
0

You can use that <meta http-equiv=\"content-type\" content=\"application/vnd.ms-excel; charset=UTF-8\"> in head tag.