Export:
1. Prepare data for writing to jsp (you can directly use a jsp template to undertake it, or you can use a stream to write a dynamic jsp in the background, outputStream.writer())
2. To make it download and not show the header type that needs to be set for the response: (set in jsp, set during dynamic writing)
<%@ page import="java.util.*"%>
<%
String file_name=java.net.URLEncoder.encode("Enterprise member information list.xls","UTF-8") ;
response.setHeader("Content-disposition","attachment; filename="+file_name);
//The above line sets the file name when it is sent to the front-end browser test1.xls
//It is this line that makes the front-end browser think that it has received an excel file
%>
<%-- <%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%> --%>
<%@ page contentType="application/msexcel; charset=UTF-8" %>//Both of these can be used, the following is more formal
//.Do requests to download or not is to set this header
model.addAttribute("operateuserList", op);//The same sub-key will be overwritten, take the last one
@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);//Sub account
// }
//
// }
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";
}
Style can be assembled by yourself
For the ajax request in our framework, do you want to download it or not?
<!-- Avoid downloading files when returning JSON when IE executes AJAX -->
<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("Enterprise member information list.xls","UTF-8") ;
response.setHeader("Content-disposition","attachment; filename="+file_name);
//The above line sets the file name when it is sent to the front-end browser test1.xls
//It is this line that makes the front-end browser think that it has received an excel file
%>
<%-- <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="Member Information List_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:Arial;
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:Arial;
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:Arial;
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:Arial;
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'>Member Code</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'>Application date</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>Approval date</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>Membership status</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'>Mobile number</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'>
$ {list.tel}
</td>
<td class='xl2210891' width='80' style='border-left:none;width:60pt'>
$ {list.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>
<!-- Document attachment viewing starts -->
</div>
</form>
</div>