I use IE9 to export an html table to excel, i have used the following js code to export my table which works fine, but the problem i face is,
when the export icon is clicked, the browser directly shows a saveAs
option, which forces the user to save the excel before opening it, it doesn't allow to open the excel in view
.
My js function :
function ExcelReport() {
var tab_text = "<table border='2px'><tr border='1px'>";
var tabcol = [];
var j = 0;
var i=0;
var temp;
tab = document.getElementById('myTable'); // id of table
var col = tab.rows[1].cells.length;
tab_text = tab_text + tab.rows[0].innerHTML + "</tr><tr>"; // table title row[0]
for (j = 1; j < tab.rows.length; j++) {
for(i=0;i<col;i++){
if(j==1){ // table header row[1]
tabcol = tabcol + "<td bgcolor='#C6D7EC'>" + tab.rows[j].cells[i].innerHTML + "</td>";
}else{
tabcol = tabcol + "<td>" + tab.rows[j].cells[i].innerHTML + "</td>";
}
}
if(j==1){
temp = tabcol + "</tr>";
}else{
temp = temp + tabcol + "</tr>";
}
tabcol = [];
}
tab_text = tab_text + temp + "</table>";
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,"MyExcelReport.xls");
} else
//other browser not tested on IE 11
sa = window.open('data:application/vnd.ms-excel,'+ encodeURIComponent(tab_text));
return (sa);
}
When export icon is clicked, it shows this dialog box:
What i need is :
Can anyone please help me in getting the above dialog box from browser. Really appreciate your time and help.