var tableToExcel = (function() { // 크롬에서는!
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML};
window.location.href = uri + base64(format(template, ctx));
};
})()
function exportExcelIe8(targetId, SaveFileName){ // ie8에서
var oNewDoc = document.createDocumentFragment();
var objMeta = oNewDoc.createElement("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>");
var objHead = oNewDoc.createElement("<head>");
var objHtml = oNewDoc.createElement("<html>");
var objBody = oNewDoc.createElement("<body>");
for(i=0; i<6; i++){
objDownload = document.getElementById(tableArray[i]); // 테이블
var oCloneNode = objDownload.cloneNode(true);
objHead.insertBefore(objMeta);
objHtml.insertBefore(objHead);
objBody.insertBefore(oCloneNode);
objHtml.insertBefore(objBody);
}
var nLength = objDownload.rows.length;
oNewDoc.insertBefore(objHtml);
if(!SaveFileName)
{
SaveFileName='통계엑셀.xls';
}
oNewDoc.execCommand("SaveAs",true, SaveFileName);
}
'IT노트 > javaScript' 카테고리의 다른 글
Node.js란? (0) | 2015.03.21 |
---|---|
ArrayList를 javascript에서 var로 받는 방법!!!! (0) | 2015.03.19 |
html, 자바스크립트, ajax 이용해서 db 연동 (0) | 2015.03.12 |
자바스크립트_클립보드에 값 저장. (0) | 2015.03.04 |
자바스크립트 고급 꼭알아두자! (0) | 2015.03.04 |