首页 > 代码库 > 报表打印
报表打印
核心代码:
/* 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();