I have the following function that exports an html to excel:
function generateexcel(tableid) {
var table= document.getElementById(tableid);
var html = table.outerHTML;
window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));
}
One problem is that the especial characters in the data are transformed to other symbols:
- 1º = 1º
- é = é
How would you fix this? Is there any character replace to the html to prevent it? Any encoding option?
In my case I use generateexcel function previously posted, just adding Capital letters of special characters in order to make it work
Hope it helps...
Replacing chars is a poor solution.
I replaced encodeURIComponent for escape and works fine, but escape is deprecated since ECMAScript v3.
This issue occurs because encodeURIComponent works with UTF-8 and Excel does not.
Better way for me.
Encode data to base64 and export like this. I used jquery-base64 plugin from https://github.com/carlo/jquery-base64/blob/master/jquery.base64.min.js
And change code to:
If you don't want to use jquery, you can use this base64_encode function http://phpjs.org/functions/base64_encode
"Base64 encoding/decoding is already a native function in modern(tm) browsers: btoa(str) and atob(str) are the functions that should can be used without any external reimplementation." - chipairon
I have the same issue, just replace encodeURIComponent for escape.
It works for me...
Just replace
encodeURIComponent
withescape
.Solved adding a replace for the problematic symbols: