java导出excel文件

<%@page contentType="application/vnd.ms-excel;charset=GBK" language="java"%> 
<%@page import="com.hhu.service.*,com.hhu.service.imp.*,com.hhu.bean.ST_R_R_X,java.util.List,java.util.Date" %>
<!-- 以上这行设定本网页为excel格式的网页 -->
<%
    String STCD=request.getParameter("STCD").toString();
    String excelName="扬州三江营";
    String tableName="001";
    if("00000001".equals(STCD))
    {
    excelName="扬州三江营";
    tableName="001";
    }
    else if("00000002".equals(STCD))
    {
    excelName="宿迁市-宿迁闸上游";
    tableName="002";
    }
    else if("00000003".equals(STCD))
    {
    excelName="宿迁市-刘老涧闸上游";
    tableName="003";
    }
    else if("00000004".equals(STCD))
    {
    excelName="宿迁市-刘老涧闸下游";
    tableName="004";
    }
    else if("00000005".equals(STCD))
    {
    excelName="宿迁市-皂河闸上游";
    tableName="005";
    }
    else if("00000006".equals(STCD))
    {
    excelName="宿迁市-皂河闸下游";
    tableName="006";
    }
    else if("00000007".equals(STCD))
    {
    excelName="宿迁市-洋河滩闸上游";
    tableName="007";
    }
    else if("00000008".equals(STCD))
    {
    excelName="宿迁市-洋河滩闸下游";
    tableName="008";
    }
    else if("00000009".equals(STCD))
    {
    excelName="宿迁市-宿迁闸下游";
    tableName="009";
    }
    else if("00000011".equals(STCD))
    {
    excelName="无锡市-洛社";
    tableName="011";
    }
    else if("00000010".equals(STCD))
    {
    excelName="无锡市-宜兴南";
    tableName="010";
    }
    else if("00000013".equals(STCD))
    {
    excelName="无锡市-白芍山";
    tableName="013";
    }
    else if("00000012".equals(STCD))
    {
    excelName="无锡市-江阴";
    tableName="012";
    }
    else
    {excelName="扬州三江营";
    tableName="001";
    }
    Date date=new Date();
   response.setHeader("Content-disposition","inline; filename="+tableName+"_"+date.toLocaleString()+".xls");
   //以上这行设定传送到前端浏览器时的档名为test1.xls
   //就是靠这一行,让前端浏览器以为接收到一个excel档 
    
%>
<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>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
<link rel=File-List href="Book1.files/filelist.xml">
<link rel=Edit-Time-Data href="Book1.files/editdata.mso">
<link rel=OLE-Object-Data href="Book1.files/oledata.mso">
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>微软用户</o:Author>
  <o:LastAuthor>微软用户</o:LastAuthor>
  <o:Created>2012-03-15T11:50:00Z</o:Created>
  <o:LastSaved>2012-03-15T11:54:30Z</o:LastSaved>
  <o:Company>微软中国</o:Company>
  <o:Version>11.9999</o:Version>
 </o:DocumentProperties>
</xml><![endif]-->
<style>
<!--table
    {mso-displayed-decimal-separator:"\.";
    mso-displayed-thousand-separator:"\,";}
@page
    {margin:1.0in .75in 1.0in .75in;
    mso-header-margin:.5in;
    mso-footer-margin:.5in;}
tr
    {mso-height-source:auto;
    mso-ruby-visibility:none;}
col
    {mso-width-source:auto;
    mso-ruby-visibility:none;}
br
    {mso-data-placement:same-cell;}
.style0
    {mso-number-format:General;
    text-align:general;
    vertical-align:middle;
    white-space:nowrap;
    mso-rotate:0;
    mso-background-source:auto;
    mso-pattern:auto;
    color:windowtext;
    font-size:12.0pt;
    font-weight:400;
    font-style:normal;
    text-decoration:none;
    font-family:宋体;
    mso-generic-font-family:auto;
    mso-font-charset:134;
    border:none;
    mso-protection:locked visible;
    mso-style-name:常规;
    mso-style-id:0;}
td
    {mso-style-parent:style0;
    padding-top:1px;
    padding-right:1px;
    padding-left:1px;
    mso-ignore:padding;
    color:windowtext;
    font-size:12.0pt;
    font-weight:400;
    font-style:normal;
    text-decoration:none;
    font-family:宋体;
    mso-generic-font-family:auto;
    mso-font-charset:134;
    mso-number-format:General;
    text-align:general;
    vertical-align:middle;
    border:none;
    mso-background-source:auto;
    mso-pattern:auto;
    mso-protection:locked visible;
    white-space:nowrap;
    mso-rotate:0;}
.xl24
    {mso-style-parent:style0;
    mso-number-format:"\@";}
.xl25
    {mso-style-parent:style0;
    mso-number-format:"\@";
    text-align:center;}
.xl26
    {mso-style-parent:style0;
    text-align:center;}
.xl27
    {mso-style-parent:style0;
    mso-number-format:"yyyy\/m\/d\\ h\:mm\:ss";
    text-align:center;}
ruby
    {ruby-align:left;}
rt
    {color:windowtext;
    font-size:9.0pt;
    font-weight:400;
    font-style:normal;
    text-decoration:none;
    font-family:宋体;
    mso-generic-font-family:auto;
    mso-font-charset:134;
    mso-char-type:none;
    display:none;}
-->
</style>
<!--[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>6</x:ActiveRow>
       <x:ActiveCol>4</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:ExcelWorksheet>
    <x:Name>Sheet2</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet3</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:WindowHeight>10890</x:WindowHeight>
  <x:WindowWidth>21195</x:WindowWidth>
  <x:WindowTopX>240</x:WindowTopX>
  <x:WindowTopY>330</x:WindowTopY>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
 </x:ExcelWorkbook>
</xml><![endif]-->
</head>

<body link=blue vlink=purple>

<table x:str border=0 cellpadding=0 cellspacing=0 width=504 style='border-collapse:
 collapse;table-layout:fixed;width:378pt'>
 <col class="xl24" width=119 style='mso-width-source:userset;mso-width-alt:3808;
 width:89pt'>
 <col width=268 style='mso-width-source:userset;mso-width-alt:8576;width:201pt'>
 <col width=117 style='mso-width-source:userset;mso-width-alt:3744;width:88pt'>
 <tr height=19 style='height:14.25pt'>
  <td height=19 class="xl25" width=119 style='height:14.25pt;width:89pt'>站号</td>
  <td class="xl26" width=268 style='width:201pt'>时间</td>
  <td class="xl26" width=117 style='width:88pt'>水位高度</td>
 </tr>
 <%
    WaterChartService wcs=new WaterChartServiceImp();
    List<ST_R_R_X> list=wcs.getSTListsFromSQL("select * from ST_R_R_00000"+tableName,null,null);
    for(ST_R_R_X sx:list)
    {
 %>
 <tr height=19 style='height:14.25pt'>
  <td height=19 class="xl25" style='height:14.25pt'><%=sx.getSTCD() %></td>
  <td class="xl27" ><%=sx.getTM().toString() %></td>
  <td class="xl25"><%=sx.getZ() %></td>
 </tr>
 <%} %>
 <![if supportMisalignedColumns]>
 <tr height=0 style='display:none'>
  <td width=119 style='width:89pt'></td>
  <td width=268 style='width:201pt'></td>
  <td width=117 style='width:88pt'></td>
 </tr>
 <![endif]>
</table>

</body>

</html>
posted @ 2012-12-01 11:04  软件小书童  阅读(1663)  评论(0)    收藏  举报