Comment puis-je exporter plusieurs tables html dans un file csv à l'aide de javascript?

J'ai trouvé cela sur la façon d'exporter une table unique dans un file excel en utilisant javascript, et ça marche parfaitement pour une table:

Tableau HTML vers Excel Javascript

Cependant, j'ai plusieurs tables que je souhaite exporter dans un seul file CSV. Comment pourrais-je modifier ce code pour y parvenir?

J'ai essayé de changer "getElementById" pour "getElementByClass" et j'ai ajouté le même nom de class pour ces arrays, mais la sortie Excel a simplement déclaré "indéfini"

Voici le code que j'ai essayé

<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]--></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, filename) { if (!table.nodeType) table = document.getElementByClass(table) var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML } document.getElementById("dlink").href = uri + base64(format(template, ctx)); document.getElementById("dlink").download = filename; document.getElementById("dlink").click(); } })()</script> <a id="dlink" style="display:none;"></a> <input type="button" onclick="tableToExcel('alltables', 'alltables', 'myfile.xls')" value="Export to Excel"> print "<table id='vmax' class='alltables'>"; print "<caption>VMAX - 3720</caption>"; print "<tr>"; print "<th>Date</th>"; print "<th>Type</th>"; print "<th>Serial</th>"; print "<th>Total Size</th>"; print "<th>Used</th>"; print "<th>Free</th>"; print "<th>Use %</th>"; print "</tr>"; while($row = sqlsrv_fetch_array($stmt)) { print "<tr>"; $date = $row[0]; $result = $date->format('Ym-d'); print "<td>" . $result . "</td>"; for($i=1; $i<6; $i++) { print "<td>" . $row[$i] . "</td>"; } print "<td>" . $row[6]*100 . "%</td>"; print "</tr>"; } print "</table>"; print "<table id='datadomain' class='alltables'>"; print "<caption>DataDomain - Enterprise Vault</caption>"; print "<tr>"; print "<th>Date</th>"; print "<th>Type</th>"; print "<th>Location</th>"; print "<th>CTWDD</th>"; print "<th>CSC</th>"; print "<th>Total Size</th>"; print "<th>Used</th>"; print "<th>Free</th>"; print "<th>Use %</th>"; print "</tr>"; while($row = sqlsrv_fetch_array($stmt)) { print "<tr>"; $date = $row[0]; $result = $date->format('Ym-d'); print "<td>" . $result . "</td>"; for($i=1; $i<8; $i++) { print "<td>" . $row[$i] . "</td>"; } print "<td>" . $row[8]*100 . "%</td>"; print "</tr>"; } print "</table>"; 

Le code se trouve dans les tags php appropriés, je l'ai laissé tomber car il y a beaucoup d'autres tables.