Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Export html table data to Excel using JavaScript

function fnExcelReport()
{
    var tab_text="<table border='2px'><tr bgcolor='#87AFC6'>";
    var textRange; var j=0;
    tab = document.getElementById('headerTable'); // id of table

    for(j = 0 ; j < tab.rows.length ; j++) 
    {     
        tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
        //tab_text=tab_text+"</tr>";
    }

    tab_text=tab_text+"</table>";
    tab_text= tab_text.replace(/<A[^>]*>|</A>/g, "");//remove if u want links in your table
    tab_text= tab_text.replace(/<img[^>]*>/gi,""); // remove if u want images in your table
    tab_text= tab_text.replace(/<input[^>]*>|</input>/gi, ""); // reomves input params

    var ua = window.navigator.userAgent;
    var msie = ua.indexOf("MSIE "); 

    if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv:11./))      // If Internet Explorer
    {
        txtArea1.document.open("txt/html","replace");
        txtArea1.document.write(tab_text);
        txtArea1.document.close();
        txtArea1.focus(); 
        sa=txtArea1.document.execCommand("SaveAs",true,"Say Thanks to Sumit.xls");
    }  
    else                 //other browser not tested on IE 11
        sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));  

    return (sa);
}
Comment

html table to excel javascript

<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]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></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>
Comment

table to excel javascript

<script
    src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script
    src="https://cdn.rawgit.com/rainabba/jquery-table2excel/1.1.0/dist/jquery.table2excel.min.js"></script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: router.push 
Javascript :: why null is object in javascript 
Javascript :: invalid json response body 
Javascript :: react native new project 
Javascript :: find an element 
Javascript :: how to take input from user in javascript console 
Javascript :: jsx attributes 
Javascript :: js array map concat 
Javascript :: nextjs link 
Javascript :: date.setdate javascript 
Javascript :: req.body showing undefined 
Javascript :: Node.js (node 11.12.0) sample 
Javascript :: how to convert string to random case in javascript 
Javascript :: javascript neue zeilekill 
Javascript :: API key header for appsync graphql request 
Javascript :: javascript continue with Nested Loop 
Javascript :: JavaScript Precision Problems 
Javascript :: JavaScript Destructuring - Before ES6 
Javascript :: JavaScript Generator Function With return 
Javascript :: actionscript round roundnumber 
Javascript :: nodjs : Stream for big file 
Javascript :: fingerprint 
Javascript :: change rotation phaser 
Javascript :: phaser wrap in rectangle 
Javascript :: add multiple phone using js 
Javascript :: nodejs where multiple condition findAll 
Javascript :: nodejs: redirect path to specific path 
Javascript :: Adding A Property To BuiltIn Class In Javascript 
Javascript :: ... in javascript 
Javascript :: sveltekit new app 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =