利用ie导出excel文件的方法

原创 2007年09月19日 16:06:00

 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>

相关文章推荐

JS直接导出excel 兼容ie、chrome、firefox

var idTmr; function getExplorer() { var explorer = window.navigator....

ie中简单导出word和excel功能

原文链接:http://blog.csdn.net/cngkqy/article/details/1803301 此方法只适合ie,并且需要设置浏览器。但是如果要实现简单的导出功能,不失为一种解决办...

JS导出 excel(适用于ie内核浏览器)

JS导出 excel(适用于ie内核浏览器)
  • ldl_xz
  • ldl_xz
  • 2016年06月29日 22:33
  • 419

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

HTML用JS导出Excel的五种方法

这五种方法前四种方法只支持IE浏览器,最后一个方法支持当前主流的浏览器(火狐,IE,Chrome,Opera,Safari) html 表格导出道 ...

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

使用jquery Ajax的post方法或直接使用jqery ajax请求action 得到返回的json数据

在初步掌握了java对象和json的相互转化之后,

实现div里的img图片水平垂直居中

body结构 方法一: 将display设置成table-cell,然后水平居中设置text-align为center,垂直居中设置vertical-align...
  • DreamFJ
  • DreamFJ
  • 2017年03月31日 09:53
  • 19900

[水晶报表]导出PDF or Excel,并返回文件到用户的IE浏览器中

using System; using System.Collections; using System.ComponentModel; using System.Data; using Sy...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:利用ie导出excel文件的方法
举报原因:
原因补充:

(最多只允许输入30个字)