Export table to excel using jquery | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Export table to excel using jquery

i will add button for export table in html page to excel file using jquery. please help me.

21st Jun 2017, 6:05 PM
Atiye Khajepour
Atiye Khajepour - avatar
4 Answers
21st Jun 2017, 7:44 PM
Burey
Burey - avatar
+ 6
please help me.
24th Aug 2017, 7:21 AM
Atiye Khajepour
Atiye Khajepour - avatar
+ 3
not correct. this codes not display correct for table with rowspan and colspan. i find below code that is correct display. but this occur "field- network error" when table rows is larger of 2000 rows. 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: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.getElementById(table)         var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }         document.getElementById("exel").href = uri + base64(format(template, ctx));         document.getElementById("exel").download = filename;         document.getElementById("exel").click();     } })()
27th Jun 2017, 5:15 AM
Atiye Khajepour
Atiye Khajepour - avatar
+ 2
I don't know about jQuery, but there's a free to use script in php which creates/reads excel files. https://blog.mayflower.de/561-Import-and-export-data-using-PHPExcel.html
21st Jun 2017, 8:45 PM
Mario L.
Mario L. - avatar