DANDARSMASH
Programmer
Hello,
I modified the code from here but i can't get it to work on my site. the only thing i changed was the id of the table: tbl2013-06-03
and then my call:
Thanks in advance for any help with this.
I modified the code from here but i can't get it to work on my site. the only thing i changed was the id of the table: tbl2013-06-03
JavaScript:
function write_to_excel()
{
str="";
var myTable = document.getElementByID('tbl2013-06-03');
var rows = myTable.getElementsByTagName('tr');
var rowCount = myTable.rows.length;
var colCount = myTable.getElementsByTagName("tr")[0].getElementsByTagName("th").length;
var ExcelApp = new ActiveXObject("Excel.Application");
var ExcelWorkbook = ExcelApp.Workbooks.Add();
var ExcelSheet = ExcelWorkbook.ActiveSheet;//new ActiveXObject("Excel.Sheet");
//ExcelSheet.Application.Visible = true;
ExcelApp.Visible = true;
ExcelSheet.Range("A1", "Z1").Font.Bold = true;
ExcelSheet.Range("A1", "Z1").Font.ColorIndex = 23;
//Format table headers
for(var i=0; i<1; i++)
{
for(var j=0; j<colCount-2; j++)
{
str= myTable.getElementsByTagName("tr")[i].getElementsByTagName("th")[j].innerHTML;
ExcelSheet.Cells(i+1,j+1).Value = str;
}
ExcelSheet.Range("A1", "Z1").EntireColumn.AutoFit();
}
for(var i=1; i<rowCount; i++)
{
for(var k=0; k<colCount-2; k++)
{
str= rows[i].getElementsByTagName('td')[k].innerHTML;
ExcelSheet.Cells(i+1,k+1).Value = myTable.rows[i].cells[k].innerText;
}
ExcelSheet.Range("A"+i, "Z"+i).WrapText = true;
ExcelSheet.Range("A"+1, "Z"+i).EntireColumn.AutoFit();
}
//ExcelSheet.SaveAs("C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\thankYouExport.xls");
//ExcelSheet.Application.Quit();
return;
}
and then my call:
HTML:
<a href="javascript:write_to_excel();">Export to Excel</a>
Thanks in advance for any help with this.