Merhaba arkadaşlar,
Bu yazımızda sizlere jquery ile html/php tabloyu excele aktarmayı, excel formatında indirmeyi anlatacağız.
Herhangi bir html veya php ile yazılmış table formatındaki tablolarınızı excele tek bir tuşla indirip, görüntüleyebilirsiniz.
HTML Kodumuz:
<table id="tbl_exporttable_to_xls" border="1"> <thead> <th>Sr</th> <th>Name</th> <th>Location</th> <th>Job Profile</th> </thead> <tbody> <tr> <td>1</td> <td><p>Amit Sarna</p></td> <td>Florida</td> <td>Data Scientist</td> </tr> <tr> <td>2</td> <td><p>Sagar Gada</p></td> <td>California</td> <td>Sr FullStack Dev</td> </tr> </tbody> </table> <button onclick="ExportToExcel('xlsx')">Excel'e Aktar</button>
Jquery / Js Kodumuz:
<script type="text/javascript" src="https://unpkg.com/xlsx@0.15.1/dist/xlsx.full.min.js"></script> <script> function ExportToExcel(type, fn, dl) { var elt = document.getElementById('tbl_exporttable_to_xls'); var wb = XLSX.utils.table_to_book(elt, { sheet: "sheet1" }); return dl ? XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }): XLSX.writeFile(wb, fn || ('dosya.' + (type || 'xlsx'))); } </script>
İlk Yorumu Siz Yapın