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

export table data to excel in jquery

$( document ).ready(function() {
	$(".export").click(function() {
		var export_type = $(this).data('export-type');		
		$('#data_table').tableExport({
			type : export_type,			
			escape : 'false',
			ignoreColumn: []
		});		
	});
});
Comment

export table data to excel using javascript or jquery

function exportTableToExcel(tableID, filename = ''){
    var downloadLink;
    var dataType = 'application/vnd.ms-excel';
    var tableSelect = document.getElementById(tableID);
    var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
    
    // Specify file name
    filename = filename?filename+'.xls':'excel_data.xls';
    
    // Create download link element
    downloadLink = document.createElement("a");
    
    document.body.appendChild(downloadLink);
    
    if(navigator.msSaveOrOpenBlob){
        var blob = new Blob(['ufeff', tableHTML], {
            type: dataType
        });
        navigator.msSaveOrOpenBlob( blob, filename);
    }else{
        // Create a link to the file
        downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
    
        // Setting the file name
        downloadLink.download = filename;
        
        //triggering the function
        downloadLink.click();
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: numeral js 
Javascript :: setstate in react 
Javascript :: json-server localhost 
Javascript :: sum of an array 
Javascript :: useRoutes 
Javascript :: js set 
Javascript :: execute shell command in javascript 
Javascript :: add class to html tag javascript 
Javascript :: javascript sort 
Javascript :: lastindexof 
Javascript :: check if value is array 
Javascript :: extract data from object when it match with array of ids js 
Javascript :: how to style navigation drawer react navigation v5 
Javascript :: javascript trim text 
Javascript :: js number round to each 15 
Javascript :: js objects 
Javascript :: represent body in javascript 
Javascript :: textcontent javascript 
Javascript :: javascript double question mark 
Javascript :: how to check if string contains substring javascript 
Javascript :: javascript regex match sequence 
Javascript :: how to get firebase document id angular 
Javascript :: switch javascript 
Javascript :: moment.js format 
Javascript :: js 1 minute sleep 
Javascript :: js random number array 
Javascript :: Updating javascript object property 
Javascript :: django csrf failed ajax case 
Javascript :: apply() js 
Javascript :: mongoose populate example 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =