Posted
Filed under Htm&Javascript
<table id="test" />
<button type="button" onclick="tableToExcel('test')" />

페이징이 없는 테이블 데이터를 받을 때 쓸만합니다.
한글 처리 핵심은 %EF%BB%BF


function
tableToExcel(id) {
    var data_type = 'data:application/vnd.ms-excel;charset=utf-8';
    var table_html = encodeURIComponent(document.getElementById(id).outerHTML);
 
    var a = document.createElement('a');
    a.href = data_type + ',%EF%BB%BF' + table_html;
    a.download = id+'_excel'+'.xls';
    a.click();
}
[참조]https://phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=81515
2017/07/27 08:58 2017/07/27 08:58