导出excel文件

代码如下,我已经运行过了,没问题

<!-- 设置输出格式,以及编码格式-->
<%@ page contentType="application/vnd.ms-excel; charset=GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String fileName = "所有学生信息.xls";
//设置生成的excel的标题
response.setHeader("Content-disposition", "attachment;filename=" + new String(fileName.getBytes("GBK"),"iso-8859-1"));
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sheet1</x:Name>
<x:WorksheetOptions>
<x:DefaultRowHeight>285</x:DefaultRowHeight>
<x:Selected/>
<x:Panes>
<x:Pane>
<x:Number>3</x:Number>
<x:ActiveRow>3</x:ActiveRow>
<x:ActiveCol>2</x:ActiveCol>
</x:Pane>
</x:Panes>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
<x:WindowHeight>9600</x:WindowHeight>
<x:WindowWidth>15075</x:WindowWidth>
<x:WindowTopX>480</x:WindowTopX>
<x:WindowTopY>90</x:WindowTopY>
<x:ProtectStructure>False</x:ProtectStructure>
<x:ProtectWindows>False</x:ProtectWindows>
</x:ExcelWorkbook>
</xml><![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<style>
td{
/*指定单元格的数据属性,避免excel自动转换格式,比如0001不自动转换成1*/
/*mso-number-forma 是office提供的格式 mso:microsoft*/
mso-number-format:"\@";
background-color:#8DB4E3;
white-space: nowrap;
}
.color0 {background-color:#DBE5F1;}
.color1 {background-color:#B8CCE4;}
</style>
<title>学生信息</title>
</head>

<body>
<table border="1" bordercolor="#538EDA">
<thead>
<tr height="23">
<th nowrap="nowrap"><font color="white">编号</font></th>
<th nowrap="nowrap"><font color="white">姓名</font></th>
<th nowrap="nowrap"><font color="white">性别</font></th>
<th nowrap="nowrap"><font color="white">年龄</font></th>
<th nowrap="nowrap"><font color="white">学号</font></th>
<th nowrap="nowrap"><font color="white">班级</font></th>
<th nowrap="nowrap"><font color="white">专业</font></th>
</tr>
</thead>
<tbody>
<tr align="center" height="23">
<td class="color${status.index mod 2}" title="编号" nowrap="nowrap">00001</td>
<td class="color${status.index mod 2}" title="姓名" nowrap="nowrap">张三</td>
<td class="color${status.index mod 2}" title="性别" nowrap="nowrap">男</td>
<td class="color${status.index mod 2}" title="年龄" nowrap="nowrap">21</td>
<td class="color${status.index mod 2}" title="学号" nowrap="nowrap">070920081</td>
<td class="color${status.index mod 2}" title="班级" nowrap="nowrap">计科0703</td>
<td class="color${status.index mod 2}" title="专业" nowrap="nowrap">计算机科学与技术</td>
</tr>
</tbody>
</table>
</body>
</html>


其中mso-number-format的参照样式可以参照如下的标准格式

mso-number-format:"0" NO Decimals 
mso-number-format:"0\.000" 3 Decimals 
mso-number-format:"\#\,\#\#0\.000" Comma with 3 dec 
mso-number-format:"mm\/dd\/yy" Date7 
mso-number-format:"mmmm\ d\,\ yyyy" Date9 
mso-number-format:"m\/d\/yy\ h\:mm\ AM\/PM" D -T AMPM 
mso-number-format:"Short Date" 01/03/1998 
mso-number-format:"Medium Date" 01-mar-98 
mso-number-format:"d\-mmm\-yyyy" 01-mar-1998 
mso-number-format:"Short Time" 5:16 
mso-number-format:"Medium Time" 5:16 am 
mso-number-format:"Long Time" 5:16:21:00 
mso-number-format:"Percent" Percent - two decimals 
mso-number-format:"0%" Percent - no decimals 
mso-number-format:"0\.E+00" Scientific Notation 
mso-number-format:"\@" Text 
mso-number-format:"\#\ ???\/???" Fractions - up to 3 digits (312/943)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值