导出excel

控制层操作;

//导出excel
	@RequestMapping("/toExcel")
	public void downLoadExcel(HttpServletRequest request, HttpServletResponse response){
		String fileName = "生长适宜性指数";
		List<Map<String, Object>> listmap = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("sheetName", "sheet1");
		listmap.add(map);
		Exponent exponent = null;
		for (int j = 0; j <list.size(); j++) {
			exponent = list.get(j);
			Map<String, Object> mapValue = new HashMap<String, Object>();
			mapValue.put("年份",exponent.getDT());
			mapValue.put("地区",exponent.getAREA());
			mapValue.put("作物名称",exponent.getFName());
			mapValue.put("站名",exponent.getSName());
			mapValue.put("站号",exponent.getSNO());		
			mapValue.put("发育期",exponent.getPhase());
			mapValue.put("24小时生长适宜性",exponent.getI24());
			mapValue.put("48小时生长适宜性",exponent.getI48());
			mapValue.put("72小时生长适宜性",exponent.getI72());
			mapValue.put("96小时生长适宜性",exponent.getI96());
			listmap.add(mapValue);
		}
		String columnNames[] = {"年份","地区","作物名称","站名","站号","发育期","24小时生长适宜性","48小时生长适宜性",
				"72小时生长适宜性","96小时生长适宜性"};// 列名
		String keys[] = {"年份","地区","作物名称","站名","站号","发育期","24小时生长适宜性","48小时生长适宜性",
				"72小时生长适宜性","96小时生长适宜性"};// map中的key
		try {
			ExportExcel.download(request, response, listmap, fileName, columnNames, keys);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

js代码:

//导出Exccel
    function pmgressbar(){//进度条
    	var win = $.messager.progress({
    		title : '请稍等',
    		msg : '正在导出中...',
    	});
    	
    	setTimeout(function(){
    		$.messager.progress("close");
    	},600)
    }
    function onClick_download(){	
    	//alert(11)
    	$.messager.confirm("确认","确认将搜索到的数据导出为Excel表格?",function(r){
    		if(r){
    			url="/SX_LGQX/exponent/toExcel.do";
    			location.href=url;	
    			pmgressbar();
    		}
    	});	
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值