Basic Method of generating Microsoft Excel file by passing html table Id into XLExport method.
function XLExport(tableId) {
var tab_text = "<table border='2px'><tr bgcolor='#87AFC6'>";
tab = document.getElementById(tableId);
for (var j = 0 ; j < tab.rows.length ; j++) {
tab_text = tab_text + tab.rows[j].innerHTML + "</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, ""); // remove input params
sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
return (sa);
}
var tab_text = "<table border='2px'><tr bgcolor='#87AFC6'>";
tab = document.getElementById(tableId);
for (var j = 0 ; j < tab.rows.length ; j++) {
tab_text = tab_text + tab.rows[j].innerHTML + "</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, ""); // remove input params
sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
return (sa);
}
0 Comments