Created
May 18, 2013 17:38
-
-
Save tracend/5605226 to your computer and use it in GitHub Desktop.
Export an excel sheet from a table with JavaScript (in IE)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. One of our computers cannot use clipboard copying method. Yours method helps me.
I wonder whether the efficiency can be improved.