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;
    	}
    

      

  • 相关阅读:
    试题 基础练习 Sine之舞
    试题 基础练习 Huffuman树
    试题 基础练习 完美的代价
    支付宝支付功能, 创建订单并生成支付链接的接口, 后端支付宝异步回调接口
    GenericAPIView, drf内置的基础分页器和偏移分页器的使用, 过滤器, django-filter插件实现区间分类
    celery, 数据库分表
    redis
    注册, 校验手机号接口, 手机号注册接口, 全局配置drf-jwt身份认证, 局部配置SendSmsAPIView类的频率认证, Vue操作Cookie
    登录, 发送验证码接口, 对官方提供的短信SDK进行二次封装
    pycharm全局搜索快捷键: ctrl + n, Xadmin的使用, 前端Banner小组件, 后端控制轮播图展示的数量, git
  • 原文地址:https://www.cnblogs.com/xdcr/p/7675621.html
Copyright © 2011-2022 走看看