javascript - How to export an html table as an xlsx file -


i have question exporting html table xlsx file. did work , can export xls, need export xlsx.

here jsfiddle : https://jsfiddle.net/272406sv/1/

here html :

<table id="toexcel" class="uitable">   <thead>     <tr>       <th>kampanya başlığı</th>       <th>kampanya türü</th>       <th>kampanya başlangıç</th>       <th>kampanya bitiş</th>       <th style="text-align: center">aksiyonlar</th>     </tr>   </thead>   <tbody>     <tr ng-repeat="item in campaign.campaignlist">       <td> item.campaigntitle </td>       <td> item.campaignhoteltype </td>       <td> item.campaignhotelcheckindate) </td>       <td>item.campaignhotelcheckoutdate</td>       <td style="text-align: center">         <button> action </button>       </td>     </tr>   </tbody> </table>  <button onclick="exceller()">excel</button> 

here js :

<script>   function exceller() {     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];         })       }     var toexcel = document.getelementbyid("toexcel").innerhtml;     var ctx = {       worksheet: name || '',       table: toexcel     };     var link = document.createelement("a");     link.download = "export.xls";     link.href = uri + base64(format(template, ctx))     link.click();   }  </script> 

you won't able export xlsx without going server. xlsx file collection of xml files, zipped together. means need create multiple files. impossible js, client-side.

instead, should create function retrieving data html table , send server. server can create xlsx file (there bunch of libs available that!) , send client download.

if expect have huge dataset, xlsx creation on server should done async process, notify user when it's done (instead of having user waiting file created).

let know language use on server, , we'll able recommend libraries.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -