zoukankan      html  css  js  c++  java
  • jsp 导出excel

    1、jsp页面

    <%@ page contentType="application/vnd.ms-excel; charset=gbk"%>
    <%@ page language="java" pageEncoding="GBK"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%
        String filename = new String(("积分流水").getBytes("GBK"),"ISO-8859-1"); 
        response.addHeader("Content-Disposition", "filename=" + filename+ ".xls");
    %>
    <html>
    <head>
    <meta name="Generator" content="Microsoft Excel 11">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <body>
    	<table border="1" align="center" cellpadding="0" cellspacing="1">
    		<tr>
    			<td colspan="10" style="text-align: center; height: 35px;"><b>积分商城订单明细</b>
    			</td>
    		</tr>
    		<tr>
    			<td colspan="10">积分流水(笔):${co},总赠送(积分):${give},总消耗(积分):${expend},总消耗价值(元):${money}
    		</tr>
    		<tr>
    			 		<td align="center">用户名</td>
                        <td align="center">用户ID </td>
                        <td align="center">手机</td>
                        <td align="center">操作类型</td>
                        <td align="center">积分数额</td>
                        <td align="center">操作时间</td>
                        <td align="center">原因</td>
                        <td align="center">订单号</td>
                        <td align="center">剩余积分</td>
                        <td align="center">当时总剩余积分</td>
                        <td align="center">当时总消耗积分</td>
                        <td align="center">当时总获赠积分</td>
    		</tr>
    		<c:forEach items="${financeCredits }" var="obj">
    			<tr>
    				<td align="center">${obj.nickname}</td>
    				<td align="center">${obj.acccode}</td>
    				<td align="center">${obj.phone}</td>
    				<c:choose>
    				   <c:when test="${obj.type ==1 }">  
    				     <td align="center">收入</td>
    					<td align="center">+${obj.count}</td>
    				   </c:when>
    				   <c:otherwise> 
    				  <td align="center">支出</td>
    					<td align="center">-${obj.count}</td>
    				   </c:otherwise>
    				</c:choose>
    				<td align="center">${obj.creattime}</td>
    				<td align="center">${obj.descript}</td>
    				<td align="center">${obj.ordercode}</td>
    				<td align="center">${obj.surCredit}</td>
    				<td align="center">${obj.consumCredit}</td>
    				<td align="center">${obj.countCredit}</td>
    				<td align="center">${obj.addCredit}</td>
    			</tr>
    		</c:forEach>
    	</table>
    </body>
    </html>
    

      2、controller

    @RequestMapping(value = "/downloadExcelMainCreadit",method = RequestMethod.GET)
    	public ModelAndView downloadExcelMainCreadit(HttpServletRequest req,HttpServletResponse resp,Integer proStatus,
    			Integer proIndex,
    			String startTime,
    			String endTime,
    			Integer startcredit,
    			Integer endcredit,
    			String userName) throws UnsupportedEncodingException{
    		ModelAndView modelAndView = new ModelAndView("Mgr/mall/downloadExcelMainCredit");
    		if(null!=userName&&""!=userName){
    			userName = new String(userName.getBytes("iso-8859-1"), "utf-8");
    		}
    		if(null==startTime.trim() || null==endTime.trim()){
    			startTime = null;
    			endTime = null;
    		}
    		List<LinkedHashMap<String,Object>> financeCredits = financeCreditService.selectAll(proStatus,proIndex,startTime,endTime,startcredit,endcredit,userName);
    		LinkedHashMap<String,Object> count = financeCreditService.selectCount();
    		
    		modelAndView.addObject("financeCredits", financeCredits);
    		modelAndView.addObject("co", count.get("co"));
    		modelAndView.addObject("give", count.get("give"));
    		modelAndView.addObject("expend", count.get("expend"));
    		modelAndView.addObject("money", MathUtil.div((BigDecimal)count.get("expend"),100));   //
    		return modelAndView;
    	}
    

      

  • 相关阅读:
    生产上第一使用线程池后的总结与反思
    20190407
    20190403
    Asp.net MVC中的ViewData与ViewBag
    easyui datagrid分页
    EF从数据库更新模型更新不到新表
    C语言 笔记(函数)
    python 写100~1000以内水仙花数
    python 求前n项阶乘的和
    python 写九九乘法表
  • 原文地址:https://www.cnblogs.com/xdcr/p/7675621.html
Copyright © 2011-2022 走看看