如何在IE浏览器中使用jQuery将html表导出到excel时将'Save as Type '更改为对话框.xls?


// If Internet Explorer
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv:11./)) {
    txtArea1.document.open("txt/html", "replace");
    txtArea1.document.write(tab_text);
    txtArea1.document.close();
    txtArea1.focus();
    sa = txtArea1.document.execCommand("SaveAs", true, tableid + fileNo + ".xls");
}
else
    sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
return (sa);

在上面的代码中,当对话框显示时,保存类型中没有.xls。所以请告诉我如何在下拉列表中添加.xls另存为类型

我同意@RoryMcCrossan - 客户端脚本不会影响浏览器的"另存为"对话框。

如果您希望用户看到该文件类型,当用户单击您的超链接时,它应该向服务器发出请求。然后,在服务器上,您必须生成.xls文件(或内存中的文件流),并使用您在标头中提到的 application/vnd.ms-excel 位将响应发送回去。

如下所示:(使用经典asp回答)

相关内容

最新更新