2017-05-06 1 views

답변

0

당신은 아래와 같은 기능을 시도 할 수 있습니다 :

이름 MyFrame을으로이 기능은 가지고 있어야 오래된 IE 브라우저에서 작업 및 은 iframe을하기 위해
function ExportToExcel(fileName) 
{ 
    var isIE = (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0); 
    if (isIE) { 
     // IE > 10 
     if (typeof Blob != 'undefined') { 
      var fileData = new Blob([document.getElementById("datatable").innerHTML.replace(/=" "/gi, "")], {type: 'application/vnd.ms-excel,'}); 
      window.navigator.msSaveBlob(fileData, fileName + '.xls'); 
     } 
     // IE < 10 
     else { 
      myFrame.document.open("text/html", "replace"); 
      myFrame.document.write(document.getElementById("datatable").innerHTML.replace(/=" "/gi, "")); 
      myFrame.document.close(); 
      myFrame.focus(); 
      myFrame.document.execCommand('SaveAs', true, fileName + '.xls'); 
     } 

    } 
    // crome,mozilla 
    else { 
    var uri = 'data:application/vnd.ms-excel,' + document.getElementById("datatable").innerHTML.replace(/ /g, '%20'); 
     var link = document.createElement("a"); 
     link.href = uri; 
     link.style = "visibility:hidden"; 
     link.download = fileName + ".xls"; 
     document.body.appendChild(link); 
     link.click(); 
     document.body.removeChild(link); 
    } 
} 

이입니다 프레임이 사용된다 이 함수에서. 또한 DIV의 ID로이 코드에서하는 DIV 내부에 테이블을 포장해야합니다 데이터 테이블

+0

덕분에, 내가 이것을 시도 할 수 있습니다. 나는 또한 그것이 base64가되기를 원한다. 당신은 말해 줄 수? –

+0

base64에서 원하는 것은 무엇입니까? 데이터 또는 Excel 시트? –

+0

예, HTML에서 데이터를 렌더링 한 후의 엑셀 시트 –

관련 문제