是这样子的,我在jsp页面上有个按钮,汇出,点击“汇出” 就会生成excel,然后提示存放到哪里,然后选存放桌面上,就直接没了,我想要让其存放到桌面上,然后提示是否打开,选打开就打开excel。
this.pageBean = customerService.queryForPage(hqls, Constant.PAGESIZE_DEFAULT, page);
HttpServletResponse response=ServletActionContext.getResponse();
response.reset();//清楚空白行
OutputStream os=response.getOutputStream();
response.setContentType("application/msexcel");
response.setHeader("Content-Disposition", "attachment;filename=customerInfo.xls");
WritableWorkbook wbook=Workbook.createWorkbook(os);//建立excel文件
String emptitle="客户信息表";//工作表名称
WritableSheet wsheet=wbook.createSheet(emptitle, 2);
//设置字体
WritableFont wfont=new WritableFont(WritableFont.ARIAL,16,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.BLACK);
WritableCellFormat titleFormat=new WritableCellFormat(wfont);
titleFormat.setAlignment(Alignment.CENTRE);//设置文字居中
wsheet.mergeCells(8, 0, 10, 0);//合并单元格,参数格式(开始列,开始行,结束列,结束行)
wsheet.addCell(new Label(8,0,"客户基本资料",titleFormat));//把单元格添加到工作表中
wbook.write();//写入文件
wbook.close();
os.close();