JSP导出Excel文件

时间:2023-12-13 12:22:14

和普通的查询数据差别是没有分页,response设置一下就是到处功能。
window.location.href="${_base}/promoteConsume/exportExcel?"+param; <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="ai" uri="/WEB-INF/tag/ai-tags.tld"%>
<%@ taglib uri="/WEB-INF/tag/ElTag.tld" prefix="el"%>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = format.format(new Date());
response.setContentType("Application/msexcel; charset=UTF-8");
System.out.println("dateStr="+dateStr);
String fileName = "促销费"+dateStr;
fileName = new String(fileName.getBytes("GBK"),"iso-8859-1");
response.setHeader("Content-disposition","attachment; filename="+fileName+".xls");
%>
<div class="big_main" id="sos_list_div" style="width: 1400px; overflow: hidden">
<div class="query_table">
<table width="100%" border="1" cellspacing="1">
<tr align="center" valign="middle">
<td height="35" colspan="14" align="center" style="border-bottom: 2px #ddd solid"><span class="STYLE4 STYLE6">${title}促销费</span></td>
</tr>
<tr align="center" valign="middle">
<td height="35" colspan="2">统计时间:${sj }</td>
<td width="20%" colspan="10"> </td>
<td width="7%" colspan="2"><span class="STYLE4">促销费合计:${totalAmount } 元</td>
</tr>
</div>
<div class="query_table" style=" margin-top:0px">
<table width="100%" border="0" cellspacing="1">
<tr align="center" valign="middle" bgcolor="#e3f0f6" style=" border-top:1px solid #d1d3d5;">
<td width="6%" height="35">促销费月份</td>
<td width="6%" height="35">受理日期</td>
<td width="7%">活动编码</td>
<td width="6%" height="35">活动名称</td>
<td width="6%" height="35">销售数量</td>
<td width="9%" height="35">促销费金额(元)</td>
<td width="7%" height="35">营业员代码</td>
<td width="7%" height="35">营业员</td>
<td width="6%" height="35">发展人编号</td>
<td width="7%" height="35">发展人姓名</td>
<td width="6%" height="35">门店代码 </td>
<td width="10%">门店名称</td>
<td width="6%" height="35"><span class="STYLE4">公司代码</span></td>
<td width="8%" height="35"><span class="lan_zi">公司名称</span></td>
</tr> <!-- 循环显示数据 -->
<c:forEach items="${pageInfo.result}" var="v" varStatus="vs" begin="0" step="1">
<tr>
<td height="35" align="center" valign="middle">${v.protoMonth}</td>
<td height="35" align="center" valign="middle">${v.dealTime}</td>
<td align="center" valign="middle">${v.productId}</td>
<td height="35" align="center" valign="middle">${v.productName}</td>
<td height="35" align="center" valign="middle">${v.sellNum}</td>
<td height="35" align="center" valign="middle">${v.protoFee}</td>
<td height="35" align="center" valign="middle">${v.optOperId}</td>
<td height="35" align="center" valign="middle">${v.optOperName}</td>
<td height="35" align="center" valign="middle">${v.devId}</td>
<td height="35" align="center" valign="middle">${v.devName}</td>
<td height="35" align="center" valign="middle">${v.storeId}</td>
<td align="center" valign="middle">${v.storeName}</td>
<td height="35" align="center" valign="middle">${v.componentId }</td>
<td height="35" align="center" valign="middle">${v.componentName}</td>
</tr>
</c:forEach>
</table>
</div>
<!-------查询table区结束-------->
</div>