码迷,mamicode.com
首页 > 其他好文 > 详细

报表打印

时间:2014-06-11 09:30:21      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:get   使用   string   set   os   代码   

核心代码:

 

 
 /* String  filename="角色信息表.xls";
  String realpath="d:\\"+filename;
  File f =new File(realpath);
  if(f.exists());else f.createNewFile();
 */ 
  
  response.setCharacterEncoding("application/vnd.ms-excel;charset=GBK");
 // response.setHeader("Content-Disposition", "attachment;filename=角色表.xls");
  response.setHeader("Content-Disposition", "attachment;filename=" 
    + new String("角色信息.xls".getBytes(),"iso-8859-1")); 
  
  

 

String sql="select * from role";
  Irole list=new roledao();
  ArrayList<role> show=list.lookall(sql);
  
  
  HSSFWorkbook workbook=new HSSFWorkbook();
  HSSFSheet sheet=workbook.createSheet("角色信息");
  
    
  HSSFRow row=sheet.createRow(0);
  
  HSSFCell cell=row.createCell(0);
  cell.setCellValue("角色id");
  HSSFCell cell1=row.createCell(1);
  cell1.setCellValue("角色名");
  HSSFCell cell2=row.createCell(2);
  cell2.setCellValue("角色状态");
  
  
  int i=1;
  
  for(role Role:show){
   
 HSSFRow rowindex=sheet.createRow(i);
 HSSFCell cella=rowindex.createCell(0);
 cella.setCellValue(Role.getRid());
 
 HSSFCell cellb=rowindex.createCell(1);
 cellb.setCellValue(Role.getRname());
 
 HSSFCell cellc=rowindex.createCell(2);
 cellc.setCellValue(Role.getRstate().trim().equals("Y")?"使用":"未使用");
 
  i++; 
   
  }
  
  //FileOutputStream s=new FileOutputStream(f);
  //workbook.write(s);
  //s.close();
  
 ServletOutputStream out =response.getOutputStream();
 BufferedOutputStream o =new BufferedOutputStream(out);
 workbook.write(o);
 o.close();

 

 

 

 

报表打印,布布扣,bubuko.com

报表打印

标签:get   使用   string   set   os   代码   

原文地址:http://www.cnblogs.com/thinkpad/p/3773113.html

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