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);
          }
     


Posted by wychoi
,