码迷,mamicode.com
首页 > 编程语言 > 详细

java 操作 Excel,java导出excel

时间:2014-07-14 18:06:14      阅读:345      评论:0      收藏:0      [点我收藏+]

标签:java   excel   

		

      WritableWorkbook out = null;

      try {
	 response.getServletResponse().reset();
	 ((HttpServletResponse) response.getServletResponse()).setHeader("Content-Disposition", "attachment;filename=export.xls");
	 response.getServletResponse().setContentType("gbk");
	 response.getServletResponse().setCharacterEncoding("gbk");
	 response.getServletResponse().setContentType("application/vnd.ms-excel");

	 out = Workbook.createWorkbook(((HttpServletResponse) response.getServletResponse()).getOutputStream());
	 int sheetNum = 0;
	 WritableSheet sheet = out.createSheet("第1页", sheetNum);
	 Label labels = null;
	 String[] labea = { "员工唯一号", "员工姓名", "补差开始时间", "补差结束时间", "申报工资" };
	 for (int i = 0; i < labea.length; i++) {
		 labels = new Label(i, 0, labea[i]);
		 sheet.addCell(labels);
	 }
		 Label label = null;
		 for (int i = 0; i < beans.size(); i++) {
			 EmppostVo vo = (EmppostVo) beans.get(i);
			 String emp_code = vo.getEmp_code() == null ? "" : vo.getEmp_code();
			 String emp_name = vo.getEmp_name() == null ? "" : vo.getEmp_name();
			 String startDate = vo.getStart_month()  == null ? "" : vo.getStart_month().substring(0, 11);
			 String endDate = vo.getEnd_month()== null ? "" : vo.getEnd_month().substring(0, 11);
			 String baseSalary = vo.getBase_salary()== null ? "" : vo.getBase_salary(); 
			 String[] strArr = { emp_code, emp_name, startDate, endDate,baseSalary};
			 for (int j = 0; j < strArr.length; j++) {
				 label = new Label(j, i + 1, strArr[j]);
				 sheet.addCell(label);
			 }
		 }
		 out.write();
	 } catch (RuntimeException e) {
		 e.printStackTrace();
	 }finally{
         	out.close();
	 }

java 操作 Excel,java导出excel,布布扣,bubuko.com

java 操作 Excel,java导出excel

标签:java   excel   

原文地址:http://blog.csdn.net/pengchengmm/article/details/37763899

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!