with una tabla online exportar data javascript excel

una - Javascript para exportar la tabla html a Excel



jquery export table to excel with css (3)

La funcionalidad de exportación de ShieldUI a Excel ya debería ser compatible con todos los caracteres especiales.

Necesito exportar la tabla html en mi página a un Excel cuando el usuario haga clic en el botón ''Exportar''. Ahora, encontré una solución aquí en desbordamiento de pila que funciona en Firefox.

Exportar tabla html dinámica para sobresalir en javascript en el navegador Firefox

Ahora, no maneja caracteres especiales como ö, ü, ö que son comunes en los idiomas que utilizamos aquí, así que quería preguntar si alguien sabe cómo puedo exportarlos también sin problemas.

Aquí está mi código:

function tabletoExcel(table, name) { var uri = ''data:application/vnd.ms-excel;base64,'' , template = ''<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>{table}</table></body></html>'' , base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))); } , format = function (s, c) { return s.replace(/{(/w+)}/g, function (m, p) { return c[p]; }); }; if (!table.nodeType) table = document.getElementById(table); var ctx = { worksheet: name || ''Worksheet'', table: table.innerHTML }; window.location.href = uri + base64(format(template, ctx)); }


Para la conversión de UTF 8 y la exportación de símbolos de moneda Utilice esto:

var tableToExcel = (function() { var uri = ''data:application/vnd.ms-excel;base64,'' , template = ''<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 version="1.0" encoding="UTF-8" standalone="yes"?><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>{table}</table></body></html>'' , 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) { if (!table.nodeType) table = document.getElementById(table) var ctx = { worksheet: name || ''Worksheet'', table: table.innerHTML } window.location.href = uri + base64(format(template, ctx)) } })()


Si agrega:

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

en la cabecera del documento comenzará a funcionar como se esperaba:

<script type="text/javascript"> var tableToExcel = (function() { var uri = ''data:application/vnd.ms-excel;base64,'' , template = ''<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]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table>{table}</table></body></html>'' , 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) { if (!table.nodeType) table = document.getElementById(table) var ctx = {worksheet: name || ''Worksheet'', table: table.innerHTML} window.location.href = uri + base64(format(template, ctx)) } })() </script>

Fiddle actualizado aquí.