poi 生成一个excel并且用response是输出
			
					(2012-07-25 18:39:00)		
		
						
		
			
  
   XSSFWorkbook xs=new
XSSFWorkbook();
   XSSFSheet
sheet=xs.createSheet("exprot data");
   XSSFRow
row=sheet.createRow((short)0);
  
row.createCell((short)0).setCellValue("序号");   
  
row.createCell((short)1).setCellValue("网点编码");
  
row.createCell((short)2).setCellValue("网点代码");
  
row.createCell((short)3).setCellValue("网点名称");
  
row.createCell((short)4).setCellValue("归属网格");
  
row.createCell((short)5).setCellValue("归属区县 ");
  
row.createCell((short)6).setCellValue("合作起始日期");
  
row.createCell((short)7).setCellValue("退出日期");
  
row.createCell((short)8).setCellValue("星级");
  
  
row.createCell((short)9).setCellValue("专营");
  
row.createCell((short)10).setCellValue("郊区");
  
row.createCell((short)11).setCellValue("申请超量奖励");
  
row.createCell((short)12).setCellValue("是否沃店");
  
row.createCell((short)13).setCellValue("是否有效");
   String sql=(String)
ServletActionContext.getRequest().getSession().getAttribute("siteInfoSession");
   System.out.println(sql);
  
List<HashMap<String,?>>
list=DbHelper.getBySQL(sql,"");
  
   String is_spec;
   String is_city;
   String is_rewa;
   String is_wo;
   String is_valied;
   for(int
i=0;i<list.size();i++){
    XSSFRow
rowdata=sheet.createRow((short)(i+1));
   
rowdata.createCell((short)0).setCellValue(i);
   
rowdata.createCell((short)1).setCellValue((String)
(((HashMap<String,?>)(list.get(i))).get("bss_id")));
   
rowdata.createCell((short)2).setCellValue((String)
(((HashMap<String,?>)(list.get(i))).get("bss_8id")));
   
rowdata.createCell((short)3).setCellValue((String)
(((HashMap<String,?>)(list.get(i))).get("bss_name")));
   
rowdata.createCell((short)4).setCellValue((String)
(((HashMap<String,?>)(list.get(i))).get("bss_wg_name")));
   
rowdata.createCell((short)5).setCellValue((String)
(((HashMap<String,?>)(list.get(i))).get("bss_qx_name")));
   
rowdata.createCell((short)6).setCellValue((String)
(((HashMap<String,?>)(list.get(i))).get("startDate")));
   
rowdata.createCell((short)7).setCellValue((String)
(((HashMap<String,?>)(list.get(i))).get("endDate")));
   
rowdata.createCell((short)8).setCellValue((String)
(((HashMap<String,?>)(list.get(i))).get("star")));
    
is_spec=(String)
(((HashMap<String,?>)(list.get(i))).get("is_spec"));
    
is_city=(String)
(((HashMap<String,?>)(list.get(i))).get("is_city"));
    
is_rewa=(String)
(((HashMap<String,?>)(list.get(i))).get("is_rewa"));
    
is_wo=(String)
(((HashMap<String,?>)(list.get(i))).get("is_wo"));
    
is_valied=(String)
(((HashMap<String,?>)(list.get(i))).get("is_valied"));
   
rowdata.createCell((short)9).setCellValue(UtilService.is_spec(is_spec));
   
rowdata.createCell((short)10).setCellValue(UtilService.is_city(is_city));
   
rowdata.createCell((short)11).setCellValue(UtilService.is_rewa(is_rewa));
   
rowdata.createCell((short)12).setCellValue(UtilService.is_wo(is_wo));
   
rowdata.createCell((short)13).setCellValue(UtilService.is_valied(is_valied));
   }
  
   HttpServletResponse
response=ServletActionContext.getResponse();
  
String   
mimetype = "application/x-msdownload";
  
response.setContentType(mimetype);
    
  String downFileName =
"dataFile.xlsx";
   String inlineType =
"attachment"; // 是否内联附件
  
response.setHeader("Content-Disposition", inlineType
    +
";filename=\"" + downFileName + "\"");
   OutputStream
out=response.getOutputStream();
   xs.write(out);
   out.flush();
   out.close();
   
  
 							
		
						
		
        	
            
	        	
	            	
	                 喜欢
喜欢
	             
                                
                    0
                     赠金笔
赠金笔
                 
                
	         
            
		 
		
		
		加载中,请稍候......