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>
  • 相关阅读:
    mysql自动增长的有关问题,怎么恢复从1开始
    java攻城狮之路--复习JDBC
    读书笔记:《写给大家看的面向对象设计》,《程序员的职业素养》,《设计模式其实很简单》
    《浪潮之巅,第二版》,《黑客与画家》,《暗时间》读后感
    查看SharePoint文档库是,显示层次目录,可以点击返回层次
    浪潮之巅 -- 读后感与杂谈
    InfoPath分别定义New/Edit 表单
    SharePoint js操作原生的New/Edit表单
    nodejs中req.body为空的问题
    请求uniRequest,会请求两次
  • 原文地址:https://www.cnblogs.com/forever2h/p/6836938.html
Copyright © 2011-2022 走看看