zoukankan      html  css  js  c++  java
  • 导出excel (返回页面方式)

    说明:不需要poi直接导出需要数据为 Excel (ssh框架实例)

    • struts2配置文件:
      <!-- 导出功能 -->
              <action name="downLoadDetail" class="employeeAction" method="downLoadDetail">
                  <result name="success">/pages/sales/feeManage/AgentDowloadDetail.jsp</result>
              </action>
    • Action代码:
      public String downLoadDetail() {
      //导出表格名称: String fileNameTemp
      = "导出明细"; try {
      //转码(避免中文乱码) String fileName
      = java.net.URLEncoder.encode(fileNameTemp, "UTF-8"); getRequest().setAttribute("fileName", fileName);
      //查询需要导出的数据: List
      <PrpCommission> prpComList = employeeService.findPrpCommission(downAgentcode, paramYearMonth); ActionContext.getContext().put("prpComList", prpComList); } catch (Exception e) { e.printStackTrace(); throw new BusinessException("导出时发生异常", false); } return SUCCESS; }
    • jsp页面:
      <%@page contentType="text/html;charset=UTF-8"%>
      <html>
      <head>
          <title>导出</title>
      /* 重点:加如该头文件 */ <% response.reset(); response.setContentType("application/vnd.ms-excel;charset=UTF-8"); response.setHeader("Content-Disposition", String.format("attachment; filename="%s"", request.getAttribute("fileName").toString()+".xls")); %> </head> <body id="all_title"> <s:form action="" namespace="" method="post"> <table border="1" cellpadding="2" cellspacing="0"> <tr align="center"> <td>***</td> <td>***</td> <td>***</td> <td>***</td> <td>***</td> <td>***</td> <td>***</td> <td>***</td> <td>***</td> <td>***</td> <td>***</td> </tr> <s:iterator value="prpComList" id="commission"> <tr class="sort" align="center"> <td><s:property value="#commission.prpSmain.policyNo"/></td> <td><s:property value="#commission.realpolicyid"/></td> <td><s:property value="#commission.prpJpaymentBill.commNo"/></td> <td><s:property value="#commission.companyCode"/></td> <td><s:property value="#commission.companyName"/></td> <td><s:property value="#commission.comCode"/></td> <td><s:property value="#commission.agentCode"/></td> <td><s:property value="#commission.agentName"/></td> <td><s:date name="#commission.generateTime" format="yyyy-MM-dd"/></td> <td><s:property value="#commission.termNum"/></td> <td><s:property value="#commission.agentfee"/></td> </tr> </s:iterator> </table> </s:form> </body> </html>
  • 相关阅读:
    IIS7.x经典模式与集成模式
    pocketsphinx实现连续大词汇量语音识别
    js对象冒充实现的继承
    你不得不知道的HTML5的新型标签
    (译)开发优秀的虚拟现实体验:从开发I Expect You to Die中总结的六个要点
    《构建之法》阅读梳理篇读后感
    VR介绍
    推荐
    VR设备
    开发VR游戏的基本要求
  • 原文地址:https://www.cnblogs.com/forever2h/p/6836938.html
Copyright © 2011-2022 走看看