Skip to content

Instantly share code, notes, and snippets.

@tracend
Created May 18, 2013 17:38
Show Gist options
  • Select an option

  • Save tracend/5605226 to your computer and use it in GitHub Desktop.

Select an option

Save tracend/5605226 to your computer and use it in GitHub Desktop.
Export an excel sheet from a table with JavaScript (in IE)
// Export an excel sheet from a table with JavaScript (in IE):
// Usage: CreateExcelSheet("myid");
function CreateExcelSheet( el ) {
var x= document.getElementById( el ).rows;
var xls = new ActiveXObject("Excel.Application");
xls.visible = true;
xls.Workbooks.Add
for (i = 0; i < x.length; i++)
{
var y = x[i].cells;
for (j = 0; j < y.length; j++)
{
xls.Cells( i+1, j+1).Value = y[j].innerText;
}
}
xls.Visible = true;
xls.UserControl = true;
return xls;
}
@gigarlew
Copy link

Thanks. One of our computers cannot use clipboard copying method. Yours method helps me.

I wonder whether the efficiency can be improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment