标签:
1 比如以下按钮, 用于导出文件,如EXCEL文件。
<li><button class="whiteBg btn2" onclick="doExp(1);return false; "><i class="fa fa-save (alias) m-r-xs" ></i>导出所有工单</button></li><li><button class="whiteBg btn2" onclick="doExp(2);return false; ">- <i class="fa fa-file-text-o m-r-xs"></i>导出所选工单
</button></li>
function expExcel(){//alert("expExcel");var url="../user/expExcel?loginName=${user.loginName}&userName=${user.userName}&moblie=${user.mobile}";//alert(url);window.location.href=url;}- 或者用
- function exportExcel(){ if(flag){ flag = false; window.location.href = "${ctx}/rpt/4gSite/empToExcel";setTimeout(function(){flag = true;},2000); } }
- 或者, 都是一样的用法.
- $(function(){ exp=function(){ var query_time=$(‘#query_time‘).val(); window.location.href="../../doExp?query_time="+query_time; } });
@RequestMapping("/expToExcel")public void expToExcel(HttpServletRequest request, HttpServletResponse response) {UserContext uc = this.getUserContext(request);String loginName = request.getParameter("loginName");String userName= request.getParameter("userName");String moblie= request.getParameter("moblie");- User user=new User();
user.setLoginName(loginName);user.setUserName(userName);user.setMobile(moblie);List<User> users=this.userService.getListBy(user,uc);ExcelExportUtils2<User> exUser = new ExcelExportUtils2<User>();HSSFWorkbook workbook = exUser.exportExcel(new HSSFWorkbook(),"用户列表清单", users);ServletUtils.flushExcelOutputStream(request, response, workbook,"用户列表清单_"+DateUtil.formatDateToString("yyyyMMdd", new Date()));}
/*** 导出Excel,使用自定义的名字作为文件名* @param request* @param response* @param dataList* @throws UnsupportedEncodingException* @throws IOException*/public static void flushExcelOutputStream(HttpServletRequest request, HttpServletResponse response,HSSFWorkbook workbook,String fileName) {String userAgent = request.getHeader("User-Agent");String newFileName = null;try {fileName = URLEncoder.encode(fileName, "UTF8");} catch (UnsupportedEncodingException e1) {e1.printStackTrace();}if (userAgent != null) {userAgent = userAgent.toLowerCase();// IE浏览器,只能采用URLEncoder编码if (userAgent.indexOf("msie") != -1) {newFileName = "filename=\"" + fileName + ".xls\"";}// Opera浏览器只能采用filename*else if (userAgent.indexOf("opera") != -1) {newFileName = "filename*=UTF-8‘‘" + fileName +".xls";}// Safari浏览器,只能采用ISO编码的中文输出else if (userAgent.indexOf("safari") != -1) {try {newFileName = "filename=\""+ new String(fileName.getBytes("UTF-8"), "ISO8859-1")+ ".xls\"";} catch (UnsupportedEncodingException e) {e.printStackTrace();}}// Chrome浏览器,只能采用MimeUtility编码或ISO编码的中文输出else if (userAgent.indexOf("applewebkit") != -1) {try {fileName = MimeUtility.encodeText(fileName, "UTF8", "B");} catch (UnsupportedEncodingException e) {e.printStackTrace();}newFileName = "filename=\"" + fileName + ".xls\"";}// FireFox浏览器,可以使用MimeUtility或filename*或ISO编码的中文输出else if (userAgent.indexOf("mozilla") != -1) {newFileName = "filename*=UTF-8‘‘" + fileName +".xls";}}//文件名编码结束。response.setHeader("Content-Disposition", "attachment;" + newFileName); // 这个很重要ServletUtils.setDisableCacheHeader(response);ServletOutputStream out = null;try {out = response.getOutputStream();workbook.write(out);out.flush();} catch (IOException e) {e.printStackTrace();}finally{if(out != null){try {out.close();} catch (IOException e) {logger.error(e.getMessage(), e);e.printStackTrace();}}}}
window.location.href = "../../../../download?"+$(‘#form_Report‘).serialize();window.location.href = "../../../../download?userName=${user.userName}"+"&"+$(‘#form_Report‘).serialize();

<input id="btnExport" class="btn btn-primary" type="button" value="导出"/>
$(document).ready(function() {// 表格排序tableSort({callBack : page});$("#btnExport").click(function(){top.$.jBox.confirm("确认要导出用户数据吗?","系统提示",function(v,h,f){if(v == "ok"){$("#searchForm").attr("action","${ctx}/sys/user/export").submit();}},{buttonsFocus:1});top.$(‘.jbox-body .jbox-icon‘).css(‘top‘,‘55px‘);});$("#btnImport").click(function(){$.jBox($("#importBox").html(), {title:"导入数据", buttons:{"关闭":true},bottomText:"导入文件不能超过5M,仅允许导入“xls”或“xlsx”格式文件!"});});});
DownLoadFile2({url:‘../../../alarm/doExp‘,data:ids}); //ids为选中的数据的id如拼接字符串,如: 1,2,3,55,333,123,
//提交表单var DownLoadFile = function (options) {var config = $.extend(true, { method: ‘post‘ }, options);var $iframe = $(‘<iframe id="down-file-iframe" />‘);var $form = $(‘<form target="down-file-iframe" method="‘ + config.method + ‘" />‘);$form.attr(‘action‘, config.url);for (var key in config.data) {$form.append(‘<input type="hidden" name="‘ + key + ‘" value="‘ + config.data[key] + ‘" />‘);}$iframe.append($form);$(document.body).append($iframe);$form[0].submit();$iframe.remove();};//提交参数var DownLoadFile2 = function (options) {var config = $.extend(true, { method: ‘post‘ }, options);var $iframe = $(‘<iframe id="down-file-iframe" />‘);var $form = $(‘<form target="down-file-iframe" method="‘ + config.method + ‘" />‘);$form.attr(‘action‘, config.url);$form.append(‘<input type="hidden" name="ids" value="‘ + options.data + ‘" />‘);$iframe.append($form);$(document.body).append($iframe);$form[0].submit();$iframe.remove();};
var DownLoadFile = function (options) {var config ={ method: ‘post‘ };var $form = $(‘<form method="‘ + config.method + ‘" />‘);$(document.body).append($form);$form.attr(‘action‘, options.url);for (var key in options.data) {$form.append(‘<input type="hidden" name="‘ + key + ‘" value="‘ + options.data[key] + ‘" />‘);}$form[0].submit();$form.remove();};
var DownLoadFile = function (options) {var config ={ method: ‘post‘ };var $form = $(‘<form method="‘ + config.method + ‘" />‘);$(document.body).append($form);$form.attr(‘action‘, options.url);for (var key in options.data) {$form.append(‘<input type="hidden" name="‘ + key + ‘" value="‘ + options.data[key] + ‘" />‘);}$form[0].submit();$form.remove();};
标签:
原文地址:http://www.cnblogs.com/redcoatjk/p/5960937.html