`

JSP导出Excel的例子

 
阅读更多

<%@ page contentType="application/msexcel" pageEncoding="utf-8"%>
<%
   response.setHeader("Content-disposition","inline; filename=coomidity.xls");
   //以上这行设定传送到前端浏览器时的档名为test1.xls
   //就是靠这一行,让前端浏览器以为接收到一个excel档
  
%>
<% response.setContentType("application/vnd.ms-excel;charset=GBK");  //防止导出excel中文乱码 %>

 

<html>
<head>
<title>Excel档案呈现方式</title>
</head>
<body>
  <table width="770" height="252" border="1">
  <tr bgcolor="#000099">
    <td width="57" rowspan="2"><span class="STYLE1">商品图片</span></td>
    <td width="57" rowspan="2"><span class="STYLE1">商品名称</span></td>
    <td width="57" rowspan="2"><span class="STYLE1">商品描述</span></td>
    <td width="57" rowspan="2"><span class="STYLE1">商品数量</span></td>
    <td width="57" rowspan="2"><span class="STYLE1">商品价格</span></td>
    <td colspan="3"><span class="STYLE1">商品大类</span></td>
    <td width="69" rowspan="2"><span class="STYLE1">商品质量 </span></td>
    <td width="204" rowspan="2"><span class="STYLE1">商品库存</span></td>
  </tr>
  <tr bgcolor="#003366">
    <td width="43"><span class="STYLE1">淘宝价</span></td>
    <td width="43"><span class="STYLE1">京东价</span></td>
    <td width="62"><span class="STYLE1">亚马孙价</span></td>
  </tr>
  <tr>
    <td><img src="img/1d3e20f3dcf75563352acc87.jpg">&nbsp;</td>
    <td>大火腿</td>
    <td>哇哈哈,真好吃</td>
    <td>222</td>
    <td>22.0</td>
    <td bgcolor="#CCFF00">22</td>
    <td>23</td>
    <td>25</td>
    <td>好</td>
    <td>354555666</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>

 

 

编码在不同环境下可能会有所不同,可以根据自己情况进行设置 ,一般都是gbk或者UTF-8(在中国),

例子里我只是赋了一些静态值吗,当然根据项目需求可以赋动态值,用lixt做个遍历什么的

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics