Javascript Exporting Table data to csv without html tags -
i trying export data table csv file without having use plugins found code:
jquery("#exportbutton").click(function (e) { window.open('data:application/csv;charset=utf-8,' + jquery('#mytable').html()); e.preventdefault(); });
this code works it's saving html tags too. how can export data table in similar way without having html tags in file?
your question interested me. try , it's possible : https://jsfiddle.net/ouvaztan/
html :
<table id="customers"> <tbody><tr> <th>company</th> <th>contact</th> <th>country</th> </tr> <tr> <td>alfreds futterkiste</td> <td>maria anders</td> <td>germany</td> </tr> <tr> <td>centro comercial moctezuma</td> <td>francisco chang</td> <td>mexico</td> </tr> <tr> <td>ernst handel</td> <td>roland mendel</td> <td>austria</td> </tr> <tr> <td>island trading</td> <td>helen bennett</td> <td>uk</td> </tr> <tr> <td>laughing bacchus winecellars</td> <td>yoshi tannamuri</td> <td>canada</td> </tr> <tr> <td>magazzini alimentari riuniti</td> <td>giovanni rovelli</td> <td>italy</td> </tr> </tbody></table>
js :
$(function() { var link = document.createelement('a'); var data = ($("#customers").text().trim().replace(/[\n]+/g, ";").replace(/ /g, "").replace(/;;;/g, ";\n") + ";").replace(/\n/g, "\r\n"); link.download = "test.csv"; link.href = 'data:application/csv;base64,' + btoa(data); link.click(); });
there limitation : lines , columns have contain text , colspan/rowspan not possible
Comments
Post a Comment