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>
  • 相关阅读:
    智力题:砝码称重问题
    Java:Comparator接口
    机器学习中比较重要的几个概念
    NLP:Gensim库之word2vec
    Java遍历Map对象的四种方式
    给数据库减负刻不容缓:多级缓存设计
    CentOS6.10安装redis5.0
    Linux下安装whl文件
    Linux下安装Gensim
    Linux下安装jieba
  • 原文地址:https://www.cnblogs.com/forever2h/p/6836938.html
Copyright © 2011-2022 走看看