码迷,mamicode.com
首页 > 其他好文 > 详细

数据导出到excel

时间:2016-08-04 23:13:38      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:

jsp页面:

数据table:

<form action="/export.jsp" method="post" id="expform">
<input name="content" id="exportcontent" type="hidden">
</form>

<table cellspacing="0" cellpadding="0" border="0" align="center"
                        id="querybody" class="querybodyout">
                        <tbody>
                            <tr id="queryhead">
                                <td width="6%" class="querybodyhead">船名</td>
                                <td width="7%" class="querybodyhead">合同号</td>
                                <td width="5%" class="querybodyhead">货物名称</td>
                                <td width="7%" class="querybodyhead">车牌号</td>
                                <td width="6%" class="querybodyhead">毛重(吨)</td>
                                <td width="6%" class="querybodyhead">皮重(吨)</td>
                                <td width="6%" class="querybodyhead">净重(吨)</td>
                                <td width="6%" class="querybodyhead">具体收货地</td>
                                <td width="6%" class="querybodyhead">货主</td>
                                <td width="6%" class="querybodyhead">货代</td>
                                <td width="8%" class="querybodyhead">皮重称量时间</td>
                                <td width="8%" class="querybodyhead">毛重称量时间</td>
                            </tr>
                            <c:forEach items="${pager.items}" var="item">
                                <tr class="querybodytr" bgcolor="#F0F9FD">
                                    <td>${item.sparestr1}</td>
                                    <td>${item.contractno}</td>
                                    <td>${item.sparestr4}</td>
                                    <td>${item.truckno}</td>
                                    <td>${item.gross/1000}</td>
                                    <td>${item.tare/1000}</td>
                                    <td>${item.net/1000}</td>
                                    <td>${item.sparestr8}</td>
                                    <td>${item.receiver}</td>
                                    <td>${item.sender}</td>
                                    <td>
                                        <fmt:formatDate value="${item.taredatetime}" pattern="yyyy-MM-dd"/>
                                        <br/>
                                        <fmt:formatDate value="${item.taredatetime}" pattern="HH:mm:ss"/>
                                    </td>
                                    <td>
                                        <fmt:formatDate value="${item.grossdatetime}" pattern="yyyy-MM-dd"/>
                                        <br/>
                                        <fmt:formatDate value="${item.grossdatetime}" pattern="HH:mm:ss"/>
                                    </td>
                                </tr>
                                <c:set value="${count + 1}" var="count" />
                                <%-- <c:set value="${sum + item.net}" var="sum" />  --%>
                            </c:forEach>
    </tbody>
 </table>

点击导出执行的js方法:

function expExl(){
     $("#exportcontent").val($(".querybodyout").prop("outerHTML").replace(/\&nbsp;/g,‘‘).replace("border=\"0\"","border=\"1\""));
     $("#expform").submit();
}

表达提交的jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="java.net.URLEncoder"%>

<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=utf-8">
    <style>
<!--
@page
    {margin:.3in .6in .3in .6in;
    mso-header-margin:.3in;
    mso-footer-margin:.3in;
    mso-page-orientation:landscape;
    mso-horizontal-page-align:center;}
.xl28
    {font-size:9.0pt;
    vertical-align:middle;}
-->
</style>
<xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
   <x:Name>Sheet1</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:FitToPage/>
     <x:Print>
      <x:PaperSizeIndex>9</x:PaperSizeIndex>
      <x:Scale>100</x:Scale>
      <x:HorizontalResolution>600</x:HorizontalResolution>
      <x:VerticalResolution>600</x:VerticalResolution>
     </x:Print>
     <x:CodeName>Sheet1</x:CodeName>
     <x:Selected/>
     <x:TopRowVisible>0</x:TopRowVisible>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
 </x:ExcelWorkbook>
</xml>
</head>
 
  <body>
      <%=content %>
  </body>
</html>

 

数据导出到excel

标签:

原文地址:http://www.cnblogs.com/clovem/p/5738663.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!