I am trying to export html table to excel using below code. Here I am not able to apply styles and format cells like text alignment using jquery. And below code is not working in IE also. Please help me out to resolve above issues.
function exportToExcel() {
var oExcel = new ActiveXObject("Excel.Application");
var oBook = oExcel.Workbooks.Add;
var oSheet = oBook.Worksheets(1);
oSheet.Range("A1", "Z1").Font.Bold = true;
oSheet.Range("A1", "Z1").Font.ColorIndex = 23;
for (var i = 0; i < detailsTable.rows.length; i++) {
for (var j = 0; j < detailsTable.rows(i).cells.length; j++) {
oSheet.Cells(i + 1, j + 1) = detailsTable.rows(i).cells(j).innerText;
}
}
oSheet.Range("A" + i, "Z" + i).WrapText = true;
oSheet.Range("A" + 1, "Z" + i).EntireColumn.AutoFit();
oExcel.Visible = true;
oExcel.UserControl = true;
}
Regards,
Saya
Nikhil PrasadPosted Sep 11, 2014, 6:21 AM
Abhishek JainPosted Sep 18, 2013, 11:11 AM
http://jsfiddle.net/abhishekjain/cV69x/
Hope it helps.
Regards
AJ