HTML数据表导出到Excel

时间:2015-11-18 14:06:46

标签: javascript html

我们使用以下代码工作正常,但我们如何设置另存为类型' Excel'在IE窗口弹出窗口?是否有可能使用不同的数据表作为源生成多个Excel工作表?

// If Internet Explorer(Not supported Data URIs), Check navigator details & find whether it is IE or NOT    
if (window.navigator.userAgent.indexOf("MSIE ") > 0 || !!window.navigator.userAgent.match(/Trident.*rv\:11\./)) {
    exportIF.document.open("txt/html", "replace");
    exportIF.document.write(document.getElementById('dataTable').innerHTML]);
    exportIF.document.close();
    exportIF.focus();
    //SaveAs command to Save CSV File
    sa = exportIF.document.execCommand("SaveAs", true, name + ".xls");
    return (sa);  
}
else //other browsers : Chrome/FireFox (Supported Data URIs)
{
    var bb = new Blob([document.getElementById('dataTable').innerHTML], {
                type: "application / vnd.ms - excel"
            });
            var link = document.createElement("a");
            link.download = name + '.xls';;
            link.href = window.URL.createObjectURL(bb);
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
}

0 个答案:

没有答案