jxl을 이용하여 자바 프로그램에서 데이터를 excel로 내보내는 예

1909 단어 Excel
public String showDetail() throws Exception {
		//  
		SysUsers loginUser = (SysUsers) session.get("loginUser");
		String queryScope = loginUser.getQueryScope();
		String[] orgScope = queryScope.split(",");

		Map map = new HashMap();
		map.put("orgScope", orgScope);
		map.put("mobtypeid", mobtypeid);

		//  
		detailList = dao.queryList("mobStock.getDetail", map);

		//  excel 
		if ("excel".equals(detailType)) {
			OutputStream os = response.getOutputStream();	// 
			response.setHeader("Content-disposition", "attachment; filename=detail.xls");//     
			response.setContentType("application/msexcel");	// 

			WritableWorkbook wb = Workbook.createWorkbook(os);	// excel 
			WritableSheet sheet = wb.createSheet("detail", 0);	// sheet 

			sheet.addCell(new Label(0, 0, " "));
			sheet.addCell(new Label(1, 0, " "));
			sheet.addCell(new Label(2, 0, " "));
			sheet.addCell(new Label(3, 0, " "));
			Iterator<StoMobstock> detailIterator = detailList.iterator();
			int rowNo = 1;
			while (detailIterator.hasNext()) {
				StoMobstock mobstock = detailIterator.next();
				sheet.addCell(new Label(0, rowNo, mobstock.getMobtypeid()));
				sheet.addCell(new Label(1, rowNo, mobstock.getSn1()));
				sheet.addCell(new Label(2, rowNo, mobstock.getSn2()));
				sheet.addCell(new Number(3, rowNo, mobstock.getBuyprice()
						.doubleValue(), new WritableCellFormat(
						new NumberFormat("#,###.00"))));  //  
				rowNo++;
			}
			wb.write();
			wb.close();
			return null;
		} else {
			return "detail";
		}
	}

좋은 웹페이지 즐겨찾기