JavaScript: exporta datos de tablas HTML a Excel


Estoy tratando de convertir las tablas HTML a Excel, lo he intentado con una función de JavaScript que convierte una tabla simple a Excel, está funcionando bien. Si tengo varias tablas, ¿cómo podré agregar todos los datos de la tabla al archivo de Excel? Esto es lo que intenté. He creado 2 tablas y he dado índice de tablatestTable ytestTable1.

¿Cómo pasaré estos 2 identificadores de tabla a la función JavaScript al hacer clic en el botón? En este momento, al hacer clic en el botón, solo la primera tabla se exporta a Excel, ya que solo paso.'testTable'. ¿Cómo podré exportar varias tablas, por ejemplo:testTable, testTable1 en Excel?

Aquí está el JavaScript:

<script>

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]-->
</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>

Aquí está la parte HTML,

<table id="testTable">
    <thead>
        <tr>
            <th>Name</th>
            <th>ACP</th>
            <th>OEMCP</th>
            <th>Unix<br>
                NT 3.1</th>
            <th>Unix<br>
                NT 3.51</th>
            <th>Unix<br>
                95</th>
        </tr>
    </thead>
</table>
<table id="testTable1">
    <thead>
        <tr>
            <th>Name</th>
            <th>ACP</th>
            <th>OEMCP</th>
            <th>Windows<br>
                NT 3.1</th>
            <th>Windows<br>
                NT 3.51</th>
            <th>Windows<br>
                95</th>
        </tr>
    </thead>
</table>

Por favor, hágamelo saber, ¿cómo se puede hacer esto?
Gracias

Respuestas a la pregunta(3)

Su respuesta a la pregunta