import net.sf.jxls.transformer.Configuration;
import net.sf.jxls.transformer.XLSTransformer;
/** 页面跳转 **/
/* 跳转考评信息查询页面 */
@RequestMapping(value = "/examInfo")
public ModelAndView examInfoPageMain(HttpServletRequest request, HttpServletResponse response, Principal principal) {
LOGGER.info("process showExamInfoPage.");
ModelAndView mav = new ModelAndView("dsm/examInfo");
try {
String orgNo = SysConfig.getInstance().getProvinceOrgNo();
String orgName = dsmService.queryOrgNameByOrgNo(orgNo);
mav.addObject("orgNo", orgNo);
mav.addObject("orgName", orgName);
} catch (Throwable ex) {
LOGGER.warn("examInfoPageMain causes inner exception:", ex);
mav.addObject("orgNo", "");
mav.addObject("orgName", "");
MyHttpServletUtil.sendErrorBadRequest(response);
}
return mav;
}
<!-- 指标查询的tab页内容 start-->
<div class="tab_contents">
<!-- 搜索条件面板 -->
<div class="search_box_panel">
<table class="search-box-table">
<tr>
<th width='40px'></th>
<th>年份:</th>
<th>
<select id="beginYear" name="" class="ui-text">
</select>
</th>
<th>至</th>
<th>
<select id="endYear" name="" class="ui-text">
</select>
</th>
<th width='55%'></th>
<th><button id="search_for_index_btn" class="ui-btn ui-btn-primary">查询</button></th>
<th><button class="ui-btn ui-btn-primary" οnclick="expPdf();">导出PDF</button></th>
<th><button class="ui-btn ui-btn-primary" οnclick="expExl();">导出Excel</button></th>
</tr>
</table>
</div>
<!-- 搜索结果面板 -->
<div id="search_result_panel" class="search_result_panel">
<table id="index_query_table">
<thead>
<tr>
<th rowspan="2">序号</th>
<th rowspan="2">年份</th>
<th colspan="4">节电量(万kWh)</th>
<th colspan="4">节电力(万kW)</th>
<th rowspan="2">状态</th>
</tr>
<tr>
<th>预指标值</th>
<th>确认值</th>
<th>承担值</th>
<th>指标值</th>
<th>预指标值</th>
<th>确认值</th>
<th>承担值</th>
<th>指标值</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<!-- 指标查询的tab页内容 end-->
function expExl(){
var rs={"data":[]};
$("#index_query_table tr").each(function(index){
var temp=[];
$(this).children("td").each(function(i){
temp.push($(this).text());
});
if(temp.length!=0)
rs.data.push(temp);
});
window.location.href="common/ExpExlController/expExl?rs="+JSON.stringify(rs)+"&&fileName=dutyAnalyze.xls";
}
public void expExl(HttpServletRequest request, HttpServletResponse response,Object data) {
String templateFileName = request.getSession().getServletContext()
.getRealPath("/")
+ "/resources/templates/"+XssStringFilter.stringFilter(request.getParameter("fileName"));
String destFileName = XssStringFilter.stringFilter(request.getParameter("fileName"));
InputStream in = null;
OutputStream out = null;
response.setHeader("Content-Disposition", "attachment;filename="
+ destFileName);
response.setContentType("application/vnd.ms-excel");
Map beans = new HashMap();
beans.put("tbInfo", data);
Configuration config = new Configuration();
try {
in = new BufferedInputStream(new FileInputStream(templateFileName));
XLSTransformer transformer = new XLSTransformer(config);
out = response.getOutputStream();
transformer.transformXLS(in, beans).write(out);
out.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
}
import net.sf.jxls.transformer.XLSTransformer;
/** 页面跳转 **/
/* 跳转考评信息查询页面 */
@RequestMapping(value = "/examInfo")
public ModelAndView examInfoPageMain(HttpServletRequest request, HttpServletResponse response, Principal principal) {
LOGGER.info("process showExamInfoPage.");
ModelAndView mav = new ModelAndView("dsm/examInfo");
try {
String orgNo = SysConfig.getInstance().getProvinceOrgNo();
String orgName = dsmService.queryOrgNameByOrgNo(orgNo);
mav.addObject("orgNo", orgNo);
mav.addObject("orgName", orgName);
} catch (Throwable ex) {
LOGGER.warn("examInfoPageMain causes inner exception:", ex);
mav.addObject("orgNo", "");
mav.addObject("orgName", "");
MyHttpServletUtil.sendErrorBadRequest(response);
}
return mav;
}
<!-- 指标查询的tab页内容 start-->
<div class="tab_contents">
<!-- 搜索条件面板 -->
<div class="search_box_panel">
<table class="search-box-table">
<tr>
<th width='40px'></th>
<th>年份:</th>
<th>
<select id="beginYear" name="" class="ui-text">
</select>
</th>
<th>至</th>
<th>
<select id="endYear" name="" class="ui-text">
</select>
</th>
<th width='55%'></th>
<th><button id="search_for_index_btn" class="ui-btn ui-btn-primary">查询</button></th>
<th><button class="ui-btn ui-btn-primary" οnclick="expPdf();">导出PDF</button></th>
<th><button class="ui-btn ui-btn-primary" οnclick="expExl();">导出Excel</button></th>
</tr>
</table>
</div>
<!-- 搜索结果面板 -->
<div id="search_result_panel" class="search_result_panel">
<table id="index_query_table">
<thead>
<tr>
<th rowspan="2">序号</th>
<th rowspan="2">年份</th>
<th colspan="4">节电量(万kWh)</th>
<th colspan="4">节电力(万kW)</th>
<th rowspan="2">状态</th>
</tr>
<tr>
<th>预指标值</th>
<th>确认值</th>
<th>承担值</th>
<th>指标值</th>
<th>预指标值</th>
<th>确认值</th>
<th>承担值</th>
<th>指标值</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<!-- 指标查询的tab页内容 end-->
function expExl(){
var rs={"data":[]};
$("#index_query_table tr").each(function(index){
var temp=[];
$(this).children("td").each(function(i){
temp.push($(this).text());
});
if(temp.length!=0)
rs.data.push(temp);
});
window.location.href="common/ExpExlController/expExl?rs="+JSON.stringify(rs)+"&&fileName=dutyAnalyze.xls";
}
public void expExl(HttpServletRequest request, HttpServletResponse response,Object data) {
String templateFileName = request.getSession().getServletContext()
.getRealPath("/")
+ "/resources/templates/"+XssStringFilter.stringFilter(request.getParameter("fileName"));
String destFileName = XssStringFilter.stringFilter(request.getParameter("fileName"));
InputStream in = null;
OutputStream out = null;
response.setHeader("Content-Disposition", "attachment;filename="
+ destFileName);
response.setContentType("application/vnd.ms-excel");
Map beans = new HashMap();
beans.put("tbInfo", data);
Configuration config = new Configuration();
try {
in = new BufferedInputStream(new FileInputStream(templateFileName));
XLSTransformer transformer = new XLSTransformer(config);
out = response.getOutputStream();
transformer.transformXLS(in, beans).write(out);
out.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
}