java 数据导入xls
@RequestMapping("admin/doorDesign/getexcel.do")
	public void getExcel(String name,String phone,Integer status,String start_time,String end_time,HttpServletRequest req, HttpServletResponse rsp)
			throws Exception {
		  OutputStream ouputStream  = null;
		  try{
			  DoorDesignEntity doorDesign =new DoorDesignEntity();
			  if(phone !=null && phone != "")
			  {
				  doorDesign.setPhone(phone); 
			  }
			  if(name != "" && name !=null )
			  {
				  doorDesign.setName(name);
			  }
			  if(status !=null && status !=-1)
			  {
				  doorDesign.setStatus(status);
			  }
			  if(start_time !=null && start_time != "")
			  {
				  doorDesign.setStart_time(start_time);
			  }
			  if(end_time !=null && end_time != "")
			  {
				  doorDesign.getEnd_time();
			  }
			  List<DoorDesignEntity> list =doorDao.getlist(doorDesign);	
			// 获取总列数
				int CountColumnNum = list.size();
				// 创建Excel文档
				HSSFWorkbook hwb = new HSSFWorkbook();
				DoorDesignEntity doorDesignEntity=null;
				// sheet 对应一个工作页
				HSSFSheet sheet = hwb.createSheet("上门设计预约列表");
				// api 段信息 Set the width (in units of 1/256th of a character width)
				sheet.setColumnWidth((short) 1, (short) 4000);
				sheet.setColumnWidth((short) 2, (short) 5000);
				sheet.setColumnWidth((short) 3, (short) 5000);
				sheet.setColumnWidth((short) 4, (short) 5000);
				sheet.setColumnWidth((short) 5, (short) 5000);
				sheet.setColumnWidth((short) 6, (short) 5000);
				sheet.setColumnWidth((short) 7, (short) 5000);
				HSSFRow firstrow = sheet.createRow(0); // 下标为0的行开始
				HSSFCell[] firstcell = new HSSFCell[7];
				String[] names = new String[7];
				names[0]="编号";
				names[1]="手机号码";
				names[2]="姓名";
				names[3]="地址";
				names[4]="表单状态";
				names[5]="处理时间";
				names[6]="提交时间";
				for (short j = 0; j < 7; j++) {
					firstcell[j] = firstrow.createCell(j);
					firstcell[j].setCellValue(new HSSFRichTextString(names[j]));
				}
				for (int i = 0; i < list.size(); i++) {
					// 创建一行
					HSSFRow row = sheet.createRow(i + 1);
					// 得到要插入的每一条记录
					doorDesignEntity = list.get(i);
				//for (short colu = 0; colu <5; colu++) {
						// 在一行内循环
						HSSFCell xh = row.createCell((short) 0);
						xh.setCellValue(i+1);
						HSSFCell xm = row.createCell((short) 1);
						xm.setCellValue(new HSSFRichTextString(doorDesignEntity.getPhone()));
						HSSFCell yxsmc= row.createCell((short) 2);
						yxsmc.setCellValue(new HSSFRichTextString(doorDesignEntity.getName()));
						HSSFCell xkl1= row.createCell((short) 3);
						xkl1.setCellValue(new HSSFRichTextString(doorDesignEntity.getProvince()+","+doorDesignEntity.getCity()));
						HSSFCell xkl= row.createCell((short) 4);
						xkl.setCellValue(new HSSFRichTextString(getstatus(doorDesignEntity.getStatus())));
						HSSFCell cj= row.createCell((short)5);
						cj.setCellValue(new HSSFRichTextString(doorDesignEntity.getChuliTime()));
						HSSFCell cjd= row.createCell((short)6);
						SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						cjd.setCellValue(new HSSFRichTextString(sdf.format(doorDesignEntity.getAddtime())));
					//}
					}
			    rsp.setContentType("applicationnd.ms-excel");
			    rsp.setHeader("Content-disposition", "attachment;filename=" + new String(( "上门设计预约列表").getBytes("gb2312"), "iso8859-1")
				        + ".xls");
			 ouputStream  = rsp.getOutputStream();
			 hwb.write(ouputStream);
				ouputStream.flush();
				ouputStream.close();
		} catch (Exception e) {
		// TODO: handle exception
		try {
			ouputStream.flush();
			ouputStream.close();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		}
				
		  }
	public String getstatus(Integer status){
		String s="";
		switch(status){
			case 0 : s="未处理"; break;
			case 1: s="已处理"; break;	
		}
		return s;}
}
 
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号