利用ie导出excel文件的方法

 1、重新做一个页面,页面样式和要导出的excel文件格式相同,在页面的最上面加入如下语句:
<%
String year=String.valueOf(request.getAttribute("year"));
String filename = "江苏省电力公司"+year+"年基建工程分市投产项目一览表.xls";
filename = new String(filename.getBytes("GBK"), "ISO-8859-1");
response.setHeader("Content-Disposition", "attachment;" + " filename="+filename);
%>
<%@ page contentType="application/vnd.ms-excel;charset=utf-8" language="java" %>
2、导出的按钮Action只需要转向到这个页面,就可以导出excel。

3、如果导入到excel中有特殊的日期显示方式:例如将2006-09显示为06.09,需要在给所在得td 加入style='mso-number-format:"/@"'
以下是一个做过的例子jsp页面:
<%
String year=String.valueOf(request.getAttribute("year"));
String filename = "江苏省电力公司"+year+"年基建工程分市投产项目一览表.xls";
filename = new String(filename.getBytes("GBK"), "ISO-8859-1");
response.setHeader("Content-Disposition", "attachment;" + " filename="+filename);
%>
<%@ page contentType="application/vnd.ms-excel;charset=utf-8" language="java" %>
<%@taglib uri="/tags/struts-html" prefix="html"%>
<%@taglib uri="/tags/struts-logic" prefix="logic"%>
<%@taglib uri="/tags/struts-bean" prefix="bean"%>
<%@taglib uri="/tags/spsoft" prefix="sp" %>

<html>
 <head>
  <title>基建工程分市投产项目一览表</title> 
 </head>
 
 <body>
    <table border="1" bordercolor="#000000">     
     <thead>    
      <tr>
       <th colspan="14">江苏省电力公司<bean:write name="year"/>年基建工程分市投产项目一览表</th>
      </tr>                  
      <tr>
       <th colspan="14">单位:千伏、万千伏安、公里、万元</th>
      </tr>
      <tr>
       <th rowspan="3">地区</th>
       <th rowspan="3">序号</th>
       <th rowspan="3">工程名称</th>
       <th colspan="6">投产规模</th>
       <th rowspan="3">总投资</th>
       <th rowspan="3">开工时间</th>
       <th rowspan="3">投产时间</th>
       <th rowspan="3">项目数</th>
       <th rowspan="3">备注</th>
      </tr>
      <tr>
       <th colspan="3">变电容量</th>
       <th colspan="3">线路长度</th>
      </tr>
      <tr>
       <th>500</th>
       <th>220</th>
       <th>110</th>
       <th>500</th>
       <th>220</th>
       <th>110</th>
      </tr>
     </thead>
     
     <tbody>
       <logic:notEmpty name="projprogressplanList">
         <logic:iterate id="plan" name="projprogressplanList" indexId="index">                    
          <tr>
       <td rowspan="<bean:write name="plan" property="rowspan"/>" class="area"><bean:write name="plan" property="area"/></td>
       <td>一</td>
       <td>220千伏投产项目</td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td rowspan="<bean:write name="plan" property="rowspan"/>"><bean:write name="plan" property="projCount"/></td>
       <td></td>
      </tr>
           <logic:iterate id="plansub220" name="plan" property="subList220" indexId="index1">                    
       <logic:equal name="plansub220" property="level" value="1">
         <tr>        
       </logic:equal>          
       <logic:equal name="plansub220" property="level" value="2">
         <tr>         
       </logic:equal>       
       <td><bean:write name="plansub220" property="sn"/></td>
       <td><bean:write name="plansub220" property="projcontent"/></td>
       <td><bean:write name="plansub220" format="###.##" property="content500"/></td>
       <td><bean:write name="plansub220" format="###.##" property="content220"/></td>
       <td><bean:write name="plansub220" format="###.##" property="content110"/></td>
       <td><bean:write name="plansub220" format="###.##" property="linelength500"/></td>
       <td><bean:write name="plansub220" format="###.##" property="linelength220"/></td>
       <td><bean:write name="plansub220" format="###.##" property="linelength110"/></td>
       <td><bean:write name="plansub220" format="###.##" property="suminvest"/></td>
       <td align="center" style='mso-number-format:"/@"'><bean:write name="plansub220" format="yy.MM" property="projstartdate"/></td>
       <td align="center" style='mso-number-format:"/@"'><bean:write name="plansub220" format="yy.MM" property="projgointorundate"/></td>
       <td><bean:write name="plansub220" property="remark"/></td>
        </tr>
                          </logic:iterate>
      <tr>
       <td>二</td>
       <td>110千伏投产项目</td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
      </tr>
           <logic:iterate id="plansub110" name="plan" property="subList110" indexId="index1">                    
       <logic:equal name="plansub110" property="level" value="1">
         <tr>        
       </logic:equal>          
       <logic:equal name="plansub110" property="level" value="2">
         <tr>         
       </logic:equal>       
       <td><bean:write name="plansub110" property="sn"/></td>
       <td><bean:write name="plansub110" property="projcontent"/></td>
       <td><bean:write name="plansub110" format="###.##" property="content500"/></td>
       <td><bean:write name="plansub110" format="###.##" property="content220"/></td>
       <td><bean:write name="plansub110" format="###.##" property="content110"/></td>
       <td><bean:write name="plansub110" format="###.##" property="linelength500"/></td>
       <td><bean:write name="plansub110" format="###.##" property="linelength220"/></td>
       <td><bean:write name="plansub110" format="###.##" property="linelength110"/></td>
       <td><bean:write name="plansub110" format="###.##" property="suminvest"/></td>
       <td><bean:write name="plansub110" format="yy.MM" property="projstartdate"/></td>
       <td><bean:write name="plansub110" format="yy.MM" property="projgointorundate"/></td>
       <td><bean:write name="plansub110" property="remark"/></td>
        </tr>
                          </logic:iterate>
      </logic:iterate>
     </logic:notEmpty> 
      <tr>
       <td></td>
       <td></td>
       <td>总计</td>
       <td></td>
       <td><bean:write name="projprogressplanByAreaFormTotal" format="###.##" property="content220"/></td>
       <td><bean:write name="projprogressplanByAreaFormTotal" format="###.##" property="content110"/></td>
       <td></td>
       <td><bean:write name="projprogressplanByAreaFormTotal" format="###.##" property="linelength220"/></td>
       <td><bean:write name="projprogressplanByAreaFormTotal" format="###.##" property="linelength110"/></td>
       <td><bean:write name="projprogressplanByAreaFormTotal" format="###.##" property="suminvest"/></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
      </tr>          
     </tbody>
    </table>
 </body>
</html>

阅读更多
个人分类: 学习笔记
想对作者说点什么? 我来说一句

IE下将table导出excel

2011年12月21日 4KB 下载

没有更多推荐了,返回首页

不良信息举报

利用ie导出excel文件的方法

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭