我在jsp中使用extjs Ext.grid.GridPanel,因为导出到Excel功能在IE中不起作用。它在FireFox和chrome中工作。
代码:
window.location='data:application/vnd.ms-excel;base64,' + Base64.encode(grid.getExcelXml());
请任何人给我解决方案。提前谢谢。
答案 0 :(得分:1)
我已使用以下代码解决了此问题。
var vExportContent = grid.getExcelXml();
var dataURL = 'export.jsp';
params =[{
name: 'ex',
value: vExportContent
},{
name: 'FileName',
value: 'excel.xls'
}];
post_to_url(dataURL, params, 'post');
function post_to_url(path, params, method) {
method = method || "post";
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var i=0; i<params.length; i++) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", params[i].name);
hiddenField.setAttribute("value", params[i].value);
// alert(params[i].value);
form.appendChild(hiddenField);
}
document.body.appendChild(form);
form.submit();
}
export.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%
response.setHeader("Pragma","public");
response.setHeader("Expires","0");
response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
response.setHeader("Content-Type","application/force-download");
response.setHeader("Content-Type","application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=export2excel.xls");
%>
<%@ page import="java.io.*" %>
<%
String h=request.getParameter("ex");
try {
PrintWriter pw = response.getWriter();
//out.println(request.getParameter("ex"));
pw.println(request.getParameter("ex"));
//clean up
pw.close();
} catch(IOException e) {
out.println(e.getMessage());
}
%>
答案 1 :(得分:0)
您可以查看IE的安全级别设置。
自定义级别 - &gt;安全设置 - &gt;下载 - &gt;自动提示文件下载 - &gt;启用
启用此选项以允许您下载文件,否则它将无法正常打开窗口并立即关闭。你无法确定发生了什么。
我希望它能为您提供解决方案。