JavaScript - exportar dados da tabela HTML para o Excel


Eu estou tentando converter tabelas HTML para o Excel, eu tentei com uma função JavaScript que converte uma tabela simples para o Excel, ele está funcionando bem. Se eu tiver várias tabelas, como poderei adicionar todos os dados da tabela no arquivo do Excel. aqui está o que eu tentei. Eu criei 2 tabelas e dei um índice de tabelatestTable etestTable1.

Como vou passar esses 2 IDs de tabela para a função JavaScript ao clicar no botão? agora mesmo no clique do botão apenas a primeira tabela é exportada para o Excel como eu estou passando apenas'testTable'. como poderei exportar várias tabelas, por exemplo:testTable, testTable1 no Excel?

Aqui está o 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>

Aqui está a 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, deixe-me saber como isso pode ser feito?
obrigado

questionAnswers(3)

yourAnswerToTheQuestion