java操作Excel的poi的导出Excel表格

页面布局

点击导出用户:触发函数,直接访问后台

后台方法如下:

public String export()throws Exception{
		Connection con=null;
		try {
			con=dbUtil.getCon();
			Workbook wb=new HSSFWorkbook();  //创建工作簿

			String headers[]={"编号","姓名","电话","Email","QQ"};
			ResultSet rs=userDao.userList(con, null);
			ExcelUtil.fillExcelData(rs, wb, headers);
			ResponseUtil.export(ServletActionContext.getResponse(), wb, "导出excel.xls");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				dbUtil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}

  

源码:https://github.com/nideguigege/poi

posted on 2019-06-17 12:53  nidegui  阅读(421)  评论(0编辑  收藏  举报