jsp输出Excel多个sheet

<%@ page language="java"   import="java.sql.ResultSet" pageEncoding="UTF-8"%>
<jsp:useBean id="dbBean" class="com.study.ding.wenjuan.Manage_db"
scope="page"></jsp:useBean>
<%
request.setCharacterEncoding("UTF-8");
   if(request.getParameter("companyName")!=null)
   {
   String compayName=request.getParameter("companyName").toString();
           
ResultSet rs1 = dbBean.getCompany1(compayName);

ResultSet rs2 = dbBean.getCompany2(compayName);

       response.reset();
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Content-Disposition" ,"attachment;filename=other.xls");
           
%>






<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
  <Author>HPO</Author>
  <LastAuthor>HPO</LastAuthor>
  <LastPrinted>2010-10-26T01:30:00Z</LastPrinted>
  <Created>2010-07-28T09:26:51Z</Created>
  <LastSaved>2011-02-10T02:40:27Z</LastSaved>
  <Company>哈佛企管</Company>
  <Version>12.00</Version>
</DocumentProperties>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  <WindowHeight>8895</WindowHeight>
  <WindowWidth>14955</WindowWidth>
  <WindowTopX>120</WindowTopX>
  <WindowTopY>105</WindowTopY>
  <ProtectStructure>False</ProtectStructure>
  <ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font ss:FontName="新細明體" x:CharSet="136" x:Family="Roman" ss:Size="12"/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
  <Style ss:ID="s21">
   <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/>
   <Borders>
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"
     ss:Color="#000000"/>
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"
     ss:Color="#000000"/>
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"
     ss:Color="#000000"/>
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"
     ss:Color="#000000"/>
   </Borders>
   <Font ss:FontName="新細明體" x:CharSet="136" x:Family="Roman" ss:Size="12"
    ss:Bold="1"/>
   <Interior/>
  </Style>
  <Style ss:ID="s22">
   <Interior/>
  </Style>
  <Style ss:ID="s23">
   <Alignment ss:Vertical="Bottom" ss:WrapText="1"/>
   <Borders>
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"
     ss:Color="#000000"/>
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"
     ss:Color="#000000"/>
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"
     ss:Color="#000000"/>
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"
     ss:Color="#000000"/>
   </Borders>
   <Interior ss:Color="#FFFF00" ss:Pattern="Solid"/>
  </Style>
  <Style ss:ID="s24">
   <Alignment ss:Vertical="Bottom" ss:WrapText="1"/>
   <Borders>
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"
     ss:Color="#000000"/>
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"
     ss:Color="#000000"/>
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"
     ss:Color="#000000"/>
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"
     ss:Color="#000000"/>
   </Borders>
   <Interior ss:Color="#FFFF00" ss:Pattern="Solid"/>
   <NumberFormat ss:Format="Short Date"/>
  </Style>
</Styles>
<Worksheet ss:Name="self">
  <Names>
   <NamedRange ss:Name="_FilterDatabase" ss:RefersTo="=self!R1C1:R1C25"
    ss:Hidden="1"/>
  </Names>
  <Table ss:ExpandedColumnCount="25" ss:ExpandedRowCount="5" x:FullColumns="1"
   x:FullRows="1" ss:StyleID="s22" ss:DefaultColumnWidth="54"
   ss:DefaultRowHeight="16.5">
   <Column ss:Index="4" ss:StyleID="s22" ss:Width="63"/>
   <Column ss:Index="25" ss:StyleID="s22" ss:Width="79.5"/>
   <Row ss:Height="33">
    <Cell ss:StyleID="s21"><Data ss:Type="String">ID</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">NAME</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">EMAIL</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">TEST_DATE</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A1</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A2</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A3</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A4</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A5</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A6</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A7</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A8</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A9</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A10</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A11</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A12</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A13</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A14</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A15</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A16</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A17</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A18</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A19</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A20</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">COMPANY</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
   </Row>



<%  while (rs2.next()){ %>



   <Row ss:Height="33">
    <Cell ss:StyleID="s23"><Data ss:Type="Number"><%=rs2.getString("Id") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("Name") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("Email") %></Data></Cell>
    <Cell ss:StyleID="s24"><Data ss:Type="DateTime"><%=rs2.getString("TEST_DATE") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A1") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A2") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A3") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A4") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A5") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A6") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A7") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A8") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A9") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A10") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A11") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A12") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A13") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A14") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A15") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A16") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A17") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A18") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A19") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("A20") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs2.getString("Company") %></Data></Cell>
   </Row>
<% }%>


  </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <Print>
    <ValidPrinterInfo/>
    <PaperSizeIndex>9</PaperSizeIndex>
    <HorizontalResolution>600</HorizontalResolution>
    <VerticalResolution>0</VerticalResolution>
   </Print>
   <Selected/>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="other">
  <Names>
   <NamedRange ss:Name="_FilterDatabase" ss:RefersTo="=other!R1C1:R1C26"
    ss:Hidden="1"/>
  </Names>
  <Table ss:ExpandedColumnCount="26" ss:ExpandedRowCount="4" x:FullColumns="1"
   x:FullRows="1" ss:StyleID="s22" ss:DefaultColumnWidth="54"
   ss:DefaultRowHeight="16.5">
   <Row ss:Height="33">
    <Cell ss:StyleID="s21"><Data ss:Type="String">ID</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">COMPANY</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">NAME</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">EMAIL</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">NAME1</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A1</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A2</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A3</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A4</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A5</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A6</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A7</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A8</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A9</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A10</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A11</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A12</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A13</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A14</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A15</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A16</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A17</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A18</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A19</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A20</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">TEST_DATE</Data><NamedCell
      ss:Name="_FilterDatabase"/></Cell>
   </Row>

<%  while (rs1.next()){ %>
   <Row ss:Height="49.5">
    <Cell ss:StyleID="s23"><Data ss:Type="Number"><%=rs1.getString("Id") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Company") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Name") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Email") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Name1") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q1") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q2") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q3") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q4") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q5") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q6") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q7") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q8") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q9") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q10") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q11") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q12") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q13") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q14") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q15") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q16") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q17") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q18") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q19") %></Data></Cell>
    <Cell ss:StyleID="s23"><Data ss:Type="String"><%=rs1.getString("Q20") %></Data></Cell>
    <Cell ss:StyleID="s24"><Data ss:Type="String"><%=rs1.getString("TEST_DATE") %></Data></Cell>
   </Row>
<%} %>



  </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <Print>
    <ValidPrinterInfo/>
    <PaperSizeIndex>9</PaperSizeIndex>
    <HorizontalResolution>600</HorizontalResolution>
    <VerticalResolution>0</VerticalResolution>
   </Print>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
  <AutoFilter x:Range="R1C1:R1C26"
   xmlns="urn:schemas-microsoft-com:office:excel">
  </AutoFilter>
  <Sorting xmlns="urn:schemas-microsoft-com:office:excel">
   <Sort>HPO</Sort>
  </Sorting>
</Worksheet>
<Worksheet ss:Name="Sheet3">
  <Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1"
   x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="16.5">
  </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
</Worksheet>
</Workbook>
<%}else{
out.println("<script type=\"text/javascript\">alert(\"错误!\");window.close(); </script>");
} %>















总结:

用现有Excel模版 保存成XML形式,  JSP页面中 以XML内容输入,以XLS格式输出到客户到保存。

这样可以实现多个sheet,

基本都是XML 的操作。

Excel 长ID会用科学计数法显示。



你可能感兴趣的:(sql,xml,jsp,Excel)