vendredi 20 février 2015

open poi excel in browser


Vote count:

0




I have a template excel in my workspace in which certain will be updated when user clicks on print button on front page.


My requirement is on clicking of print button the excel should get opened in a new tab of browser so that user can take its print but it is not opening in a browser rather it gets downloaded.I don't want user to download excel it should be 'print only'.


I have written excel code in apache poi and have set the 'content-disposition' parameter to 'inline' but still it doesn't work


`FileInputStream fsIP= new FileInputStream(new File(request.getSession().getServletContext().getRealPath(".")+ "/Cheque Printing.xls"));



HSSFWorkbook wb = new HSSFWorkbook(fsIP);

HSSFSheet worksheet = wb.getSheetAt(0);
worksheet.setDisplayGridlines(false);
HSSFCell cell = null;

cell = (HSSFCell)worksheet.getRow(1).getCell((short)8);
cell.setCellValue(date);

cell = (HSSFCell)worksheet.getRow(2).getCell((short)2);
cell.setCellValue(payee);


cell = (HSSFCell)worksheet.getRow(3).getCell((short)3);
cell.setCellValue(amt1);


cell = (HSSFCell)worksheet.getRow(5).getCell((short)8);
cell.setCellValue(amount);

fsIP.close();
response.setContentType("application/vnd.ms-excel");


// I thought this line will help me out.

response.setHeader("Content-Disposition", "inline; filename=filename.xls");



final ServletOutputStream os = response.getOutputStream();
wb.write(os);
os.flush();
os.close();`


asked 49 secs ago







open poi excel in browser

Aucun commentaire:

Enregistrer un commentaire