我想用这种方法导出excel文件,但是导出来的文件打开是乱码,请问是什么原因,谢谢了<%@ page contentType="application/msexcel" %>
<!-- 以上这行设定本网页为excel格式的网页 -->
<%
response.setHeader("Content-disposition","inline; filename=test1.xls");
//以上这行设定传送到前端浏览器时的档名为test1.xls
//就是靠这一行,让前端浏览器以为接收到一个excel档
%>
<html>
<head>
<title>Excel档案呈现方式</title>
</head>
<body>
<table border="1" width="100%">
<tr>
<td>姓名</td><td>身份证字号</td><td>生日</td>
</tr>
<tr>
<td>李</td><td>N111111111</td><td>1900/11/12</td>
</tr>
<tr>
<td>梁</td><td>N222222222</td><td>1923/10/1</td>
</tr>
<tr>
<td>张</td><td>N333333333</td><td>1934/12/18</td>
</tr>
</table>
</body>
</html>
<!-- 以上这行设定本网页为excel格式的网页 -->
<%
response.setHeader("Content-disposition","inline; filename=test1.xls");
//以上这行设定传送到前端浏览器时的档名为test1.xls
//就是靠这一行,让前端浏览器以为接收到一个excel档
%>
<html>
<head>
<title>Excel档案呈现方式</title>
</head>
<body>
<table border="1" width="100%">
<tr>
<td>姓名</td><td>身份证字号</td><td>生日</td>
</tr>
<tr>
<td>李</td><td>N111111111</td><td>1900/11/12</td>
</tr>
<tr>
<td>梁</td><td>N222222222</td><td>1923/10/1</td>
</tr>
<tr>
<td>张</td><td>N333333333</td><td>1934/12/18</td>
</tr>
</table>
</body>
</html>
解决方案 »
- 求教下JSON的时间的问题
- servlet没法运行python?
- webService文件上传
- jsp action 在做修改和删除成功和失败页面弹出后出现空白的页面?
- HTTP Status 500是怎恶魔回事?
- 要多长时间学习JSP
- struts标签中的radio怎样实现默认选中一个
- 讨论:关于response.sendRedirect()和out.close()的问题
- 简单问题:<% include file="test.jsp"%>可以传参数码?怎么传?
- 下拉列表选择
- java调用psexec执行远程主机命令,想返回信息分析,但程序一直停在调用语句上了
- jstl标签<ec:table>问题
<%page ……>就可以!
String surfix=fileName.substring(fileName.lastIndexOf('.')+1);
if (surfix.equalsIgnoreCase("pdf")) {
response.setContentType("application/pdf");
return ;
}
if (surfix.equalsIgnoreCase("rar")) {
response.setContentType("application/rar");
return ;
}
if (surfix.equalsIgnoreCase("zip")) {
response.setContentType("application/zip");
return ;
}
if (surfix.equalsIgnoreCase("xls")) {
response.setContentType("application/x-xls");
return ;
}
if (surfix.equalsIgnoreCase("doc")) {
response.setContentType("application/msword");
return ;
}
if (surfix.equalsIgnoreCase("docx")) {
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
return ;
}
if (surfix.equalsIgnoreCase("ppt")) {
response.setContentType("application/vnd.ms-powerpoint");
return ;
}
if (surfix.equalsIgnoreCase("pptx")) {
response.setContentType("application/vnd.openxmlformats-officedocument.presentationml.presentation");
return ;
}
}
<%@ page contentType="application/msexcel" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
response.setHeader("Content-disposition", "inline; filename=test1.xls");
//以上这行设定传送到前端浏览器时的档名为test1.xls
//就是靠这一行,让前
%><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>导出</title>
</head>
<body>
<table border="1" width="100%">
<tr>
<td>
姓名
</td>
<td>
身份证字号
</td>
<td>
生日
</td>
</tr>
<tr>
<td>
李
</td>
<td>
N111111111
</td>
<td>
1900/11/12
</td>
</tr>
<tr>
<td>
梁
</td>
<td>
N222222222
</td>
<td>
1923/10/1
</td>
</tr>
<tr>
<td>
张
</td>
<td>
N333333333
</td>
<td>
1934/12/18
</td>
</tr>
</table>
</body>
</html>俺也测了一下!你就少了
<%@ page language="java" pageEncoding="gbk"%>加上就一切正常了