Servlet and xls
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Chucho_Cumbia
Posted On:   Monday, February 17, 2003 08:42 AM

Hi, I am generating excel reports with JExcel, and I am using and writing the ServletOutputStream, I am doing something like: response.setContentType( "application/vnd.ms-excel" ); //response.setHeader("Content-Disposition","attachment;inline=whatever.xls"); //response.setHeader("Content-Disposition","inline;inline=whatever.xls"); ServletOutputStream sos = response.getOutputStream(); (It is supposed whatever.xls is a random name). The problems are: if i run this code, the first time runs ok but when I try to run it again, the messange says that I canýt open 2 files with the same name (the default name that java takes is the servlet na   More>>

Hi, I am generating excel reports with JExcel, and I am using and writing the ServletOutputStream, I am doing something like:




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

  2. //response.setHeader("Content-Disposition","attachment;inline=whatever.xls");

  3. //response.setHeader("Content-Disposition","inline;inline=whatever.xls");

  4. ServletOutputStream sos = response.getOutputStream();


(It is supposed whatever.xls is a random name). The problems are:



  • if i run this code, the first time runs ok but when I try to run it again, the messange says that I canýt open 2 files with the same name (the default name that java takes is the servlet name.xls)

  • If I uncomment the line 2 and put different names it works but it launches the excel app, and I want to open it in explorer.

  • If I uncomment the line 3 it opens me the first time the excel file in the browser, but if I don´t close the window to request a new file, it opens a blank explorer, that sometimes blocks the explorer



What can I do to assign a name to the file and where can I get info about MIME Types?



Suggestions?



Thanks a lot...

   <<Less

Re: Servlet and xls

Posted By:   anil_palat  
Posted On:   Wednesday, February 19, 2003 11:42 PM

If you want to save the file to the hard disk first with a filename & then show the link to the browser, you can try the following



FileOutputStream fileOut = new FileOutputStream("workbook.xls");

//write your generated excel work book to the stream.

wb.write(fileOut);

fileOut.close();



If you dont want to store the excel file to the hard disk then filenaming is required. It will take your servlet name as default.In this case you can directly write the excel work book to the browser as follows :



ServletOutputStream sos=response.getOutputStream();

//write your generated excel work book to the stream.

wb.write(sos);

sos.close();



hope this would solve your problem.

About | Sitemap | Contact