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>
  • 相关阅读:
    Retrofit 传递json 和 复杂参数类型List<T>
    Android Activity has leaked window that was originally added
    Android 集成GoogleMap,实现定位和获取位置信息
    Android 新浪微博开放平台应用 android签名怎么获得
    Android java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader......couldn't find "libweibosdkcore.so
    Android 微信第三方登录
    Android RxVolley = Volley + RxJava + OkHttp
    Android 微博sdk接入授权指南
    Android之通过配置Flavor实现一个项目打包成多个apk
    Android第三方登陆之新浪微博Weibo篇(原生登陆授权)
  • 原文地址:https://www.cnblogs.com/forever2h/p/6836938.html
Copyright © 2011-2022 走看看