Last active
January 4, 2016 10:59
-
-
Save oshanz/8612235 to your computer and use it in GitHub Desktop.
client side html table export to excel
This file contains 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
function ExportExcel(table) { | |
if (!table.nodeType) { | |
table = document.getElementById(table); | |
download(table.outerHTML, "ftable.xls", "application/vnd.ms-excel"); | |
}else{ | |
alert('not a tbl'); | |
} | |
} |
This file contains 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
function download(strData, strFileName, strMimeType) { | |
var D = document, | |
a = D.createElement("a"); | |
strMimeType = strMimeType || "application/octet-stream"; | |
if (window.MSBlobBuilder) { //IE10+ routine | |
var bb = new MSBlobBuilder(); | |
bb.append(strData); | |
return navigator.msSaveBlob(bb, strFileName); | |
} /* end if(window.MSBlobBuilder) */ | |
if ('download' in a) { //html5 A[download] | |
a.href = "data:" + strMimeType + "," + encodeURIComponent(strData); | |
a.setAttribute("download", strFileName); | |
a.innerHTML = "downloading..."; | |
D.body.appendChild(a); | |
setTimeout(function() { | |
a.click(); | |
D.body.removeChild(a); | |
}, 66); | |
return true; | |
} /* end if('download' in a) */ | |
//do iframe dataURL download (old ch+FF): | |
var f = D.createElement("iframe"); | |
D.body.appendChild(f); | |
f.src = "data:" + strMimeType + "," + encodeURIComponent(strData); | |
setTimeout(function() { | |
D.body.removeChild(f); | |
}, 333); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment