poi operation of java Excel Export Excel spreadsheet

Page Layout

Click Export User: trigger functions directly to the back

Background follows:

public String export()throws Exception{
		Connection con=null;
		try {
			con=dbUtil.getCon();
			Workbook wb = new HSSFWorkbook (); // create a workbook

			String headers [] = { "number", "name", "telephone", "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;
	}

  

Source: https://github.com/nideguigege/poi

Guess you like

Origin www.cnblogs.com/nidegui/p/11039090.html