php - How to download multiple HTML tables to Excel using JavaScript -
i have page multiple html tables there...i need download html tables microsoft excel. current coding have can download first table need download tables.
this javascript have used:
<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) { if (!table.nodetype) table = document.getelementbyid(table) var ctx = {worksheet: name || 'worksheet', table: table.innerhtml} window.location.href = uri + base64(format(template, ctx)) } })() </script>
and portion of php table populated:
<div id="render_me"> <table width='100%' id="testtable"> <col width="15%" /> <col width="10%" /> <col width="25%" /> <col width="15%" /> <col width="10%" /> <col width="15%" /> <col width="10%" /> <tr> <th><?php echo $b; //row id ?></th> <th class='forcedwidth1'>merk</th> <th class='forcedwidth1'>artikel naam</th> <th>ean</th> <th>prijs kieskeurig.nl</th> <th>verschil kieskeurig.nl</th> <th>ral prijs</th> </tr> <?php while($row=mysql_fetch_object($sql)):?> <tr> <td width:'90px'></td> <td class='forcedwidth1'><?php echo $row->merk; //row id ?></td> <td class='forcedwidth1'><?php echo (utf8_decode($row->om)); //row id ?></td> <td class='forcedwidth'><?php echo(utf8_decode("<a href=".$row->tw_url.">".$row->ean."</a>")); ?></td> <td class='forcedwidth'><?php $num2 = $row->price; echo number_format($num2,2,'.', ''); ?></td> <td class='forcedwidth'><?php $num6 = $num2 - $row->ral; echo number_format($num6, 2, '.', ''); // row first name ?></td> <td class='forcedwidth'><?php echo $row->ral; // row first name ?></td> </tr> <?php endwhile;?> </table> <?php } }?> <?php }?> <button id="btnexport" class="button2"></button> <button onclick="demopdf()" class="button1"> </button> </div> <input type="button" onclick="tabletoexcel('testtable', 'w3c example table')" value="export excel">
any appreciated.
Comments
Post a Comment