`
microsoft_hang
  • 浏览: 8871 次
  • 性别: Icon_minigender_1
  • 来自: 陕西
社区版块
存档分类
最新评论

java代码导出excel

阅读更多

举个例子更加直观

 

在信息展示页面有一个button 此按钮用到将模块信息导出excel则首先用它连接一个action然后在action里查出所有数据将它放入范围在进行跳转到生成数据的jsp

如下:

<%@ page contentType="text/html; charset=GBK" %>、

<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>

<%
  //独立打开excel软件
response.setHeader("Content-disposition","attachment; filename=laborDispute.xls");
//嵌套在ie里打开excel

//response.setHeader("Content-disposition","inline; filename=MyExcel.xls");

//Word只需要把contentType="application/msexcel"改为contentType="application/msword"

%>

<html>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<head>
<title>title</title>

</head>
<body>

<table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#70C3FD" style="border-collapse:collapse">
<tr class=""> 
        <td width="2%">&nbsp;</td>
       <td width="10%" align="center">争议编号</td>
       <td width="10%" align="center">保 险号</td>
       <td width="10%" align="center">单 位号</td>
       <td width="10%" align="center">争议类型</td>             
       <td width="10%" align="center">开始时间</td>
                      <td width="15%" align="center">争议内容</td>
                      <td width="10%" align="center">结    果</td>
                      <td width="10%" align="center">争议附件</td>
                      <td width="15%" align="center">备    注</td>
                    </tr>
     <c:forEach items="${dispute}" var="info">                     
                     <tr >
                       <td width="2%" ></td>
                       <td height="19"  width="10%" align="center">${info.laborDisputeId}</td>
        <td height="19"  width="10%" align="center">${info.employeeUserInfo.UEmployeeId}</td>
        <td height="19"  width="10%"  align="center">${info.organCode}</td>
        <td height="19"  width="10%" align="center">${info.disputeType}</td>
        <td height="19" width="10%" align="center">${info.startDate}</td>
                       <td  width="15%" align="center">${info.disputeContent}</td>
                       <td  width="10%" align="center"> ${info.result}</td>
                       <td  width="10%" align="center"> ${info.attachment}</td>
                       <td  width="15%" align="center"> ${info.memo}</td>
                     </tr>
                   </c:forEach>
   
                  </table>

</body>
</html>

 

只需如此将自己的信息放入jsp 则直接可实现另存为功能导出excel 注意页头部分的设置

<!-- -->
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics