java Excel导出

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) {
}
}
}


}



















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值