导出,下载,(如何决定下不下载)
导出:
1,准备数据写入jsp(可以直接用一个jsp模板承接,也可以后台用流写动态的jsp,outputStream.writer())
2,要让其会下载不展现需要设置响应的头类型:(jsp中设置,动态写入时设置)
<%@ page import="java.util.*"%>
<%
String file_name=java.net.URLEncoder.encode("企业会员信息列表.xls","UTF-8") ;
response.setHeader("Content-disposition","attachment; filename="+file_name);
//以上这行设定传送到前端浏览器时的档名为test1.xls
//就是靠这一行,让前端浏览器以为接收到一个excel档
%>
<%-- <%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%> --%>
<%@ page contentType="application/msexcel; charset=UTF-8" %>//这两个都可以,下面这个更正规
//.do请求要不要下载就是设置这个头
model.addAttribute("operateuserList", op);//同样分key会被覆盖,取最后一个
@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping("/account/tbCusFirmChg/customerListXLS")
public String customerListXLS(TbCusFirmChgVo tbCusFirmChg,Model model) throws EsteelException {
Map<String,Object> param = new HashMap<String,Object>();
param.put("pageNum", tbCusFirmChg.getPageNum()+"");
param.put("pageSize", tbCusFirmChg.getPageSize()+"");
tbCusFirmChg.setCusTradeKind("A");
param = getParam(param,tbCusFirmChg);
if (null == tbCusFirmChg.getOrderField() || tbCusFirmChg.getOrderField() == "") {
tbCusFirmChg.setOrderField("CUSTOMER_KEY");
tbCusFirmChg.setOrderDirection("ASC");
}
param.put("orderField", "C."+tbCusFirmChg.getOrderField());
param.put("orderDirection", tbCusFirmChg.getOrderDirection());
List<TbCusFirmChgVo> tbCusFirmWebList= tbCusFirmChgService.getTbCusFirmChgList(param);
// if(tbCusFirmWebList!=null&&tbCusFirmWebList.size()>0){
// for(TbCusFirmChgVo b:tbCusFirmWebList){
Map<String,Object> param1 = new HashMap<String,Object>();
// param1.put("customer_key", b.getCustomerKey()+"");
List<TbCusUserVo> op= tbCusUserService.getOperateUser(param1);
model.addAttribute("operateuserList", op);//子账户
// }
//
// }
List<TbBasBedSrt> tbBasBedSrtList = new ArrayList<TbBasBedSrt>();
tbBasBedSrtList= tbBasBedSrtService.list();
List<String> companyType= tbCusFirmChgService.getCompanyType();
model.addAttribute("list", tbCusFirmWebList);
model.addAttribute("basbedsrt", tbBasBedSrtList);
model.addAttribute("companyType", companyType);
return "/account/tbCusFirmChg/customerListXLS";
}
样式可以自己拼装
对于我们框架中ajax请求返回要不要下载用
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
===============================================
<%@ page contentType="application/msexcel; charset=UTF-8" %>
<%@ include file="../common/include.inc.jsp"%>
<%@ page import="java.util.*"%>
<%
String file_name=java.net.URLEncoder.encode("企业会员信息列表.xls","UTF-8") ;
response.setHeader("Content-disposition","attachment; filename="+file_name);
//以上这行设定传送到前端浏览器时的档名为test1.xls
//就是靠这一行,让前端浏览器以为接收到一个excel档
%>
<%-- <form id="pagerForm" method="post"
action="/basBedSrt//edit/${vo.warekind_id}">
<input type="hidden" name="pageNum" value="1" />
</form> onsubmit="return checkForm(this); --%>
<link rel=File-List href="Page.files/filelist.xml">
<style id="会员信息列表_10891_Styles">
table
{mso-displayed-decimal-separator:"\.";
mso-displayed-thousand-separator:"\,";}
.font510891
{color:windowtext;
font-size:9.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:宋体;
mso-generic-font-family:auto;
mso-font-charset:134;}
.xl1510891
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:windowtext;
font-size:12.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:宋体;
mso-generic-font-family:auto;
mso-font-charset:134;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl2210891
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:windowtext;
font-size:12.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:宋体;
mso-generic-font-family:auto;
mso-font-charset:134;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
ruby
{ruby-align:left;}
rt
{color:windowtext;
font-size:9.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:宋体;
mso-generic-font-family:auto;
mso-font-charset:134;
mso-char-type:none;}
</style>
<div class="pageContent">
<form method="post"
action="<c:url value='/account/tbCusFirmChg/editJypz?navTabId=tbConFirmFeeNav&callbackType=closeCurrent&flag=${flag}'/>"
class="pageForm required-validate" onsubmit="return validateCallback(this,navTabAjaxDone);" >
<%-- <input type="hidden" name="id" value="${vo.ware_key}" /> --%>
<div class="pageFormContent" layoutH="57">
<input type="hidden" name="customerKey" value="${regUser.CUSTOMER_KEY}" />
<input type="hidden" name="customerId" value="${regUser.CUSTOMER_ID}" />
<input type="hidden" name="creditGrade" value="${regUser.CREDIT_GRADE}" />
<input type="hidden" name="compType" value="${regUser.COMP_TYPE}" />
<input type="hidden" name="tradeApt" value="${regUser.TRADE_APT}" />
<input type="hidden" name="chineseName" value="${regUser.CHINESE_NAME}" />
<input type="hidden" name="englishName" value="${regUser.ENGLISH_NAME}" />
<input type="hidden" name="communicateAddress" value="${regUser.COMMUNICATE_ADDRESS}" />
<input type="hidden" name="companyType" value="${regUser.COMPANY_TYPE}" />
<input type="hidden" name="mainManage" value="${regUser.MAIN_MANAGE}" />
<input type="hidden" name="companyKind" value="${regUser.COMPANY_KIND}" />
<input type="hidden" name="cusTradeKind" value="${regUser.CUS_TRADE_KIND}" />
<table x:str border='0' cellpadding='0' cellspacing='0' width='1008'
style='border-collapse: collapse;table-layout:fixed;width:756pt'>
<col width='80' span=14 style='width:60pt'>
<tr height='19' style='height:14.25pt'>
<td height='19' class='xl2210891' width='80'style='height:14.25pt;width:60pt'>序号</td>
<td height='19' class='xl2210891' width='80'style='height:14.25pt;width:60pt'>会员编码</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>境内/*</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>会员名称</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>联系人</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>手机号</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>邮箱</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>申请日期</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>审批日期</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>会员状态</td>
</tr>
<c:forEach items="${list}" var="item" varStatus="s">
<tr height='19' style='height:14.25pt'>
<td height='19' class='xl2210891' align='right'
style='height:14.25pt;border-top:none'>
${s.index+1}
</td>
<td height='19' class='xl2210891' align='right'
style='height:14.25pt;border-top:none'>
${item.customerId}
</td>
<td class='xl2210891' align='right'
style='border-top:none;border-left:none'>
<c:if test="${item.compType=='A'}">境内</c:if>
<c:if test="${item.compType=='B'}">*</c:if>
</td>
<td class='xl2210891' align='right'
style='border-top:none;border-left:none'>
${item.customerName}
</td>
<td class='xl2210891' align='right'
style='border-top:none;border-left:none'>
${item.tradeManName}
</td>
<td class='xl2210891' align='right'
style='border-top:none;border-left:none'>
${item.tradeManMobile}
</td>
<td class='xl2210891' align='right'
style='border-top:none;border-left:none'>
${item.tradeManEmail}
</td>
<td class='xl2210891' align='right'
style='border-top:none;border-left:none'>
${item.registerDate}
</td>
<td class='xl2210891' align='right'
style='border-top:none;border-left:none'>
<fmt:formatDate value="${item.chkTime}" pattern="yyyy-MM-dd"/>
</td>
<td class='xl2210891' align='right'
style='border-top:none;border-left:none'>
${item.customerStatus}
</td>
</tr>
<tr height='19' style='height:14.25pt'>
<td height='19' class='xl2210891' width='100' style='height:14.25pt;width:60pt'>序号</td>
<td height='19' class='xl2210891' width='100' style='height:14.25pt;width:60pt'>子账号</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>手机号码</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>邮箱</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
</tr>
<c:forEach items="${operateuserList}" var="oplist" varStatus="st">
<c:if test="${item.customerKey==oplist.customer_key}">
<tr height='19' style='height:14.25pt'>
<td height='19' class='xl2210891' align='right'
style='height:14.25pt;border-top:none'>
${st.index+1}
</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>
${oplist.cus_user_id}
</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>
${oplist.tel}
</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>
${oplist.email}
</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td height='19' class='xl2210891' width='80' style='height:14.25pt;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
</tr>
</c:if>
</c:forEach>
<tr height='19' style='height:14.25pt'>
<td height='19' class='xl2210891' width='100' style='height:14.25pt;width:60pt'></td>
<td height='19' class='xl2210891' width='100' style='height:14.25pt;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'></td>
</tr>
</c:forEach>
<![if supportMisalignedColumns]>
<tr height='0' style='display:none'>
<td width='80' style='width:60pt'></td>
<td width='80' style='width:60pt'></td>
<td width='80' style='width:60pt'></td>
<td width='80' style='width:60pt'></td>
<td width='80' style='width:60pt'></td>
<td width='80' style='width:60pt'></td>
<td width='80' style='width:60pt'></td>
<td width='80' style='width:60pt'></td>
<td width='80' style='width:60pt'></td>
</tr>
<![endif]>
</table>
<!-- 证件附件查看 开始 -->
</div>
</form>
</div>
上一篇: 纯CSS绘制漂亮的圆形图案效果